modified to work with new stdio; added retain command; fixed several bugs
authorSerge ??? <serge@ucbvax.Berkeley.EDU>
Fri, 19 Apr 1985 09:20:34 +0000 (01:20 -0800)
committerSerge ??? <serge@ucbvax.Berkeley.EDU>
Fri, 19 Apr 1985 09:20:34 +0000 (01:20 -0800)
SCCS-vsn: usr.bin/mail/lex.c 2.17
SCCS-vsn: usr.bin/mail/cmdtab.c 2.11
SCCS-vsn: usr.bin/mail/def.h 2.15
SCCS-vsn: usr.bin/mail/glob.h 2.11
SCCS-vsn: usr.bin/mail/aux.c 2.12
SCCS-vsn: usr.bin/mail/cmd2.c 2.13

usr/src/usr.bin/mail/aux.c
usr/src/usr.bin/mail/cmd2.c
usr/src/usr.bin/mail/cmdtab.c
usr/src/usr.bin/mail/def.h
usr/src/usr.bin/mail/glob.h
usr/src/usr.bin/mail/lex.c

index fa7a506..516b609 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)aux.c      2.11 (Berkeley) %G%";
+static char *sccsid = "@(#)aux.c       2.12 (Berkeley) %G%";
 #endif
 
 #include "rcv.h"
 #endif
 
 #include "rcv.h"
@@ -384,7 +384,7 @@ struct sstack {
        FILE    *s_file;                /* File we were in. */
        int     s_cond;                 /* Saved state of conditionals */
        int     s_loading;              /* Loading .mailrc, etc. */
        FILE    *s_file;                /* File we were in. */
        int     s_cond;                 /* Saved state of conditionals */
        int     s_loading;              /* Loading .mailrc, etc. */
-} sstack[_NFILE];
+} sstack[NOFILE];
 
 /*
  * Pushdown current input file and switch to a new one.
 
 /*
  * Pushdown current input file and switch to a new one.
@@ -404,7 +404,7 @@ source(name)
                perror(cp);
                return(1);
        }
                perror(cp);
                return(1);
        }
-       if (ssp >= _NFILE-2) {
+       if (ssp >= NOFILE - 2) {
                printf("Too much \"sourcing\" going on.\n");
                fclose(fi);
                return(1);
                printf("Too much \"sourcing\" going on.\n");
                fclose(fi);
                return(1);
@@ -503,7 +503,7 @@ blankline(linebuf)
        register char *cp;
 
        for (cp = linebuf; *cp; cp++)
        register char *cp;
 
        for (cp = linebuf; *cp; cp++)
-               if (!any(*cp, " \t"))
+               if (*cp != ' ' && *cp != '\t')
                        return(0);
        return(1);
 }
                        return(0);
        return(1);
 }
@@ -543,6 +543,7 @@ skin(name)
        register char *cp, *cp2;
        int gotlt, lastsp;
        char nbuf[BUFSIZ];
        register char *cp, *cp2;
        int gotlt, lastsp;
        char nbuf[BUFSIZ];
+       int nesting;
 
        if (name == NOSTR)
                return(NOSTR);
 
        if (name == NOSTR)
                return(NOSTR);
@@ -554,10 +555,21 @@ skin(name)
        for (cp = name, cp2 = nbuf; c = *cp++; ) {
                switch (c) {
                case '(':
        for (cp = name, cp2 = nbuf; c = *cp++; ) {
                switch (c) {
                case '(':
-                       while (*cp != ')' && *cp != 0)
-                               cp++;
-                       if (*cp)
-                               cp++;
+                       nesting = 1;
+                       while (*cp != '\0') {
+                               switch (*cp++) {
+                               case '(':
+                                       nesting++;
+                                       break;
+
+                               case ')':
+                                       --nesting;
+                                       break;
+                               }
+
+                               if (nesting <= 0)
+                                       break;
+                       }
                        lastsp = 0;
                        break;
 
                        lastsp = 0;
                        break;
 
@@ -767,13 +779,28 @@ isign(field)
        char *field;
 {
        char realfld[BUFSIZ];
        char *field;
 {
        char realfld[BUFSIZ];
-       register int h;
-       register struct ignore *igp;
 
 
+       /*
+        * Lower-case the string, so that "Status" and "status"
+        * will hash to the same place.
+        */
        istrcpy(realfld, field);
        istrcpy(realfld, field);
-       h = hash(realfld);
-       for (igp = ignore[h]; igp != 0; igp = igp->i_link)
-               if (strcmp(igp->i_field, realfld) == 0)
-                       return(1);
-       return(0);
+
+       if (nretained > 0)
+               return (!member(realfld, retain));
+       else
+               return (member(realfld, ignore));
+}
+
+member(realfield, table)
+       register char *realfield;
+       register struct ignore **table;
+{
+       register struct ignore *igp;
+
+       for (igp = table[hash(realfield)]; igp != 0; igp = igp->i_link)
+               if (equal(igp->i_field, realfield))
+                       return (1);
+
+       return (0);
 }
 }
index 1cbb6b4..0eedfbb 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)cmd2.c     2.12 (Berkeley) %G%";
+static char *sccsid = "@(#)cmd2.c      2.13 (Berkeley) %G%";
 #endif
 
 #include "rcv.h"
 #endif
 
 #include "rcv.h"
@@ -445,6 +445,67 @@ 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.
 /*
  * Add the given header fields to the ignored list.
  * If no arguments, print the current list of ignored fields.
index e33de13..afbd66a 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)cmdtab.c   2.10 (Berkeley) %G%";
+static char *sccsid = "@(#)cmdtab.c    2.11 (Berkeley) %G%";
 #endif
 
 #include "def.h"
 #endif
 
 #include "def.h"
@@ -17,7 +17,7 @@ extern int messize(), psalloc(), deltype(), unset(), set(), source();
 extern int pversion(), group(), top(), core(), null(), stouch(), visual();
 extern int swrite(), dosh(), file(), echo(), Respond(), scroll(), ifcmd();
 extern int elsecmd(), endifcmd(), mboxit(), clobber(), alternates();
 extern int pversion(), group(), top(), core(), null(), stouch(), visual();
 extern int swrite(), dosh(), file(), echo(), Respond(), scroll(), ifcmd();
 extern int elsecmd(), endifcmd(), mboxit(), clobber(), alternates();
-extern int local(), folders(), igfield(), Type();
+extern int local(), folders(), igfield(), Type(), retfield();
 
 struct cmd cmdtab[] = {
        "next",         next,           NDMLIST,        0,      MMNDEL,
 
 struct cmd cmdtab[] = {
        "next",         next,           NDMLIST,        0,      MMNDEL,
@@ -76,6 +76,7 @@ struct cmd cmdtab[] = {
        "alternates",   alternates,     M|RAWLIST,      0,      1000,
        "ignore",       igfield,        M|RAWLIST,      0,      1000,
        "discard",      igfield,        M|RAWLIST,      0,      1000,
        "alternates",   alternates,     M|RAWLIST,      0,      1000,
        "ignore",       igfield,        M|RAWLIST,      0,      1000,
        "discard",      igfield,        M|RAWLIST,      0,      1000,
+       "retain",       retfield,       M|RAWLIST,      0,      1000,
        "core",         core,           M|NOLIST,       0,      0,
        "#",            null,           M|NOLIST,       0,      0,
        "clobber",      clobber,        M|RAWLIST,      0,      1,
        "core",         core,           M|NOLIST,       0,      0,
        "#",            null,           M|NOLIST,       0,      0,
        "clobber",      clobber,        M|RAWLIST,      0,      1,
index 215b78e..6005325 100644 (file)
@@ -1,6 +1,6 @@
-/*     def.h   2.14    85/01/09        */
+/*     def.h   2.15    85/04/18        */
 
 
-#include <sys/types.h>
+#include <sys/param.h>         /* includes <sys/types.h> */
 #include <signal.h>
 #include <stdio.h>
 #include <sgtty.h>
 #include <signal.h>
 #include <stdio.h>
 #include <sgtty.h>
index 5c1a135..ce2601f 100644 (file)
@@ -1,4 +1,4 @@
-/*     glob.h  2.10    83/08/11        */
+/*     glob.h  2.11    85/04/18        */
 
 /*
  * A bunch of global variable declarations lie herein.
 
 /*
  * A bunch of global variable declarations lie herein.
@@ -52,6 +52,8 @@ struct        message *message;               /* The actual message structure */
 struct var     *variables[HSHSIZE];    /* Pointer to active var list */
 struct grouphead       *groups[HSHSIZE];/* Pointer to active groups */
 struct ignore          *ignore[HSHSIZE];/* Pointer to ignored fields */
 struct var     *variables[HSHSIZE];    /* Pointer to active var list */
 struct grouphead       *groups[HSHSIZE];/* Pointer to active groups */
 struct ignore          *ignore[HSHSIZE];/* Pointer to ignored fields */
+struct ignore          *retain[HSHSIZE];/* Pointer to retained fields */
+int    nretained;                      /* Number of retained fields */
 char   **altnames;                     /* List of alternate names for user */
 char   **localnames;                   /* List of aliases for our local host */
 int    debug;                          /* Debug flag set */
 char   **altnames;                     /* List of alternate names for user */
 char   **localnames;                   /* List of aliases for our local host */
 int    debug;                          /* Debug flag set */
index 8212a96..904f68f 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)lex.c      2.16 (Berkeley) %G%";
+static char *sccsid = "@(#)lex.c       2.17 (Berkeley) %G%";
 #endif
 
 #include "rcv.h"
 #endif
 
 #include "rcv.h"
@@ -499,6 +499,34 @@ isprefix(as1, as2)
 
 int    inithdr;                        /* am printing startup headers */
 
 
 int    inithdr;                        /* am printing startup headers */
 
+#ifdef _NFILE
+static
+_fwalk(function)
+       register int (*function)();
+{
+       register FILE *iop;
+
+       for (iop = _iob; iop < _iob + _NFILE; iop++)
+               (*function)(iop);
+}
+#endif
+
+static
+xclose(iop)
+       register FILE *iop;
+{
+       if (iop == stdin || iop == stdout ||
+           iop == stderr || iop == itf || iop == otf)
+               return;
+
+       if (iop != pipef)
+               fclose(iop);
+       else {
+               pclose(pipef);
+               pipef = NULL;
+       }
+}
+
 stop(s)
 {
        register FILE *fp;
 stop(s)
 {
        register FILE *fp;
@@ -513,20 +541,12 @@ stop(s)
        while (sourcing)
                unstack();
        getuserid((char *) -1);
        while (sourcing)
                unstack();
        getuserid((char *) -1);
-       for (fp = &_iob[0]; fp < &_iob[_NFILE]; fp++) {
-               if (fp == stdin || fp == stdout)
-                       continue;
-               if (fp == itf || fp == otf)
-                       continue;
-               if (fp == stderr)
-                       continue;
-               if (fp == pipef) {
-                       pclose(pipef);
-                       pipef = NULL;
-                       continue;
-               }
-               fclose(fp);
-       }
+
+       /*
+        * Walk through all the open FILEs, applying xclose() to them
+        */
+       _fwalk(xclose);
+
        if (image >= 0) {
                close(image);
                image = -1;
        if (image >= 0) {
                close(image);
                image = -1;