Add define for Kirk Smith's USR Courier driver. Change default baud
[unix-history] / usr / src / usr.bin / mail / cmd2.c
index b46d6aa..6f99a87 100644 (file)
@@ -1,4 +1,12 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)cmd2.c      5.3 (Berkeley) %G%";
+#endif not lint
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
@@ -9,8 +17,6 @@
  * More user commands.
  */
 
  * More user commands.
  */
 
-static char *SccsId = "@(#)cmd2.c      2.6 %G%";
-
 /*
  * If any arguments were given, go to the next applicable argument
  * following dot, otherwise, go to the next applicable message.
 /*
  * If any arguments were given, go to the next applicable argument
  * following dot, otherwise, go to the next applicable message.
@@ -122,7 +128,8 @@ save1(str, mark)
        register int *ip, mesg;
        register struct message *mp;
        char *file, *disp, *cmd;
        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;
 
        FILE *obuf;
        struct stat statb;
 
@@ -143,7 +150,7 @@ save1(str, mark)
        if ((file = expand(file)) == NOSTR)
                return(1);
        printf("\"%s\" ", file);
        if ((file = expand(file)) == NOSTR)
                return(1);
        printf("\"%s\" ", file);
-       flush();
+       fflush(stdout);
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
@@ -152,18 +159,19 @@ save1(str, mark)
                perror(NOSTR);
                return(1);
        }
                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];
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
-               if ((t = send(mp, obuf)) < 0) {
+               if ((t = send(mp, obuf, 0)) < 0) {
                        perror(file);
                        fclose(obuf);
                        return(1);
                }
                lc += t;
                        perror(file);
                        fclose(obuf);
                        return(1);
                }
                lc += t;
-               cc += msize(mp);
+               cc += mp->m_size;
                if (mark)
                        mp->m_flag |= MSAVED;
        }
                if (mark)
                        mp->m_flag |= MSAVED;
        }
@@ -171,7 +179,7 @@ save1(str, mark)
        if (ferror(obuf))
                perror(file);
        fclose(obuf);
        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);
 }
 
        return(0);
 }
 
@@ -207,7 +215,7 @@ swrite(str)
        if (f && getmsglist(str, msgvec, 0) < 0)
                return(1);
        printf("\"%s\" ", file);
        if (f && getmsglist(str, msgvec, 0) < 0)
                return(1);
        printf("\"%s\" ", file);
-       flush();
+       fflush(stdout);
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
@@ -222,8 +230,12 @@ swrite(str)
                touch(mesg);
                mp = &message[mesg-1];
                mesf = setinput(mp);
                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);
                while (t-- > 0) {
                        fgets(linebuf, BUFSIZ, mesf);
                        fputs(linebuf, obuf);
@@ -442,3 +454,132 @@ clob1(n)
                ;
        clob1(n - 1);
 }
                ;
        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[];
+{
+       char field[BUFSIZ];
+       register int h;
+       register struct ignore *igp;
+       char **ap;
+
+       if (argcount(list) == 0)
+               return(retshow());
+       for (ap = list; *ap != 0; ap++) {
+               istrcpy(field, *ap);
+
+               if (member(field, retain))
+                       continue;
+
+               h = hash(field);
+               igp = (struct ignore *) calloc(1, sizeof (struct ignore));
+               igp->i_field = calloc(strlen(field) + 1, sizeof (char));
+               strcpy(igp->i_field, field);
+               igp->i_link = retain[h];
+               retain[h] = igp;
+               nretained++;
+       }
+       return(0);
+}
+
+/*
+ * Print out all currently retained fields.
+ */
+retshow()
+{
+       register int h, count;
+       struct ignore *igp;
+       char **ap, **ring;
+       int igcomp();
+
+       count = 0;
+       for (h = 0; h < HSHSIZE; h++)
+               for (igp = retain[h]; igp != 0; igp = igp->i_link)
+                       count++;
+       if (count == 0) {
+               printf("No fields currently being retained.\n");
+               return(0);
+       }
+       ring = (char **) salloc((count + 1) * sizeof (char *));
+       ap = ring;
+       for (h = 0; h < HSHSIZE; h++)
+               for (igp = retain[h]; igp != 0; igp = igp->i_link)
+                       *ap++ = igp->i_field;
+       *ap = 0;
+       qsort(ring, count, sizeof (char *), igcomp);
+       for (ap = ring; *ap != 0; ap++)
+               printf("%s\n", *ap);
+       return(0);
+}
+
+/*
+ * Add the given header fields to the ignored list.
+ * If no arguments, print the current list of ignored fields.
+ */
+igfield(list)
+       char *list[];
+{
+       char field[BUFSIZ];
+       register int h;
+       register struct ignore *igp;
+       char **ap;
+
+       if (argcount(list) == 0)
+               return(igshow());
+       for (ap = list; *ap != 0; ap++) {
+               if (isign(*ap))
+                       continue;
+               istrcpy(field, *ap);
+               h = hash(field);
+               igp = (struct ignore *) calloc(1, sizeof (struct ignore));
+               igp->i_field = calloc(strlen(field) + 1, sizeof (char));
+               strcpy(igp->i_field, field);
+               igp->i_link = ignore[h];
+               ignore[h] = igp;
+       }
+       return(0);
+}
+
+/*
+ * Print out all currently ignored fields.
+ */
+igshow()
+{
+       register int h, count;
+       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);
+       }
+       ring = (char **) salloc((count + 1) * sizeof (char *));
+       ap = ring;
+       for (h = 0; h < HSHSIZE; h++)
+               for (igp = ignore[h]; igp != 0; igp = igp->i_link)
+                       *ap++ = igp->i_field;
+       *ap = 0;
+       qsort(ring, 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));
+}