Deleted Added
full compact
lex.c (69249) lex.c (74769)
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 69249 2000-11-27 06:55:38Z kris $
33 * $FreeBSD: head/usr.bin/mail/lex.c 74769 2001-03-25 04:57:05Z mikeh $
34 */
35
36#ifndef lint
34 */
35
36#ifndef lint
37#if 0
37static char sccsid[] = "@(#)lex.c 8.1 (Berkeley) 6/6/93";
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 $";
38#endif /* not lint */
39
40#include "rcv.h"
41#include <errno.h>
42#include <fcntl.h>
43#include "extern.h"
44
45/*

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

56 * editing the file, otherwise we are reading our mail which has
57 * signficance for mbox and so forth.
58 */
59int
60setfile(name)
61 char *name;
62{
63 FILE *ibuf;
42#endif /* not lint */
43
44#include "rcv.h"
45#include <errno.h>
46#include <fcntl.h>
47#include "extern.h"
48
49/*

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

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;
64 int i;
68 int i, fd;
65 struct stat stb;
66 char isedit = *name != '%';
67 char *who = name[1] ? name + 1 : myname;
69 struct stat stb;
70 char isedit = *name != '%';
71 char *who = name[1] ? name + 1 : myname;
72 char tempname[PATHSIZE];
68 static int shudclob;
73 static int shudclob;
69 extern char *tempMesg;
70
71 if ((name = expand(name)) == NOSTR)
72 return -1;
73
74 if ((ibuf = Fopen(name, "r")) == NULL) {
75 if (!isedit && errno == ENOENT)
76 goto nomail;
74
75 if ((name = expand(name)) == NOSTR)
76 return -1;
77
78 if ((ibuf = Fopen(name, "r")) == NULL) {
79 if (!isedit && errno == ENOENT)
80 goto nomail;
77 perror(name);
81 warn("%s", name);
78 return(-1);
79 }
80
81 if (fstat(fileno(ibuf), &stb) < 0) {
82 return(-1);
83 }
84
85 if (fstat(fileno(ibuf), &stb) < 0) {
82 perror("fstat");
86 warn("fstat");
83 Fclose(ibuf);
84 return (-1);
85 }
86
87 Fclose(ibuf);
88 return (-1);
89 }
90
87 switch (stb.st_mode & S_IFMT) {
88 case S_IFDIR:
91 if (S_ISDIR(stb.st_mode) || !S_ISREG(stb.st_mode)) {
89 Fclose(ibuf);
92 Fclose(ibuf);
90 errno = EISDIR;
91 perror(name);
93 errno = S_ISDIR(stb.st_mode) ? EISDIR : EINVAL;
94 warn("%s", name);
92 return (-1);
95 return (-1);
93
94 case S_IFREG:
95 break;
96
97 default:
98 Fclose(ibuf);
99 errno = EINVAL;
100 perror(name);
101 return (-1);
102 }
103
104 /*
105 * Looks like all will be well. We must now relinquish our
106 * hold on the current set of stuff. Must hold signals
107 * while we are reading the new file, else we will ruin
108 * the message[] data structure.
109 */

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

123 else
124 close(i);
125 if (shudclob) {
126 fclose(itf);
127 fclose(otf);
128 }
129 shudclob = 1;
130 edit = isedit;
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
101 * while we are reading the new file, else we will ruin
102 * the message[] data structure.
103 */

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

117 else
118 close(i);
119 if (shudclob) {
120 fclose(itf);
121 fclose(otf);
122 }
123 shudclob = 1;
124 edit = isedit;
131 strcpy(prevfile, mailname);
125 strlcpy(prevfile, mailname, sizeof(prevfile));
132 if (name != mailname)
126 if (name != mailname)
133 strcpy(mailname, name);
127 strlcpy(mailname, name, sizeof(mailname));
134 mailsize = fsize(ibuf);
128 mailsize = fsize(ibuf);
135 if ((otf = fopen(tempMesg, "w")) == NULL) {
136 perror(tempMesg);
137 exit(1);
138 }
129 snprintf(tempname, sizeof(tempname), "%s/mail.RxXXXXXXXXXX", tmpdir);
130 if ((fd = mkstemp(tempname)) == -1 || (otf = fdopen(fd, "w")) == NULL)
131 err(1, "%s", tempname);
139 (void) fcntl(fileno(otf), F_SETFD, 1);
132 (void) fcntl(fileno(otf), F_SETFD, 1);
140 if ((itf = fopen(tempMesg, "r")) == NULL) {
141 perror(tempMesg);
142 exit(1);
143 }
133 if ((itf = fopen(tempname, "r")) == NULL)
134 err(1, "%s", tempname);
144 (void) fcntl(fileno(itf), F_SETFD, 1);
135 (void) fcntl(fileno(itf), F_SETFD, 1);
145 rm(tempMesg);
136 rm(tempname);
146 setptr(ibuf);
147 setmsize(msgCount);
148 Fclose(ibuf);
149 relsesigs();
150 sawcom = 0;
151 if (!edit && msgCount == 0) {
152nomail:
153 fprintf(stderr, "No mail for %s\n", who);

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

268 if (sourcing) {
269 printf("Can't \"!\" while sourcing\n");
270 goto out;
271 }
272 shell(cp+1);
273 return(0);
274 }
275 cp2 = word;
137 setptr(ibuf);
138 setmsize(msgCount);
139 Fclose(ibuf);
140 relsesigs();
141 sawcom = 0;
142 if (!edit && msgCount == 0) {
143nomail:
144 fprintf(stderr, "No mail for %s\n", who);

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

259 if (sourcing) {
260 printf("Can't \"!\" while sourcing\n");
261 goto out;
262 }
263 shell(cp+1);
264 return(0);
265 }
266 cp2 = word;
276 while (*cp && index(" \t0123456789$^.:/-+*'\"", *cp) == NOSTR)
267 while (*cp && strchr(" \t0123456789$^.:/-+*'\"", *cp) == NOSTR)
277 *cp2++ = *cp++;
278 *cp2 = '\0';
279
280 /*
281 * Look up the command; if not found, bitch.
282 * Normally, a blank command would map to the
283 * first command in the table; while sourcing,
284 * however, we ignore blank lines to eliminate

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

400 /*
401 * Just the constant zero, for exiting,
402 * eg.
403 */
404 e = (*com->c_func)(0);
405 break;
406
407 default:
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

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

391 /*
392 * Just the constant zero, for exiting,
393 * eg.
394 */
395 e = (*com->c_func)(0);
396 break;
397
398 default:
408 panic("Unknown argtype");
399 errx(1, "Unknown argtype");
409 }
410
411out:
412 /*
413 * Exit the current source file on
414 * error.
415 */
416 if (e) {

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

458{
459 register struct cmd *cp;
460 extern struct cmd cmdtab[];
461
462 /*
463 * ignore trailing chars after `#'
464 *
465 * lines with beginning `#' are comments
400 }
401
402out:
403 /*
404 * Exit the current source file on
405 * error.
406 */
407 if (e) {

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

449{
450 register struct cmd *cp;
451 extern struct cmd cmdtab[];
452
453 /*
454 * ignore trailing chars after `#'
455 *
456 * lines with beginning `#' are comments
466 * spaces befor `#' are ignored in execute()
457 * spaces before `#' are ignored in execute()
467 */
468
469 if (*word == '#')
470 *(word+1) = '\0';
471
472
473 for (cp = &cmdtab[0]; cp->c_name != NOSTR; cp++)
474 if (isprefix(word, cp->c_name))

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

583 * Announce information about the file we are editing.
584 * Return a likely place to set dot.
585 */
586int
587newfileinfo()
588{
589 register struct message *mp;
590 register int u, n, mdot, d, s;
458 */
459
460 if (*word == '#')
461 *(word+1) = '\0';
462
463
464 for (cp = &cmdtab[0]; cp->c_name != NOSTR; cp++)
465 if (isprefix(word, cp->c_name))

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

574 * Announce information about the file we are editing.
575 * Return a likely place to set dot.
576 */
577int
578newfileinfo()
579{
580 register struct message *mp;
581 register int u, n, mdot, d, s;
591 char fname[BUFSIZ], zname[BUFSIZ], *ename;
582 char fname[PATHSIZE+1], zname[PATHSIZE+1], *ename;
592
593 for (mp = &message[0]; mp < &message[msgCount]; mp++)
594 if (mp->m_flag & MNEW)
595 break;
596 if (mp >= &message[msgCount])
597 for (mp = &message[0]; mp < &message[msgCount]; mp++)
598 if ((mp->m_flag & MREAD) == 0)
599 break;

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

608 if ((mp->m_flag & MREAD) == 0)
609 u++;
610 if (mp->m_flag & MDELETED)
611 d++;
612 if (mp->m_flag & MSAVED)
613 s++;
614 }
615 ename = mailname;
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)
590 break;

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

599 if ((mp->m_flag & MREAD) == 0)
600 u++;
601 if (mp->m_flag & MDELETED)
602 d++;
603 if (mp->m_flag & MSAVED)
604 s++;
605 }
606 ename = mailname;
616 if (getfold(fname) >= 0) {
607 if (getfold(fname, sizeof(fname) - 1) >= 0) {
617 strcat(fname, "/");
618 if (strncmp(fname, mailname, strlen(fname)) == 0) {
608 strcat(fname, "/");
609 if (strncmp(fname, mailname, strlen(fname)) == 0) {
619 sprintf(zname, "+%s", mailname + strlen(fname));
610 snprintf(zname, sizeof(zname), "+%s", mailname + strlen(fname));
620 ename = zname;
621 }
622 }
623 printf("\"%s\": ", ename);
624 if (msgCount == 1)
625 printf("1 message");
626 else
627 printf("%d messages", msgCount);

--- 50 unchanged lines hidden ---
611 ename = zname;
612 }
613 }
614 printf("\"%s\": ", ename);
615 if (msgCount == 1)
616 printf("1 message");
617 else
618 printf("%d messages", msgCount);

--- 50 unchanged lines hidden ---