-#
+/*
+ * 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 <sys/stat.h>
+#include <sys/wait.h>
/*
* Mail -- a mail program
* More user commands.
*/
-static char *SccsId = "@(#)cmd2.c 2.8 %G%";
-
/*
* If any arguments were given, go to the next applicable argument
* following dot, otherwise, go to the next applicable message.
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;
if ((file = expand(file)) == NOSTR)
return(1);
printf("\"%s\" ", file);
- flush();
+ fflush(stdout);
if (stat(file, &statb) >= 0)
disp = "[Appended]";
else
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;
}
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);
}
if (f && getmsglist(str, msgvec, 0) < 0)
return(1);
printf("\"%s\" ", file);
- flush();
+ fflush(stdout);
if (stat(file, &statb) >= 0)
disp = "[Appended]";
else
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);
* Strip away trailing blanks.
*/
- while (*cp == ' ' && cp > linebuf)
+ while (cp > linebuf && isspace(*cp))
cp--;
*++cp = 0;
* 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;
core()
{
register int pid;
- int status;
+ union wait status;
if ((pid = vfork()) == -1) {
perror("fork");
return(1);
}
if (pid == 0) {
- sigchild();
abort();
_exit(1);
}
fflush(stdout);
while (wait(&status) != pid)
;
- if (status & 0200)
+ if (status.w_coredump)
printf(" -- Core dumped\n");
else
printf("\n");
+ return 0;
}
/*
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.
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++) {
- if (isign(*ap))
- continue;
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, count;
+ register int h;
struct ignore *igp;
char **ap, **ring;
int igcomp();
- count = 0;
- for (h = 0; h < HSHSIZE; h++)
- for (igp = ignore[h]; igp != 0; igp = igp->i_link)
- count++;
- if (count == 0) {
- printf("No fields currently being ignored.\n");
- return(0);
+ if (tab->i_count == 0) {
+ printf("No fields currently being %s.\n", which);
+ return 0;
}
- ring = (char **) alloca((count + 1) * sizeof (char *));
+ 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)
+ for (igp = tab->i_head[h]; igp != 0; igp = igp->i_link)
*ap++ = igp->i_field;
*ap = 0;
- qsort(ring, count, sizeof (char *), igcomp);
+ qsort((char *) ring, tab->i_count, sizeof (char *), igcomp);
for (ap = ring; *ap != 0; ap++)
printf("%s\n", *ap);
- return(0);
+ return 0;
}
/*
char **l, **r;
{
- return(strcmp(*l, *r));
+ return strcmp(*l, *r);
}