Deleted Added
full compact
cmd3.c (37453) cmd3.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

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

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
34#ifndef lint
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

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

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
34#ifndef lint
35#if 0
35static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93";
36static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/usr.bin/mail/cmd3.c 74769 2001-03-25 04:57:05Z mikeh $";
36#endif /* not lint */
37
38#include "rcv.h"
39#include "extern.h"
40
41/*
42 * Mail -- a mail program
43 *

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

51int
52shell(str)
53 char *str;
54{
55 sig_t sigint = signal(SIGINT, SIG_IGN);
56 char *shell;
57 char cmd[BUFSIZ];
58
40#endif /* not lint */
41
42#include "rcv.h"
43#include "extern.h"
44
45/*
46 * Mail -- a mail program
47 *

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

55int
56shell(str)
57 char *str;
58{
59 sig_t sigint = signal(SIGINT, SIG_IGN);
60 char *shell;
61 char cmd[BUFSIZ];
62
59 (void) strcpy(cmd, str);
60 if (bangexp(cmd) < 0)
63 if (strlcpy(cmd, str, sizeof(cmd)) >= sizeof(cmd))
61 return 1;
64 return 1;
65 if (bangexp(cmd, sizeof(cmd)) < 0)
66 return 1;
62 if ((shell = value("SHELL")) == NOSTR)
63 shell = _PATH_CSHELL;
64 (void) run_command(shell, 0, -1, -1, "-c", cmd, NOSTR);
65 (void) signal(SIGINT, sigint);
66 printf("!\n");
67 return 0;
68}
69

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

85 putchar('\n');
86 return 0;
87}
88
89/*
90 * Expand the shell escape by expanding unescaped !'s into the
91 * last issued command where possible.
92 */
67 if ((shell = value("SHELL")) == NOSTR)
68 shell = _PATH_CSHELL;
69 (void) run_command(shell, 0, -1, -1, "-c", cmd, NOSTR);
70 (void) signal(SIGINT, sigint);
71 printf("!\n");
72 return 0;
73}
74

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

90 putchar('\n');
91 return 0;
92}
93
94/*
95 * Expand the shell escape by expanding unescaped !'s into the
96 * last issued command where possible.
97 */
93
94char lastbang[128];
95
96int
98int
97bangexp(str)
99bangexp(str, strsize)
98 char *str;
100 char *str;
101 size_t strsize;
99{
100 char bangbuf[BUFSIZ];
102{
103 char bangbuf[BUFSIZ];
104 static char lastbang[BUFSIZ];
101 register char *cp, *cp2;
102 register int n;
103 int changed = 0;
104
105 cp = str;
106 cp2 = bangbuf;
105 register char *cp, *cp2;
106 register int n;
107 int changed = 0;
108
109 cp = str;
110 cp2 = bangbuf;
107 n = BUFSIZ;
111 n = sizeof(bangbuf);
108 while (*cp) {
109 if (*cp == '!') {
110 if (n < strlen(lastbang)) {
111overf:
112 printf("Command buffer overflow\n");
113 return(-1);
114 }
115 changed++;
112 while (*cp) {
113 if (*cp == '!') {
114 if (n < strlen(lastbang)) {
115overf:
116 printf("Command buffer overflow\n");
117 return(-1);
118 }
119 changed++;
116 strcpy(cp2, lastbang);
120 if (strlcpy(cp2, lastbang, sizeof(bangbuf) - (cp2 - bangbuf))
121 >= sizeof(bangbuf) - (cp2 - bangbuf))
122 goto overf;
117 cp2 += strlen(lastbang);
118 n -= strlen(lastbang);
119 cp++;
120 continue;
121 }
122 if (*cp == '\\' && cp[1] == '!') {
123 if (--n <= 1)
124 goto overf;

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

130 goto overf;
131 *cp2++ = *cp++;
132 }
133 *cp2 = 0;
134 if (changed) {
135 printf("!%s\n", bangbuf);
136 fflush(stdout);
137 }
123 cp2 += strlen(lastbang);
124 n -= strlen(lastbang);
125 cp++;
126 continue;
127 }
128 if (*cp == '\\' && cp[1] == '!') {
129 if (--n <= 1)
130 goto overf;

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

136 goto overf;
137 *cp2++ = *cp++;
138 }
139 *cp2 = 0;
140 if (changed) {
141 printf("!%s\n", bangbuf);
142 fflush(stdout);
143 }
138 strcpy(str, bangbuf);
139 strncpy(lastbang, bangbuf, 128);
140 lastbang[127] = 0;
144 if (strlcpy(str, bangbuf, strsize) >= strsize)
145 goto overf;
146 if (strlcpy(lastbang, bangbuf, sizeof(lastbang)) >= sizeof(lastbang))
147 goto overf;
141 return(0);
142}
143
144/*
145 * Print out a nice help message from some file or another.
146 */
147
148int
149help()
150{
151 register c;
152 register FILE *f;
153
154 if ((f = Fopen(_PATH_HELP, "r")) == NULL) {
148 return(0);
149}
150
151/*
152 * Print out a nice help message from some file or another.
153 */
154
155int
156help()
157{
158 register c;
159 register FILE *f;
160
161 if ((f = Fopen(_PATH_HELP, "r")) == NULL) {
155 perror(_PATH_HELP);
162 warn("%s", _PATH_HELP);
156 return(1);
157 }
158 while ((c = getc(f)) != EOF)
159 putchar(c);
160 Fclose(f);
161 return(0);
162}
163
164/*
165 * Change user's working directory.
166 */
167int
168schdir(arglist)
169 char **arglist;
170{
171 char *cp;
172
163 return(1);
164 }
165 while ((c = getc(f)) != EOF)
166 putchar(c);
167 Fclose(f);
168 return(0);
169}
170
171/*
172 * Change user's working directory.
173 */
174int
175schdir(arglist)
176 char **arglist;
177{
178 char *cp;
179
173 if (*arglist == NOSTR)
180 if (*arglist == NOSTR) {
181 if (homedir == NOSTR)
182 return(1);
174 cp = homedir;
183 cp = homedir;
175 else
184 } else
176 if ((cp = expand(*arglist)) == NOSTR)
177 return(1);
178 if (chdir(cp) < 0) {
185 if ((cp = expand(*arglist)) == NOSTR)
186 return(1);
187 if (chdir(cp) < 0) {
179 perror(cp);
188 warn("%s", cp);
180 return(1);
181 }
182 return 0;
183}
184
185int
186respond(msgvec)
187 int *msgvec;

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

271
272 if (subj == NOSTR)
273 return NOSTR;
274 if ((subj[0] == 'r' || subj[0] == 'R') &&
275 (subj[1] == 'e' || subj[1] == 'E') &&
276 subj[2] == ':')
277 return subj;
278 newsubj = salloc(strlen(subj) + 5);
189 return(1);
190 }
191 return 0;
192}
193
194int
195respond(msgvec)
196 int *msgvec;

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

280
281 if (subj == NOSTR)
282 return NOSTR;
283 if ((subj[0] == 'r' || subj[0] == 'R') &&
284 (subj[1] == 'e' || subj[1] == 'E') &&
285 subj[2] == ':')
286 return subj;
287 newsubj = salloc(strlen(subj) + 5);
279 strcpy(newsubj, "Re: ");
280 strcpy(newsubj + 4, subj);
288 sprintf(newsubj, "Re: %s", subj);
281 return newsubj;
282}
283
284/*
285 * Preserve the named messages, so that they will be sent
286 * back to the system mailbox.
287 */
288int

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

381 for (p = ap; *p != NOSTR; p++)
382 printf("%s\t%s\n", *p, value(*p));
383 return(0);
384 }
385 errs = 0;
386 for (ap = arglist; *ap != NOSTR; ap++) {
387 cp = *ap;
388 cp2 = varbuf;
289 return newsubj;
290}
291
292/*
293 * Preserve the named messages, so that they will be sent
294 * back to the system mailbox.
295 */
296int

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

389 for (p = ap; *p != NOSTR; p++)
390 printf("%s\t%s\n", *p, value(*p));
391 return(0);
392 }
393 errs = 0;
394 for (ap = arglist; *ap != NOSTR; ap++) {
395 cp = *ap;
396 cp2 = varbuf;
389 while (*cp != '=' && *cp != '\0')
397 while (cp2 < varbuf + sizeof(varbuf) - 1 && *cp != '=' && *cp != '\0')
390 *cp2++ = *cp++;
391 *cp2 = '\0';
392 if (*cp == '\0')
393 cp = "";
394 else
395 cp++;
396 if (equal(varbuf, "")) {
397 printf("Non-null variable name required\n");

--- 341 unchanged lines hidden ---
398 *cp2++ = *cp++;
399 *cp2 = '\0';
400 if (*cp == '\0')
401 cp = "";
402 else
403 cp++;
404 if (equal(varbuf, "")) {
405 printf("Non-null variable name required\n");

--- 341 unchanged lines hidden ---