Deleted Added
full compact
cmd2.c (216370) cmd2.c (216564)
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

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

28 */
29
30#ifndef lint
31#if 0
32static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93";
33#endif
34#endif /* not lint */
35#include <sys/cdefs.h>
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

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

28 */
29
30#ifndef lint
31#if 0
32static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93";
33#endif
34#endif /* not lint */
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/usr.bin/mail/cmd2.c 216370 2010-12-11 08:32:16Z joel $");
36__FBSDID("$FreeBSD: head/usr.bin/mail/cmd2.c 216564 2010-12-19 16:25:23Z charnier $");
37
38#include "rcv.h"
39#include <sys/wait.h>
40#include "extern.h"
41
42/*
43 * Mail -- a mail program
44 *
45 * More user commands.
46 */
47
48extern int wait_status;
49
50/*
51 * If any arguments were given, go to the next applicable argument
52 * following dot, otherwise, go to the next applicable message.
53 * If given as first command with no arguments, print first message.
54 */
55int
37
38#include "rcv.h"
39#include <sys/wait.h>
40#include "extern.h"
41
42/*
43 * Mail -- a mail program
44 *
45 * More user commands.
46 */
47
48extern int wait_status;
49
50/*
51 * If any arguments were given, go to the next applicable argument
52 * following dot, otherwise, go to the next applicable message.
53 * If given as first command with no arguments, print first message.
54 */
55int
56next(msgvec)
57 int *msgvec;
56next(int *msgvec)
58{
59 struct message *mp;
60 int *ip, *ip2, list[2], mdot;
61
62 if (*msgvec != 0) {
63
64 /*
65 * If some messages were supplied, find the

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

126 return (type(list));
127}
128
129/*
130 * Save a message in a file. Mark the message as saved
131 * so we can discard when the user quits.
132 */
133int
57{
58 struct message *mp;
59 int *ip, *ip2, list[2], mdot;
60
61 if (*msgvec != 0) {
62
63 /*
64 * If some messages were supplied, find the

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

125 return (type(list));
126}
127
128/*
129 * Save a message in a file. Mark the message as saved
130 * so we can discard when the user quits.
131 */
132int
134save(str)
135 char str[];
133save(char str[])
136{
137
138 return (save1(str, 1, "save", saveignore));
139}
140
141/*
142 * Copy a message to a file without affected its saved-ness
143 */
144int
134{
135
136 return (save1(str, 1, "save", saveignore));
137}
138
139/*
140 * Copy a message to a file without affected its saved-ness
141 */
142int
145copycmd(str)
146 char str[];
143copycmd(char str[])
147{
148
149 return (save1(str, 0, "copy", saveignore));
150}
151
152/*
153 * Save/copy the indicated messages at the end of the passed file name.
154 * If mark is true, mark the message "saved."
155 */
156int
144{
145
146 return (save1(str, 0, "copy", saveignore));
147}
148
149/*
150 * Save/copy the indicated messages at the end of the passed file name.
151 * If mark is true, mark the message "saved."
152 */
153int
157save1(str, mark, cmd, ignore)
158 char str[];
159 int mark;
160 const char *cmd;
161 struct ignoretab *ignore;
154save1(char str[], int mark, const char *cmd, struct ignoretab *ignore)
162{
163 struct message *mp;
164 char *file;
165 const char *disp;
166 int f, *msgvec, *ip;
167 FILE *obuf;
168
169 msgvec = (int *)salloc((msgCount + 2) * sizeof(*msgvec));

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

210 return (0);
211}
212
213/*
214 * Write the indicated messages at the end of the passed
215 * file name, minus header and trailing blank line.
216 */
217int
155{
156 struct message *mp;
157 char *file;
158 const char *disp;
159 int f, *msgvec, *ip;
160 FILE *obuf;
161
162 msgvec = (int *)salloc((msgCount + 2) * sizeof(*msgvec));

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

203 return (0);
204}
205
206/*
207 * Write the indicated messages at the end of the passed
208 * file name, minus header and trailing blank line.
209 */
210int
218swrite(str)
219 char str[];
211swrite(char str[])
220{
221
222 return (save1(str, 1, "write", ignoreall));
223}
224
225/*
226 * Snarf the file from the end of the command line and
227 * return a pointer to it. If there is no file attached,
228 * just return NULL. Put a null in front of the file
229 * name so that the message list processing won't see it,
230 * unless the file name is the only thing on the line, in
231 * which case, return 0 in the reference flag variable.
232 */
233
234char *
212{
213
214 return (save1(str, 1, "write", ignoreall));
215}
216
217/*
218 * Snarf the file from the end of the command line and
219 * return a pointer to it. If there is no file attached,
220 * just return NULL. Put a null in front of the file
221 * name so that the message list processing won't see it,
222 * unless the file name is the only thing on the line, in
223 * which case, return 0 in the reference flag variable.
224 */
225
226char *
235snarf(linebuf, flag)
236 char linebuf[];
237 int *flag;
227snarf(char linebuf[], int *flag)
238{
239 char *cp;
240
241 *flag = 1;
242 cp = strlen(linebuf) + linebuf - 1;
243
244 /*
245 * Strip away trailing blanks.

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

265 *flag = 0;
266 return (cp);
267}
268
269/*
270 * Delete messages.
271 */
272int
228{
229 char *cp;
230
231 *flag = 1;
232 cp = strlen(linebuf) + linebuf - 1;
233
234 /*
235 * Strip away trailing blanks.

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

255 *flag = 0;
256 return (cp);
257}
258
259/*
260 * Delete messages.
261 */
262int
273delete(msgvec)
274 int msgvec[];
263delete(int msgvec[])
275{
276
277 delm(msgvec);
278 return (0);
279}
280
281/*
282 * Delete messages, then type the new dot.
283 */
284int
264{
265
266 delm(msgvec);
267 return (0);
268}
269
270/*
271 * Delete messages, then type the new dot.
272 */
273int
285deltype(msgvec)
286 int msgvec[];
274deltype(int msgvec[])
287{
288 int list[2];
289 int lastdot;
290
291 lastdot = dot - &message[0] + 1;
292 if (delm(msgvec) >= 0) {
293 list[0] = dot - &message[0] + 1;
294 if (list[0] > lastdot) {

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

303}
304
305/*
306 * Delete the indicated messages.
307 * Set dot to some nice place afterwards.
308 * Internal interface.
309 */
310int
275{
276 int list[2];
277 int lastdot;
278
279 lastdot = dot - &message[0] + 1;
280 if (delm(msgvec) >= 0) {
281 list[0] = dot - &message[0] + 1;
282 if (list[0] > lastdot) {

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

291}
292
293/*
294 * Delete the indicated messages.
295 * Set dot to some nice place afterwards.
296 * Internal interface.
297 */
298int
311delm(msgvec)
312 int *msgvec;
299delm(int *msgvec)
313{
314 struct message *mp;
315 int *ip, last;
316
317 last = 0;
318 for (ip = msgvec; *ip != 0; ip++) {
319 mp = &message[*ip - 1];
320 touch(mp);

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

341
342 return (-1);
343}
344
345/*
346 * Undelete the indicated messages.
347 */
348int
300{
301 struct message *mp;
302 int *ip, last;
303
304 last = 0;
305 for (ip = msgvec; *ip != 0; ip++) {
306 mp = &message[*ip - 1];
307 touch(mp);

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

328
329 return (-1);
330}
331
332/*
333 * Undelete the indicated messages.
334 */
335int
349undelete_messages(msgvec)
350 int *msgvec;
336undelete_messages(int *msgvec)
351{
352 struct message *mp;
353 int *ip;
354
355 for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
356 mp = &message[*ip - 1];
357 touch(mp);
358 dot = mp;
359 mp->m_flag &= ~MDELETED;
360 }
361 return (0);
362}
363
364/*
365 * Interactively dump core on "core"
366 */
367int
337{
338 struct message *mp;
339 int *ip;
340
341 for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
342 mp = &message[*ip - 1];
343 touch(mp);
344 dot = mp;
345 mp->m_flag &= ~MDELETED;
346 }
347 return (0);
348}
349
350/*
351 * Interactively dump core on "core"
352 */
353int
368core()
354core(void)
369{
370 int pid;
371
372 switch (pid = fork()) {
373 case -1:
374 warn("fork");
375 return (1);
376 case 0:

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

386 printf(" -- Can't dump core.\n");
387 return (0);
388}
389
390/*
391 * Clobber as many bytes of stack as the user requests.
392 */
393int
355{
356 int pid;
357
358 switch (pid = fork()) {
359 case -1:
360 warn("fork");
361 return (1);
362 case 0:

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

372 printf(" -- Can't dump core.\n");
373 return (0);
374}
375
376/*
377 * Clobber as many bytes of stack as the user requests.
378 */
379int
394clobber(argv)
395 char **argv;
380clobber(char **argv)
396{
397 int times;
398
399 if (argv[0] == 0)
400 times = 1;
401 else
402 times = (atoi(argv[0]) + 511) / 512;
403 clob1(times);
404 return (0);
405}
406
407/*
408 * Clobber the stack.
409 */
410void
381{
382 int times;
383
384 if (argv[0] == 0)
385 times = 1;
386 else
387 times = (atoi(argv[0]) + 511) / 512;
388 clob1(times);
389 return (0);
390}
391
392/*
393 * Clobber the stack.
394 */
395void
411clob1(n)
412 int n;
396clob1(int n)
413{
414 char buf[512];
415 char *cp;
416
417 if (n <= 0)
418 return;
419 for (cp = buf; cp < &buf[512]; *cp++ = 0xFF)
420 ;
421 clob1(n - 1);
422}
423
424/*
425 * Add the given header fields to the retained list.
426 * If no arguments, print the current list of retained fields.
427 */
428int
397{
398 char buf[512];
399 char *cp;
400
401 if (n <= 0)
402 return;
403 for (cp = buf; cp < &buf[512]; *cp++ = 0xFF)
404 ;
405 clob1(n - 1);
406}
407
408/*
409 * Add the given header fields to the retained list.
410 * If no arguments, print the current list of retained fields.
411 */
412int
429retfield(list)
430 char *list[];
413retfield(char *list[])
431{
432
433 return (ignore1(list, ignore + 1, "retained"));
434}
435
436/*
437 * Add the given header fields to the ignored list.
438 * If no arguments, print the current list of ignored fields.
439 */
440int
414{
415
416 return (ignore1(list, ignore + 1, "retained"));
417}
418
419/*
420 * Add the given header fields to the ignored list.
421 * If no arguments, print the current list of ignored fields.
422 */
423int
441igfield(list)
442 char *list[];
424igfield(char *list[])
443{
444
445 return (ignore1(list, ignore, "ignored"));
446}
447
448int
425{
426
427 return (ignore1(list, ignore, "ignored"));
428}
429
430int
449saveretfield(list)
450 char *list[];
431saveretfield(char *list[])
451{
452
453 return (ignore1(list, saveignore + 1, "retained"));
454}
455
456int
432{
433
434 return (ignore1(list, saveignore + 1, "retained"));
435}
436
437int
457saveigfield(list)
458 char *list[];
438saveigfield(char *list[])
459{
460
461 return (ignore1(list, saveignore, "ignored"));
462}
463
464int
439{
440
441 return (ignore1(list, saveignore, "ignored"));
442}
443
444int
465ignore1(list, tab, which)
466 char *list[];
467 struct ignoretab *tab;
468 const char *which;
445ignore1(char *list[], struct ignoretab *tab, const char *which)
469{
470 char field[LINESIZE];
471 int h;
472 struct ignore *igp;
473 char **ap;
474
475 if (*list == NULL)
476 return (igshow(tab, which));

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

489 }
490 return (0);
491}
492
493/*
494 * Print out all currently retained fields.
495 */
496int
446{
447 char field[LINESIZE];
448 int h;
449 struct ignore *igp;
450 char **ap;
451
452 if (*list == NULL)
453 return (igshow(tab, which));

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

466 }
467 return (0);
468}
469
470/*
471 * Print out all currently retained fields.
472 */
473int
497igshow(tab, which)
498 struct ignoretab *tab;
499 const char *which;
474igshow(struct ignoretab *tab, const char *which)
500{
501 int h;
502 struct ignore *igp;
503 char **ap, **ring;
504
505 if (tab->i_count == 0) {
506 printf("No fields currently being %s.\n", which);
507 return (0);

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

517 printf("%s\n", *ap);
518 return (0);
519}
520
521/*
522 * Compare two names for sorting ignored field list.
523 */
524int
475{
476 int h;
477 struct ignore *igp;
478 char **ap, **ring;
479
480 if (tab->i_count == 0) {
481 printf("No fields currently being %s.\n", which);
482 return (0);

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

492 printf("%s\n", *ap);
493 return (0);
494}
495
496/*
497 * Compare two names for sorting ignored field list.
498 */
499int
525igcomp(l, r)
526 const void *l, *r;
500igcomp(const void *l, const void *r)
527{
528
529 return (strcmp(*(const char **)l, *(const char **)r));
530}
501{
502
503 return (strcmp(*(const char **)l, *(const char **)r));
504}