Deleted Added
full compact
lex.c (74769) lex.c (77274)
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

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

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
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

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

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * $FreeBSD: head/usr.bin/mail/lex.c 74769 2001-03-25 04:57:05Z mikeh $
33 * $FreeBSD: head/usr.bin/mail/lex.c 77274 2001-05-27 20:26:22Z mikeh $
34 */
35
36#ifndef lint
37#if 0
38static char sccsid[] = "@(#)lex.c 8.1 (Berkeley) 6/6/93";
39#endif
40static const char rcsid[] =
34 */
35
36#ifndef lint
37#if 0
38static char sccsid[] = "@(#)lex.c 8.1 (Berkeley) 6/6/93";
39#endif
40static const char rcsid[] =
41 "$FreeBSD: head/usr.bin/mail/lex.c 74769 2001-03-25 04:57:05Z mikeh $";
41 "$FreeBSD: head/usr.bin/mail/lex.c 77274 2001-05-27 20:26:22Z mikeh $";
42#endif /* not lint */
43
44#include "rcv.h"
45#include <errno.h>
46#include <fcntl.h>
47#include "extern.h"
48
49/*
50 * Mail -- a mail program
51 *
52 * Lexical processing of commands.
53 */
54
42#endif /* not lint */
43
44#include "rcv.h"
45#include <errno.h>
46#include <fcntl.h>
47#include "extern.h"
48
49/*
50 * Mail -- a mail program
51 *
52 * Lexical processing of commands.
53 */
54
55char *prompt = "& ";
55const char *prompt = "& ";
56
56
57extern const struct cmd cmdtab[];
58extern const char *version;
59
57/*
58 * Set up editing on the given file name.
59 * If the first character of name is %, we are considered to be
60 * editing the file, otherwise we are reading our mail which has
61 * signficance for mbox and so forth.
62 */
63int
64setfile(name)
65 char *name;
66{
67 FILE *ibuf;
68 int i, fd;
69 struct stat stb;
70 char isedit = *name != '%';
71 char *who = name[1] ? name + 1 : myname;
72 char tempname[PATHSIZE];
73 static int shudclob;
74
60/*
61 * Set up editing on the given file name.
62 * If the first character of name is %, we are considered to be
63 * editing the file, otherwise we are reading our mail which has
64 * signficance for mbox and so forth.
65 */
66int
67setfile(name)
68 char *name;
69{
70 FILE *ibuf;
71 int i, fd;
72 struct stat stb;
73 char isedit = *name != '%';
74 char *who = name[1] ? name + 1 : myname;
75 char tempname[PATHSIZE];
76 static int shudclob;
77
75 if ((name = expand(name)) == NOSTR)
76 return -1;
78 if ((name = expand(name)) == NULL)
79 return (-1);
77
78 if ((ibuf = Fopen(name, "r")) == NULL) {
79 if (!isedit && errno == ENOENT)
80 goto nomail;
81 warn("%s", name);
80
81 if ((ibuf = Fopen(name, "r")) == NULL) {
82 if (!isedit && errno == ENOENT)
83 goto nomail;
84 warn("%s", name);
82 return(-1);
85 return (-1);
83 }
84
85 if (fstat(fileno(ibuf), &stb) < 0) {
86 warn("fstat");
86 }
87
88 if (fstat(fileno(ibuf), &stb) < 0) {
89 warn("fstat");
87 Fclose(ibuf);
90 (void)Fclose(ibuf);
88 return (-1);
89 }
90
91 if (S_ISDIR(stb.st_mode) || !S_ISREG(stb.st_mode)) {
91 return (-1);
92 }
93
94 if (S_ISDIR(stb.st_mode) || !S_ISREG(stb.st_mode)) {
92 Fclose(ibuf);
95 (void)Fclose(ibuf);
93 errno = S_ISDIR(stb.st_mode) ? EISDIR : EINVAL;
94 warn("%s", name);
95 return (-1);
96 }
97
98 /*
99 * Looks like all will be well. We must now relinquish our
100 * hold on the current set of stuff. Must hold signals

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

110 * Copy the messages into /tmp
111 * and set pointers.
112 */
113
114 readonly = 0;
115 if ((i = open(name, 1)) < 0)
116 readonly++;
117 else
96 errno = S_ISDIR(stb.st_mode) ? EISDIR : EINVAL;
97 warn("%s", name);
98 return (-1);
99 }
100
101 /*
102 * Looks like all will be well. We must now relinquish our
103 * hold on the current set of stuff. Must hold signals

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

113 * Copy the messages into /tmp
114 * and set pointers.
115 */
116
117 readonly = 0;
118 if ((i = open(name, 1)) < 0)
119 readonly++;
120 else
118 close(i);
121 (void)close(i);
119 if (shudclob) {
122 if (shudclob) {
120 fclose(itf);
121 fclose(otf);
123 (void)fclose(itf);
124 (void)fclose(otf);
122 }
123 shudclob = 1;
124 edit = isedit;
125 strlcpy(prevfile, mailname, sizeof(prevfile));
126 if (name != mailname)
127 strlcpy(mailname, name, sizeof(mailname));
128 mailsize = fsize(ibuf);
125 }
126 shudclob = 1;
127 edit = isedit;
128 strlcpy(prevfile, mailname, sizeof(prevfile));
129 if (name != mailname)
130 strlcpy(mailname, name, sizeof(mailname));
131 mailsize = fsize(ibuf);
129 snprintf(tempname, sizeof(tempname), "%s/mail.RxXXXXXXXXXX", tmpdir);
132 (void)snprintf(tempname, sizeof(tempname),
133 "%s/mail.RxXXXXXXXXXX", tmpdir);
130 if ((fd = mkstemp(tempname)) == -1 || (otf = fdopen(fd, "w")) == NULL)
131 err(1, "%s", tempname);
134 if ((fd = mkstemp(tempname)) == -1 || (otf = fdopen(fd, "w")) == NULL)
135 err(1, "%s", tempname);
132 (void) fcntl(fileno(otf), F_SETFD, 1);
136 (void)fcntl(fileno(otf), F_SETFD, 1);
133 if ((itf = fopen(tempname, "r")) == NULL)
134 err(1, "%s", tempname);
137 if ((itf = fopen(tempname, "r")) == NULL)
138 err(1, "%s", tempname);
135 (void) fcntl(fileno(itf), F_SETFD, 1);
136 rm(tempname);
139 (void)fcntl(fileno(itf), F_SETFD, 1);
140 (void)rm(tempname);
137 setptr(ibuf);
138 setmsize(msgCount);
141 setptr(ibuf);
142 setmsize(msgCount);
139 Fclose(ibuf);
143 (void)Fclose(ibuf);
140 relsesigs();
141 sawcom = 0;
142 if (!edit && msgCount == 0) {
143nomail:
144 fprintf(stderr, "No mail for %s\n", who);
144 relsesigs();
145 sawcom = 0;
146 if (!edit && msgCount == 0) {
147nomail:
148 fprintf(stderr, "No mail for %s\n", who);
145 return -1;
149 return (-1);
146 }
150 }
147 return(0);
151 return (0);
148}
149
150int *msgvec;
151int reset_on_stop; /* do a reset() if stopped */
152
153/*
154 * Interpret user commands one by one. If standard input is not a tty,
155 * print no prompt.
156 */
157void
158commands()
159{
152}
153
154int *msgvec;
155int reset_on_stop; /* do a reset() if stopped */
156
157/*
158 * Interpret user commands one by one. If standard input is not a tty,
159 * print no prompt.
160 */
161void
162commands()
163{
160 int eofloop = 0;
161 register int n;
164 int n, eofloop = 0;
162 char linebuf[LINESIZE];
165 char linebuf[LINESIZE];
163 void intr(), stop(), hangup();
164
165 if (!sourcing) {
166 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
166
167 if (!sourcing) {
168 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
167 signal(SIGINT, intr);
169 (void)signal(SIGINT, intr);
168 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
170 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
169 signal(SIGHUP, hangup);
170 signal(SIGTSTP, stop);
171 signal(SIGTTOU, stop);
172 signal(SIGTTIN, stop);
171 (void)signal(SIGHUP, hangup);
172 (void)signal(SIGTSTP, stop);
173 (void)signal(SIGTTOU, stop);
174 (void)signal(SIGTTIN, stop);
173 }
174 setexit();
175 for (;;) {
176 /*
177 * Print the prompt, if needed. Clear out
178 * string space, and flush the output.
179 */
175 }
176 setexit();
177 for (;;) {
178 /*
179 * Print the prompt, if needed. Clear out
180 * string space, and flush the output.
181 */
180 if (!sourcing && value("interactive") != NOSTR) {
182 if (!sourcing && value("interactive") != NULL) {
181 reset_on_stop = 1;
182 printf("%s", prompt);
183 }
183 reset_on_stop = 1;
184 printf("%s", prompt);
185 }
184 fflush(stdout);
186 (void)fflush(stdout);
185 sreset();
186 /*
187 * Read a line of commands from the current input
188 * and handle end of file specially.
189 */
190 n = 0;
191 for (;;) {
192 if (readline(input, &linebuf[n], LINESIZE - n) < 0) {

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

205 if (n < 0) {
206 /* eof */
207 if (loading)
208 break;
209 if (sourcing) {
210 unstack();
211 continue;
212 }
187 sreset();
188 /*
189 * Read a line of commands from the current input
190 * and handle end of file specially.
191 */
192 n = 0;
193 for (;;) {
194 if (readline(input, &linebuf[n], LINESIZE - n) < 0) {

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

207 if (n < 0) {
208 /* eof */
209 if (loading)
210 break;
211 if (sourcing) {
212 unstack();
213 continue;
214 }
213 if (value("interactive") != NOSTR &&
214 value("ignoreeof") != NOSTR &&
215 if (value("interactive") != NULL &&
216 value("ignoreeof") != NULL &&
215 ++eofloop < 25) {
216 printf("Use \"quit\" to quit.\n");
217 continue;
218 }
219 break;
220 }
221 eofloop = 0;
222 if (execute(linebuf, 0))

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

233 */
234int
235execute(linebuf, contxt)
236 char linebuf[];
237 int contxt;
238{
239 char word[LINESIZE];
240 char *arglist[MAXARGC];
217 ++eofloop < 25) {
218 printf("Use \"quit\" to quit.\n");
219 continue;
220 }
221 break;
222 }
223 eofloop = 0;
224 if (execute(linebuf, 0))

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

235 */
236int
237execute(linebuf, contxt)
238 char linebuf[];
239 int contxt;
240{
241 char word[LINESIZE];
242 char *arglist[MAXARGC];
241 struct cmd *com;
242 register char *cp, *cp2;
243 register int c;
244 int muvec[2];
243 const struct cmd *com;
244 char *cp, *cp2;
245 int c, muvec[2];
245 int e = 1;
246
247 /*
248 * Strip the white space away from the beginning
249 * of the command, then scan out a word, which
250 * consists of anything except digits and white space.
251 *
252 * Handle ! escapes differently to get the correct
253 * lexical conventions.
254 */
255
256 for (cp = linebuf; isspace(*cp); cp++)
257 ;
258 if (*cp == '!') {
259 if (sourcing) {
260 printf("Can't \"!\" while sourcing\n");
261 goto out;
262 }
263 shell(cp+1);
246 int e = 1;
247
248 /*
249 * Strip the white space away from the beginning
250 * of the command, then scan out a word, which
251 * consists of anything except digits and white space.
252 *
253 * Handle ! escapes differently to get the correct
254 * lexical conventions.
255 */
256
257 for (cp = linebuf; isspace(*cp); cp++)
258 ;
259 if (*cp == '!') {
260 if (sourcing) {
261 printf("Can't \"!\" while sourcing\n");
262 goto out;
263 }
264 shell(cp+1);
264 return(0);
265 return (0);
265 }
266 cp2 = word;
266 }
267 cp2 = word;
267 while (*cp && strchr(" \t0123456789$^.:/-+*'\"", *cp) == NOSTR)
268 while (*cp != '\0' && strchr(" \t0123456789$^.:/-+*'\"", *cp) == NULL)
268 *cp2++ = *cp++;
269 *cp2 = '\0';
270
271 /*
272 * Look up the command; if not found, bitch.
273 * Normally, a blank command would map to the
274 * first command in the table; while sourcing,
275 * however, we ignore blank lines to eliminate
276 * confusion.
277 */
278
279 if (sourcing && *word == '\0')
269 *cp2++ = *cp++;
270 *cp2 = '\0';
271
272 /*
273 * Look up the command; if not found, bitch.
274 * Normally, a blank command would map to the
275 * first command in the table; while sourcing,
276 * however, we ignore blank lines to eliminate
277 * confusion.
278 */
279
280 if (sourcing && *word == '\0')
280 return(0);
281 return (0);
281 com = lex(word);
282 com = lex(word);
282 if (com == NONE) {
283 if (com == NULL) {
283 printf("Unknown command: \"%s\"\n", word);
284 goto out;
285 }
286
287 /*
288 * See if we should execute the command -- if a conditional
289 * we always execute it, otherwise, check the state of cond.
290 */
291
292 if ((com->c_argtype & F) == 0)
284 printf("Unknown command: \"%s\"\n", word);
285 goto out;
286 }
287
288 /*
289 * See if we should execute the command -- if a conditional
290 * we always execute it, otherwise, check the state of cond.
291 */
292
293 if ((com->c_argtype & F) == 0)
293 if (cond == CRCV && !rcvmode || cond == CSEND && rcvmode)
294 return(0);
294 if ((cond == CRCV && !rcvmode) || (cond == CSEND && rcvmode))
295 return (0);
295
296 /*
297 * Process the arguments to the command, depending
298 * on the type he expects. Default to an error.
299 * If we are sourcing an interactive command, it's
300 * an error.
301 */
302

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

327 */
328 if (msgvec == 0) {
329 printf("Illegal use of \"message list\"\n");
330 break;
331 }
332 if ((c = getmsglist(cp, msgvec, com->c_msgflag)) < 0)
333 break;
334 if (c == 0) {
296
297 /*
298 * Process the arguments to the command, depending
299 * on the type he expects. Default to an error.
300 * If we are sourcing an interactive command, it's
301 * an error.
302 */
303

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

328 */
329 if (msgvec == 0) {
330 printf("Illegal use of \"message list\"\n");
331 break;
332 }
333 if ((c = getmsglist(cp, msgvec, com->c_msgflag)) < 0)
334 break;
335 if (c == 0) {
335 *msgvec = first(com->c_msgflag,
336 com->c_msgmask);
336 *msgvec = first(com->c_msgflag, com->c_msgmask);
337 msgvec[1] = 0;
338 }
339 if (*msgvec == 0) {
340 printf("No applicable messages\n");
341 break;
342 }
343 e = (*com->c_func)(msgvec);
344 break;

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

367 e = (*com->c_func)(cp);
368 break;
369
370 case RAWLIST:
371 /*
372 * A vector of strings, in shell style.
373 */
374 if ((c = getrawlist(cp, arglist,
337 msgvec[1] = 0;
338 }
339 if (*msgvec == 0) {
340 printf("No applicable messages\n");
341 break;
342 }
343 e = (*com->c_func)(msgvec);
344 break;

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

367 e = (*com->c_func)(cp);
368 break;
369
370 case RAWLIST:
371 /*
372 * A vector of strings, in shell style.
373 */
374 if ((c = getrawlist(cp, arglist,
375 sizeof arglist / sizeof *arglist)) < 0)
375 sizeof(arglist) / sizeof(*arglist))) < 0)
376 break;
377 if (c < com->c_minargs) {
378 printf("%s requires at least %d arg(s)\n",
376 break;
377 if (c < com->c_minargs) {
378 printf("%s requires at least %d arg(s)\n",
379 com->c_name, com->c_minargs);
379 com->c_name, com->c_minargs);
380 break;
381 }
382 if (c > com->c_maxargs) {
383 printf("%s takes no more than %d arg(s)\n",
380 break;
381 }
382 if (c > com->c_maxargs) {
383 printf("%s takes no more than %d arg(s)\n",
384 com->c_name, com->c_maxargs);
384 com->c_name, com->c_maxargs);
385 break;
386 }
387 e = (*com->c_func)(arglist);
388 break;
389
390 case NOLIST:
391 /*
392 * Just the constant zero, for exiting,

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

401
402out:
403 /*
404 * Exit the current source file on
405 * error.
406 */
407 if (e) {
408 if (e < 0)
385 break;
386 }
387 e = (*com->c_func)(arglist);
388 break;
389
390 case NOLIST:
391 /*
392 * Just the constant zero, for exiting,

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

401
402out:
403 /*
404 * Exit the current source file on
405 * error.
406 */
407 if (e) {
408 if (e < 0)
409 return 1;
409 return (1);
410 if (loading)
410 if (loading)
411 return 1;
411 return (1);
412 if (sourcing)
413 unstack();
412 if (sourcing)
413 unstack();
414 return 0;
414 return (0);
415 }
415 }
416 if (value("autoprint") != NOSTR && com->c_argtype & P)
416 if (value("autoprint") != NULL && com->c_argtype & P)
417 if ((dot->m_flag & MDELETED) == 0) {
418 muvec[0] = dot - &message[0] + 1;
419 muvec[1] = 0;
420 type(muvec);
421 }
422 if (!sourcing && (com->c_argtype & T) == 0)
423 sawcom = 1;
417 if ((dot->m_flag & MDELETED) == 0) {
418 muvec[0] = dot - &message[0] + 1;
419 muvec[1] = 0;
420 type(muvec);
421 }
422 if (!sourcing && (com->c_argtype & T) == 0)
423 sawcom = 1;
424 return(0);
424 return (0);
425}
426
427/*
428 * Set the size of the message vector used to construct argument
429 * lists to message list functions.
430 */
431void
432setmsize(sz)
433 int sz;
434{
435
436 if (msgvec != 0)
425}
426
427/*
428 * Set the size of the message vector used to construct argument
429 * lists to message list functions.
430 */
431void
432setmsize(sz)
433 int sz;
434{
435
436 if (msgvec != 0)
437 free((char *) msgvec);
438 msgvec = (int *) calloc((unsigned) (sz + 1), sizeof *msgvec);
437 (void)free(msgvec);
438 msgvec = calloc((unsigned)(sz + 1), sizeof(*msgvec));
439}
440
441/*
442 * Find the correct command in the command table corresponding
443 * to the passed command "word"
444 */
445
439}
440
441/*
442 * Find the correct command in the command table corresponding
443 * to the passed command "word"
444 */
445
446struct cmd *
446__const struct cmd *
447lex(word)
448 char word[];
449{
447lex(word)
448 char word[];
449{
450 register struct cmd *cp;
451 extern struct cmd cmdtab[];
450 const struct cmd *cp;
452
453 /*
451
452 /*
454 * ignore trailing chars after `#'
453 * ignore trailing chars after `#'
455 *
456 * lines with beginning `#' are comments
457 * spaces before `#' are ignored in execute()
458 */
459
460 if (*word == '#')
461 *(word+1) = '\0';
462
463
454 *
455 * lines with beginning `#' are comments
456 * spaces before `#' are ignored in execute()
457 */
458
459 if (*word == '#')
460 *(word+1) = '\0';
461
462
464 for (cp = &cmdtab[0]; cp->c_name != NOSTR; cp++)
463 for (cp = &cmdtab[0]; cp->c_name != NULL; cp++)
465 if (isprefix(word, cp->c_name))
464 if (isprefix(word, cp->c_name))
466 return(cp);
467 return(NONE);
465 return (cp);
466 return (NULL);
468}
469
470/*
471 * Determine if as1 is a valid prefix of as2.
472 * Return true if yep.
473 */
474int
475isprefix(as1, as2)
467}
468
469/*
470 * Determine if as1 is a valid prefix of as2.
471 * Return true if yep.
472 */
473int
474isprefix(as1, as2)
476 char *as1, *as2;
475 const char *as1, *as2;
477{
476{
478 register char *s1, *s2;
477 const char *s1, *s2;
479
480 s1 = as1;
481 s2 = as2;
482 while (*s1++ == *s2)
483 if (*s2++ == '\0')
478
479 s1 = as1;
480 s2 = as2;
481 while (*s1++ == *s2)
482 if (*s2++ == '\0')
484 return(1);
485 return(*--s1 == '\0');
483 return (1);
484 return (*--s1 == '\0');
486}
487
488/*
489 * The following gets called on receipt of an interrupt. This is
490 * to abort printout of a command, mainly.
491 * Dispatching here when command() is inactive crashes rcv.
492 * Close all open files except 0, 1, 2, and the temporary.
493 * Also, unstack all source files.

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

506 sawcom++;
507 inithdr = 0;
508 while (sourcing)
509 unstack();
510
511 close_all_files();
512
513 if (image >= 0) {
485}
486
487/*
488 * The following gets called on receipt of an interrupt. This is
489 * to abort printout of a command, mainly.
490 * Dispatching here when command() is inactive crashes rcv.
491 * Close all open files except 0, 1, 2, and the temporary.
492 * Also, unstack all source files.

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

505 sawcom++;
506 inithdr = 0;
507 while (sourcing)
508 unstack();
509
510 close_all_files();
511
512 if (image >= 0) {
514 close(image);
513 (void)close(image);
515 image = -1;
516 }
517 fprintf(stderr, "Interrupt\n");
518 reset(0);
519}
520
521/*
522 * When we wake up after ^Z, reprint the prompt.
523 */
524void
525stop(s)
526 int s;
527{
528 sig_t old_action = signal(s, SIG_DFL);
529
514 image = -1;
515 }
516 fprintf(stderr, "Interrupt\n");
517 reset(0);
518}
519
520/*
521 * When we wake up after ^Z, reprint the prompt.
522 */
523void
524stop(s)
525 int s;
526{
527 sig_t old_action = signal(s, SIG_DFL);
528
530 sigsetmask(sigblock(0) & ~sigmask(s));
531 kill(0, s);
532 sigblock(sigmask(s));
533 signal(s, old_action);
529 (void)sigsetmask(sigblock(0) & ~sigmask(s));
530 (void)kill(0, s);
531 (void)sigblock(sigmask(s));
532 (void)signal(s, old_action);
534 if (reset_on_stop) {
535 reset_on_stop = 0;
536 reset(0);
537 }
538}
539
540/*
541 * Branch here on hangup signal and simulate "exit".

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

558announce()
559{
560 int vec[2], mdot;
561
562 mdot = newfileinfo();
563 vec[0] = mdot;
564 vec[1] = 0;
565 dot = &message[mdot - 1];
533 if (reset_on_stop) {
534 reset_on_stop = 0;
535 reset(0);
536 }
537}
538
539/*
540 * Branch here on hangup signal and simulate "exit".

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

557announce()
558{
559 int vec[2], mdot;
560
561 mdot = newfileinfo();
562 vec[0] = mdot;
563 vec[1] = 0;
564 dot = &message[mdot - 1];
566 if (msgCount > 0 && value("noheader") == NOSTR) {
565 if (msgCount > 0 && value("noheader") == NULL) {
567 inithdr++;
568 headers(vec);
569 inithdr = 0;
570 }
571}
572
573/*
574 * Announce information about the file we are editing.
575 * Return a likely place to set dot.
576 */
577int
578newfileinfo()
579{
566 inithdr++;
567 headers(vec);
568 inithdr = 0;
569 }
570}
571
572/*
573 * Announce information about the file we are editing.
574 * Return a likely place to set dot.
575 */
576int
577newfileinfo()
578{
580 register struct message *mp;
581 register int u, n, mdot, d, s;
579 struct message *mp;
580 int u, n, mdot, d, s;
582 char fname[PATHSIZE+1], zname[PATHSIZE+1], *ename;
583
584 for (mp = &message[0]; mp < &message[msgCount]; mp++)
585 if (mp->m_flag & MNEW)
586 break;
587 if (mp >= &message[msgCount])
588 for (mp = &message[0]; mp < &message[msgCount]; mp++)
589 if ((mp->m_flag & MREAD) == 0)

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

602 d++;
603 if (mp->m_flag & MSAVED)
604 s++;
605 }
606 ename = mailname;
607 if (getfold(fname, sizeof(fname) - 1) >= 0) {
608 strcat(fname, "/");
609 if (strncmp(fname, mailname, strlen(fname)) == 0) {
581 char fname[PATHSIZE+1], zname[PATHSIZE+1], *ename;
582
583 for (mp = &message[0]; mp < &message[msgCount]; mp++)
584 if (mp->m_flag & MNEW)
585 break;
586 if (mp >= &message[msgCount])
587 for (mp = &message[0]; mp < &message[msgCount]; mp++)
588 if ((mp->m_flag & MREAD) == 0)

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

601 d++;
602 if (mp->m_flag & MSAVED)
603 s++;
604 }
605 ename = mailname;
606 if (getfold(fname, sizeof(fname) - 1) >= 0) {
607 strcat(fname, "/");
608 if (strncmp(fname, mailname, strlen(fname)) == 0) {
610 snprintf(zname, sizeof(zname), "+%s", mailname + strlen(fname));
609 (void)snprintf(zname, sizeof(zname), "+%s",
610 mailname + strlen(fname));
611 ename = zname;
612 }
613 }
614 printf("\"%s\": ", ename);
615 if (msgCount == 1)
616 printf("1 message");
617 else
618 printf("%d messages", msgCount);
619 if (n > 0)
620 printf(" %d new", n);
621 if (u-n > 0)
622 printf(" %d unread", u);
623 if (d > 0)
624 printf(" %d deleted", d);
625 if (s > 0)
626 printf(" %d saved", s);
627 if (readonly)
628 printf(" [Read only]");
629 printf("\n");
611 ename = zname;
612 }
613 }
614 printf("\"%s\": ", ename);
615 if (msgCount == 1)
616 printf("1 message");
617 else
618 printf("%d messages", msgCount);
619 if (n > 0)
620 printf(" %d new", n);
621 if (u-n > 0)
622 printf(" %d unread", u);
623 if (d > 0)
624 printf(" %d deleted", d);
625 if (s > 0)
626 printf(" %d saved", s);
627 if (readonly)
628 printf(" [Read only]");
629 printf("\n");
630 return(mdot);
630 return (mdot);
631}
632
633/*
634 * Print the current version number.
635 */
636
637/*ARGSUSED*/
638int
639pversion(e)
640 int e;
641{
631}
632
633/*
634 * Print the current version number.
635 */
636
637/*ARGSUSED*/
638int
639pversion(e)
640 int e;
641{
642 extern char *version;
643
644 printf("Version %s\n", version);
642
643 printf("Version %s\n", version);
645 return(0);
644 return (0);
646}
647
648/*
649 * Load a file of user definitions.
650 */
651void
652load(name)
653 char *name;
654{
645}
646
647/*
648 * Load a file of user definitions.
649 */
650void
651load(name)
652 char *name;
653{
655 register FILE *in, *oldin;
654 FILE *in, *oldin;
656
657 if ((in = Fopen(name, "r")) == NULL)
658 return;
659 oldin = input;
660 input = in;
661 loading = 1;
662 sourcing = 1;
663 commands();
664 loading = 0;
665 sourcing = 0;
666 input = oldin;
655
656 if ((in = Fopen(name, "r")) == NULL)
657 return;
658 oldin = input;
659 input = in;
660 loading = 1;
661 sourcing = 1;
662 commands();
663 loading = 0;
664 sourcing = 0;
665 input = oldin;
667 Fclose(in);
666 (void)Fclose(in);
668}
667}