X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/eed74ec1281870c32edff41385ffeea5bd5bc75d..e9392205b1e4f29ca7c63a1df58c77bfb3e289cf:/usr/src/usr.bin/mail/cmd2.c diff --git a/usr/src/usr.bin/mail/cmd2.c b/usr/src/usr.bin/mail/cmd2.c index c6320dddae..cdb94fbde2 100644 --- a/usr/src/usr.bin/mail/cmd2.c +++ b/usr/src/usr.bin/mail/cmd2.c @@ -1,7 +1,22 @@ -# +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that this notice is preserved and that due credit is given + * to the University of California at Berkeley. The name of the University + * may not be used to endorse or promote products derived from this + * software without specific prior written permission. This software + * is provided ``as is'' without express or implied warranty. + */ + +#ifdef notdef +static char sccsid[] = "@(#)cmd2.c 5.6 (Berkeley) %G%"; +#endif /* notdef */ #include "rcv.h" #include +#include /* * Mail -- a mail program @@ -9,8 +24,6 @@ * More user commands. */ -static char *SccsId = "@(#)cmd2.c 2.7 %G%"; - /* * If any arguments were given, go to the next applicable argument * following dot, otherwise, go to the next applicable message. @@ -122,7 +135,8 @@ save1(str, mark) register int *ip, mesg; register struct message *mp; char *file, *disp, *cmd; - int f, *msgvec, lc, cc, t; + int f, *msgvec, lc, t; + long cc; FILE *obuf; struct stat statb; @@ -143,7 +157,7 @@ save1(str, mark) if ((file = expand(file)) == NOSTR) return(1); printf("\"%s\" ", file); - flush(); + fflush(stdout); if (stat(file, &statb) >= 0) disp = "[Appended]"; else @@ -152,18 +166,19 @@ save1(str, mark) perror(NOSTR); return(1); } - cc = lc = 0; + cc = 0L; + lc = 0; for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { mesg = *ip; touch(mesg); mp = &message[mesg-1]; - if ((t = send(mp, obuf, 0)) < 0) { + if ((t = send(mp, obuf, saveignore)) < 0) { perror(file); fclose(obuf); return(1); } lc += t; - cc += msize(mp); + cc += mp->m_size; if (mark) mp->m_flag |= MSAVED; } @@ -171,7 +186,7 @@ save1(str, mark) if (ferror(obuf)) perror(file); fclose(obuf); - printf("%s %d/%d\n", disp, lc, cc); + printf("%s %d/%ld\n", disp, lc, cc); return(0); } @@ -207,7 +222,7 @@ swrite(str) if (f && getmsglist(str, msgvec, 0) < 0) return(1); printf("\"%s\" ", file); - flush(); + fflush(stdout); if (stat(file, &statb) >= 0) disp = "[Appended]"; else @@ -222,8 +237,12 @@ swrite(str) touch(mesg); mp = &message[mesg-1]; mesf = setinput(mp); - t = mp->m_lines - 2; - readline(mesf, linebuf); + t = mp->m_lines - 1; + while (t-- > 0) { + readline(mesf, linebuf); + if (blankline(linebuf)) + break; + } while (t-- > 0) { fgets(linebuf, BUFSIZ, mesf); fputs(linebuf, obuf); @@ -263,7 +282,7 @@ snarf(linebuf, flag) * Strip away trailing blanks. */ - while (*cp == ' ' && cp > linebuf) + while (cp > linebuf && isspace(*cp)) cp--; *++cp = 0; @@ -271,13 +290,13 @@ snarf(linebuf, flag) * Now search for the beginning of the file name. */ - while (cp > linebuf && !any(*cp, "\t ")) + while (cp > linebuf && !isspace(*cp)) cp--; if (*cp == '\0') { printf("No file specified.\n"); return(NOSTR); } - if (any(*cp, " \t")) + if (isspace(*cp)) *cp++ = 0; else *flag = 0; @@ -392,14 +411,13 @@ undelete(msgvec) core() { register int pid; - int status; + union wait status; if ((pid = vfork()) == -1) { perror("fork"); return(1); } if (pid == 0) { - sigchild(); abort(); _exit(1); } @@ -407,10 +425,11 @@ core() fflush(stdout); while (wait(&status) != pid) ; - if (status & 0200) + if (status.w_coredump) printf(" -- Core dumped\n"); else printf("\n"); + return 0; } /* @@ -443,6 +462,17 @@ clob1(n) clob1(n - 1); } +/* + * Add the given header fields to the retained list. + * If no arguments, print the current list of retained fields. + */ +retfield(list) + char *list[]; +{ + + return ignore1(list, ignore + 1, "retained"); +} + /* * Add the given header fields to the ignored list. * If no arguments, print the current list of ignored fields. @@ -450,40 +480,86 @@ clob1(n) igfield(list) char *list[]; { + + return ignore1(list, ignore, "ignored"); +} + +saveretfield(list) + char *list[]; +{ + + return ignore1(list, saveignore + 1, "retained"); +} + +saveigfield(list) + char *list[]; +{ + + return ignore1(list, saveignore, "ignored"); +} + +ignore1(list, tab, which) + char *list[]; + struct ignoretab *tab; + char *which; +{ char field[BUFSIZ]; register int h; register struct ignore *igp; char **ap; if (argcount(list) == 0) - return(igshow()); + return igshow(tab, which); for (ap = list; *ap != 0; ap++) { istrcpy(field, *ap); + if (member(field, tab)) + continue; h = hash(field); igp = (struct ignore *) calloc(1, sizeof (struct ignore)); - igp->i_field = calloc(strlen(field) + 1, sizeof (char)); + igp->i_field = calloc((unsigned) strlen(field) + 1, + sizeof (char)); strcpy(igp->i_field, field); - igp->i_link = ignore[h]; - ignore[h] = igp; + igp->i_link = tab->i_head[h]; + tab->i_head[h] = igp; + tab->i_count++; } - return(0); + return 0; } /* - * Print out all currently ignored fields. + * Print out all currently retained fields. */ -igshow() +igshow(tab, which) + struct ignoretab *tab; + char *which; { - register int h, did; + register int h; struct ignore *igp; + char **ap, **ring; + int igcomp(); - did = 0; + if (tab->i_count == 0) { + printf("No fields currently being %s.\n", which); + return 0; + } + ring = (char **) salloc((tab->i_count + 1) * sizeof (char *)); + ap = ring; for (h = 0; h < HSHSIZE; h++) - for (igp = ignore[h]; igp != 0; igp = igp->i_link) { - printf("%s\n", igp->i_field); - did++; - } - if (!did) - printf("No fields currently being ignored.\n"); - return(0); + for (igp = tab->i_head[h]; igp != 0; igp = igp->i_link) + *ap++ = igp->i_field; + *ap = 0; + qsort((char *) ring, tab->i_count, sizeof (char *), igcomp); + for (ap = ring; *ap != 0; ap++) + printf("%s\n", *ap); + return 0; +} + +/* + * Compare two names for sorting ignored field list. + */ +igcomp(l, r) + char **l, **r; +{ + + return strcmp(*l, *r); }