lex.c (da52b4caaf187775f6b56a72c6b16e94ad728f7b) lex.c (6d8484b0d0191b66f9bfd0dfa89c06a29647f02a)
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 48 unchanged lines hidden (view full) ---

57 * editing the file, otherwise we are reading our mail which has
58 * signficance for mbox and so forth.
59 *
60 * If the -e option is being passed to mail, this function has a
61 * tri-state return code: -1 on error, 0 on no mail, 1 if there is
62 * mail.
63 */
64int
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 48 unchanged lines hidden (view full) ---

57 * editing the file, otherwise we are reading our mail which has
58 * signficance for mbox and so forth.
59 *
60 * If the -e option is being passed to mail, this function has a
61 * tri-state return code: -1 on error, 0 on no mail, 1 if there is
62 * mail.
63 */
64int
65setfile(name)
66 char *name;
65setfile(char *name)
67{
68 FILE *ibuf;
69 int checkmode, i, fd;
70 struct stat stb;
71 char isedit = *name != '%' || getuserid(myname) != getuid();
72 char *who = name[1] ? name + 1 : myname;
73 char tempname[PATHSIZE];
74 static int shudclob;

--- 85 unchanged lines hidden (view full) ---

160 return (checkmode ? 1 : 0);
161}
162
163/*
164 * Incorporate any new mail that has arrived since we first
165 * started reading mail.
166 */
167int
66{
67 FILE *ibuf;
68 int checkmode, i, fd;
69 struct stat stb;
70 char isedit = *name != '%' || getuserid(myname) != getuid();
71 char *who = name[1] ? name + 1 : myname;
72 char tempname[PATHSIZE];
73 static int shudclob;

--- 85 unchanged lines hidden (view full) ---

159 return (checkmode ? 1 : 0);
160}
161
162/*
163 * Incorporate any new mail that has arrived since we first
164 * started reading mail.
165 */
166int
168incfile()
167incfile(void)
169{
170 off_t newsize;
171 int omsgCount = msgCount;
172 FILE *ibuf;
173
174 ibuf = Fopen(mailname, "r");
175 if (ibuf == NULL)
176 return (-1);

--- 16 unchanged lines hidden (view full) ---

193static int *msgvec;
194static int reset_on_stop; /* do a reset() if stopped */
195
196/*
197 * Interpret user commands one by one. If standard input is not a tty,
198 * print no prompt.
199 */
200void
168{
169 off_t newsize;
170 int omsgCount = msgCount;
171 FILE *ibuf;
172
173 ibuf = Fopen(mailname, "r");
174 if (ibuf == NULL)
175 return (-1);

--- 16 unchanged lines hidden (view full) ---

192static int *msgvec;
193static int reset_on_stop; /* do a reset() if stopped */
194
195/*
196 * Interpret user commands one by one. If standard input is not a tty,
197 * print no prompt.
198 */
199void
201commands()
200commands(void)
202{
203 int n, eofloop = 0;
204 char linebuf[LINESIZE];
205
206 if (!sourcing) {
207 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
208 (void)signal(SIGINT, intr);
209 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)

--- 60 unchanged lines hidden (view full) ---

270/*
271 * Execute a single command.
272 * Command functions return 0 for success, 1 for error, and -1
273 * for abort. A 1 or -1 aborts a load or source. A -1 aborts
274 * the interactive command loop.
275 * Contxt is non-zero if called while composing mail.
276 */
277int
201{
202 int n, eofloop = 0;
203 char linebuf[LINESIZE];
204
205 if (!sourcing) {
206 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
207 (void)signal(SIGINT, intr);
208 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)

--- 60 unchanged lines hidden (view full) ---

269/*
270 * Execute a single command.
271 * Command functions return 0 for success, 1 for error, and -1
272 * for abort. A 1 or -1 aborts a load or source. A -1 aborts
273 * the interactive command loop.
274 * Contxt is non-zero if called while composing mail.
275 */
276int
278execute(linebuf, contxt)
279 char linebuf[];
280 int contxt;
277execute(char linebuf[], int contxt)
281{
282 char word[LINESIZE];
283 char *arglist[MAXARGC];
284 const struct cmd *com;
285 char *cp, *cp2;
286 int c, muvec[2];
287 int e = 1;
288

--- 178 unchanged lines hidden (view full) ---

467 return (0);
468}
469
470/*
471 * Set the size of the message vector used to construct argument
472 * lists to message list functions.
473 */
474void
278{
279 char word[LINESIZE];
280 char *arglist[MAXARGC];
281 const struct cmd *com;
282 char *cp, *cp2;
283 int c, muvec[2];
284 int e = 1;
285

--- 178 unchanged lines hidden (view full) ---

464 return (0);
465}
466
467/*
468 * Set the size of the message vector used to construct argument
469 * lists to message list functions.
470 */
471void
475setmsize(sz)
476 int sz;
472setmsize(int sz)
477{
478
479 if (msgvec != NULL)
480 (void)free(msgvec);
481 msgvec = calloc((unsigned)(sz + 1), sizeof(*msgvec));
482}
483
484/*
485 * Find the correct command in the command table corresponding
486 * to the passed command "word"
487 */
488
489__const struct cmd *
473{
474
475 if (msgvec != NULL)
476 (void)free(msgvec);
477 msgvec = calloc((unsigned)(sz + 1), sizeof(*msgvec));
478}
479
480/*
481 * Find the correct command in the command table corresponding
482 * to the passed command "word"
483 */
484
485__const struct cmd *
490lex(word)
491 char word[];
486lex(char word[])
492{
493 const struct cmd *cp;
494
495 /*
496 * ignore trailing chars after `#'
497 *
498 * lines with beginning `#' are comments
499 * spaces before `#' are ignored in execute()

--- 9 unchanged lines hidden (view full) ---

509 return (NULL);
510}
511
512/*
513 * Determine if as1 is a valid prefix of as2.
514 * Return true if yep.
515 */
516int
487{
488 const struct cmd *cp;
489
490 /*
491 * ignore trailing chars after `#'
492 *
493 * lines with beginning `#' are comments
494 * spaces before `#' are ignored in execute()

--- 9 unchanged lines hidden (view full) ---

504 return (NULL);
505}
506
507/*
508 * Determine if as1 is a valid prefix of as2.
509 * Return true if yep.
510 */
511int
517isprefix(as1, as2)
518 const char *as1, *as2;
512isprefix(const char *as1, const char *as2)
519{
520 const char *s1, *s2;
521
522 s1 = as1;
523 s2 = as2;
524 while (*s1++ == *s2)
525 if (*s2++ == '\0')
526 return (1);

--- 5 unchanged lines hidden (view full) ---

532 * to abort printout of a command, mainly.
533 * Dispatching here when command() is inactive crashes rcv.
534 * Close all open files except 0, 1, 2, and the temporary.
535 * Also, unstack all source files.
536 */
537
538static int inithdr; /* am printing startup headers */
539
513{
514 const char *s1, *s2;
515
516 s1 = as1;
517 s2 = as2;
518 while (*s1++ == *s2)
519 if (*s2++ == '\0')
520 return (1);

--- 5 unchanged lines hidden (view full) ---

526 * to abort printout of a command, mainly.
527 * Dispatching here when command() is inactive crashes rcv.
528 * Close all open files except 0, 1, 2, and the temporary.
529 * Also, unstack all source files.
530 */
531
532static int inithdr; /* am printing startup headers */
533
540/*ARGSUSED*/
541void
534void
542intr(s)
543 int s;
535intr(int s __unused)
544{
545
546 noreset = 0;
547 if (!inithdr)
548 sawcom++;
549 inithdr = 0;
550 while (sourcing)
551 unstack();

--- 7 unchanged lines hidden (view full) ---

559 fprintf(stderr, "Interrupt\n");
560 reset(0);
561}
562
563/*
564 * When we wake up after ^Z, reprint the prompt.
565 */
566void
536{
537
538 noreset = 0;
539 if (!inithdr)
540 sawcom++;
541 inithdr = 0;
542 while (sourcing)
543 unstack();

--- 7 unchanged lines hidden (view full) ---

551 fprintf(stderr, "Interrupt\n");
552 reset(0);
553}
554
555/*
556 * When we wake up after ^Z, reprint the prompt.
557 */
558void
567stop(s)
568 int s;
559stop(int s)
569{
570 sig_t old_action = signal(s, SIG_DFL);
571 sigset_t nset;
572
573 (void)sigemptyset(&nset);
574 (void)sigaddset(&nset, s);
575 (void)sigprocmask(SIG_UNBLOCK, &nset, NULL);
576 (void)kill(0, s);
577 (void)sigprocmask(SIG_BLOCK, &nset, NULL);
578 (void)signal(s, old_action);
579 if (reset_on_stop) {
580 reset_on_stop = 0;
581 reset(0);
582 }
583}
584
585/*
586 * Branch here on hangup signal and simulate "exit".
587 */
560{
561 sig_t old_action = signal(s, SIG_DFL);
562 sigset_t nset;
563
564 (void)sigemptyset(&nset);
565 (void)sigaddset(&nset, s);
566 (void)sigprocmask(SIG_UNBLOCK, &nset, NULL);
567 (void)kill(0, s);
568 (void)sigprocmask(SIG_BLOCK, &nset, NULL);
569 (void)signal(s, old_action);
570 if (reset_on_stop) {
571 reset_on_stop = 0;
572 reset(0);
573 }
574}
575
576/*
577 * Branch here on hangup signal and simulate "exit".
578 */
588/*ARGSUSED*/
589void
579void
590hangup(s)
591 int s;
580hangup(int s __unused)
592{
593
594 /* nothing to do? */
595 exit(1);
596}
597
598/*
599 * Announce the presence of the current Mail version,
600 * give the message count, and print a header listing.
601 */
602void
581{
582
583 /* nothing to do? */
584 exit(1);
585}
586
587/*
588 * Announce the presence of the current Mail version,
589 * give the message count, and print a header listing.
590 */
591void
603announce()
592announce(void)
604{
605 int vec[2], mdot;
606
607 mdot = newfileinfo(0);
608 vec[0] = mdot;
609 vec[1] = 0;
610 dot = &message[mdot - 1];
611 if (msgCount > 0 && value("noheader") == NULL) {
612 inithdr++;
613 headers(vec);
614 inithdr = 0;
615 }
616}
617
618/*
619 * Announce information about the file we are editing.
620 * Return a likely place to set dot.
621 */
622int
593{
594 int vec[2], mdot;
595
596 mdot = newfileinfo(0);
597 vec[0] = mdot;
598 vec[1] = 0;
599 dot = &message[mdot - 1];
600 if (msgCount > 0 && value("noheader") == NULL) {
601 inithdr++;
602 headers(vec);
603 inithdr = 0;
604 }
605}
606
607/*
608 * Announce information about the file we are editing.
609 * Return a likely place to set dot.
610 */
611int
623newfileinfo(omsgCount)
624 int omsgCount;
612newfileinfo(int omsgCount)
625{
626 struct message *mp;
627 int u, n, mdot, d, s;
628 char fname[PATHSIZE+1], zname[PATHSIZE+1], *ename;
629
630 for (mp = &message[omsgCount]; mp < &message[msgCount]; mp++)
631 if (mp->m_flag & MNEW)
632 break;

--- 43 unchanged lines hidden (view full) ---

676 printf("\n");
677 return (mdot);
678}
679
680/*
681 * Print the current version number.
682 */
683
613{
614 struct message *mp;
615 int u, n, mdot, d, s;
616 char fname[PATHSIZE+1], zname[PATHSIZE+1], *ename;
617
618 for (mp = &message[omsgCount]; mp < &message[msgCount]; mp++)
619 if (mp->m_flag & MNEW)
620 break;

--- 43 unchanged lines hidden (view full) ---

664 printf("\n");
665 return (mdot);
666}
667
668/*
669 * Print the current version number.
670 */
671
684/*ARGSUSED*/
685int
672int
686pversion(e)
687 int e;
673pversion(int e __unused)
688{
689
690 printf("Version %s\n", version);
691 return (0);
692}
693
694/*
695 * Load a file of user definitions.
696 */
697void
674{
675
676 printf("Version %s\n", version);
677 return (0);
678}
679
680/*
681 * Load a file of user definitions.
682 */
683void
698load(name)
699 char *name;
684load(char *name)
700{
701 FILE *in, *oldin;
702
703 if ((in = Fopen(name, "r")) == NULL)
704 return;
705 oldin = input;
706 input = in;
707 loading = 1;
708 sourcing = 1;
709 commands();
710 loading = 0;
711 sourcing = 0;
712 input = oldin;
713 (void)Fclose(in);
714}
685{
686 FILE *in, *oldin;
687
688 if ((in = Fopen(name, "r")) == NULL)
689 return;
690 oldin = input;
691 input = in;
692 loading = 1;
693 sourcing = 1;
694 commands();
695 loading = 0;
696 sourcing = 0;
697 input = oldin;
698 (void)Fclose(in);
699}