date and time created 83/02/11 15:44:29 by rrh
[unix-history] / usr / src / usr.bin / mail / aux.c
index bf19be8..cac91df 100644 (file)
@@ -2,7 +2,6 @@
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
-#include <sgtty.h>
 #include <ctype.h>
 
 /*
 #include <ctype.h>
 
 /*
@@ -11,7 +10,7 @@
  * Auxiliary functions.
  */
 
  * Auxiliary functions.
  */
 
-static char *SccsId = "@(#)aux.c       1.7 %G%";
+static char *SccsId = "@(#)aux.c       2.8 %G%";
 
 /*
  * Return a pointer to a dynamic copy of the argument.
 
 /*
  * Return a pointer to a dynamic copy of the argument.
@@ -123,20 +122,6 @@ isdir(name)
        return((sbuf.st_mode & S_IFMT) == S_IFDIR);
 }
 
        return((sbuf.st_mode & S_IFMT) == S_IFDIR);
 }
 
-/*
- * Compute the size in characters of the passed message
- */
-
-unsigned int
-msize(messp)
-       struct message *messp;
-{
-       register struct message *mp;
-
-       mp = messp;
-       return(mp->m_size);
-}
-
 /*
  * Count the number of arguments in the given string raw list.
  */
 /*
  * Count the number of arguments in the given string raw list.
  */
@@ -373,6 +358,21 @@ icequal(s1, s2)
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Copy a string, lowercasing it as we go.
+ */
+istrcpy(dest, src)
+       char *dest, *src;
+{
+       register char *cp, *cp2;
+
+       cp2 = dest;
+       cp = src;
+       do {
+               *cp2++ = little(*cp);
+       } while (*cp++ != 0);
+}
+
 /*
  * The following code deals with input stacking to do source
  * commands.  All but the current file pointer are saved on
 /*
  * The following code deals with input stacking to do source
  * commands.  All but the current file pointer are saved on
@@ -383,6 +383,7 @@ static      int     ssp = -1;               /* Top of file stack */
 struct sstack {
        FILE    *s_file;                /* File we were in. */
        int     s_cond;                 /* Saved state of conditionals */
 struct sstack {
        FILE    *s_file;                /* File we were in. */
        int     s_cond;                 /* Saved state of conditionals */
+       int     s_loading;              /* Loading .mailrc, etc. */
 } sstack[_NFILE];
 
 /*
 } sstack[_NFILE];
 
 /*
@@ -410,6 +411,8 @@ source(name)
        }
        sstack[++ssp].s_file = input;
        sstack[ssp].s_cond = cond;
        }
        sstack[++ssp].s_file = input;
        sstack[ssp].s_cond = cond;
+       sstack[ssp].s_loading = loading;
+       loading = 0;
        cond = CANY;
        input = fi;
        sourcing++;
        cond = CANY;
        input = fi;
        sourcing++;
@@ -447,9 +450,10 @@ unstack()
        if (cond != CANY)
                printf("Unmatched \"if\"\n");
        cond = sstack[ssp].s_cond;
        if (cond != CANY)
                printf("Unmatched \"if\"\n");
        cond = sstack[ssp].s_cond;
+       loading = sstack[ssp].s_loading;
        input = sstack[ssp--].s_file;
        if (ssp < 0)
        input = sstack[ssp--].s_file;
        if (ssp < 0)
-               sourcing = 0;
+               sourcing = loading;
        return(0);
 }
 
        return(0);
 }
 
@@ -480,14 +484,9 @@ alter(name)
        time_p[1] = statb.st_mtime;
        utime(name, time_p);
 #else
        time_p[1] = statb.st_mtime;
        utime(name, time_p);
 #else
-       if ((pid = fork()) != 0)
-               return;
-       clrbuf(stdout);
-       clrbuf(stderr);
-       clrbuf(stdin);
        sleep(1);
        if ((f = open(name, 0)) < 0)
        sleep(1);
        if ((f = open(name, 0)) < 0)
-               exit(1);
+               return;
        read(f, &w, 1);
        exit(0);
 #endif
        read(f, &w, 1);
        exit(0);
 #endif
@@ -518,8 +517,18 @@ char *
 nameof(mp, reptype)
        register struct message *mp;
 {
 nameof(mp, reptype)
        register struct message *mp;
 {
+       register char *cp, *cp2;
 
 
-       return(skin(name1(mp, reptype)));
+       cp = skin(name1(mp, reptype));
+       if (reptype != 0 || charcount(cp, '!') < 2)
+               return(cp);
+       cp2 = rindex(cp, '!');
+       cp2--;
+       while (cp2 > cp && *cp2 != '!')
+               cp2--;
+       if (*cp2 == '!')
+               return(cp2 + 1);
+       return(cp);
 }
 
 /*
 }
 
 /*
@@ -599,7 +608,7 @@ name1(mp, reptype)
        register FILE *ibuf;
        int first = 1;
 
        register FILE *ibuf;
        int first = 1;
 
-#ifndef DELIVERMAIL
+#ifndef SENDMAIL
        if ((cp = hfield("from", mp)) != NOSTR)
                return(cp);
        if (reptype == 0 && (cp = hfield("sender", mp)) != NOSTR)
        if ((cp = hfield("from", mp)) != NOSTR)
                return(cp);
        if (reptype == 0 && (cp = hfield("sender", mp)) != NOSTR)
@@ -646,11 +655,25 @@ newname:
        return(savestr(namebuf));
 }
 
        return(savestr(namebuf));
 }
 
+/*
+ * Count the occurances of c in str
+ */
+charcount(str, c)
+       char *str;
+{
+       register char *cp;
+       register int i;
+
+       for (i = 0, cp = str; *cp; cp++)
+               if (*cp == c)
+                       i++;
+       return(i);
+}
+
 /*
  * Find the rightmost pointer to an instance of the
  * character in the string and return it.
  */
 /*
  * Find the rightmost pointer to an instance of the
  * character in the string and return it.
  */
-
 char *
 rindex(str, c)
        char str[];
 char *
 rindex(str, c)
        char str[];
@@ -731,3 +754,20 @@ strncmp(as1, as2, an)
        return(n<0 ? 0 : *s1 - *--s2);
 }
 
        return(n<0 ? 0 : *s1 - *--s2);
 }
 
+/*
+ * See if the given header field is supposed to be ignored.
+ */
+isign(field)
+       char *field;
+{
+       char realfld[BUFSIZ];
+       register int h;
+       register struct ignore *igp;
+
+       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);
+}