bug report from gumkowsk@nadc.arpa (fix is my own),
[unix-history] / usr / src / usr.bin / mail / aux.c
index 89d410f..2e5229c 100644 (file)
@@ -3,16 +3,21 @@
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * 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.
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  */
 
-#ifdef notdef
-static char sccsid[] = "@(#)aux.c      5.9 (Berkeley) %G%";
-#endif /* notdef */
+#ifndef lint
+static char sccsid[] = "@(#)aux.c      5.15 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
@@ -26,22 +31,16 @@ static char sccsid[] = "@(#)aux.c   5.9 (Berkeley) %G%";
 /*
  * Return a pointer to a dynamic copy of the argument.
  */
 /*
  * Return a pointer to a dynamic copy of the argument.
  */
-
 char *
 savestr(str)
        char *str;
 {
 char *
 savestr(str)
        char *str;
 {
-       register char *cp, *cp2, *top;
+       char *new;
+       int size = strlen(str) + 1;
 
 
-       for (cp = str; *cp; cp++)
-               ;
-       top = salloc(cp-str + 1);
-       if (top == NOSTR)
-               return(NOSTR);
-       for (cp = str, cp2 = top; *cp; cp++)
-               *cp2++ = *cp;
-       *cp2 = 0;
-       return(top);
+       if ((new = salloc(size)) != NOSTR)
+               bcopy(str, new, size);
+       return new;
 }
 
 /*
 }
 
 /*
@@ -63,14 +62,10 @@ panic(fmt, a, b)
  * Touched messages have the effect of not being sent
  * back to the system mailbox on exit.
  */
  * Touched messages have the effect of not being sent
  * back to the system mailbox on exit.
  */
-
-touch(mesg)
-{
+touch(mp)
        register struct message *mp;
        register struct message *mp;
+{
 
 
-       if (mesg < 1 || mesg > msgCount)
-               return;
-       mp = &message[mesg-1];
        mp->m_flag |= MTOUCH;
        if ((mp->m_flag & MREAD) == 0)
                mp->m_flag |= MREAD|MSTATUS;
        mp->m_flag |= MTOUCH;
        if ((mp->m_flag & MREAD) == 0)
                mp->m_flag |= MREAD|MSTATUS;
@@ -80,7 +75,6 @@ touch(mesg)
  * Test to see if the passed file name is a directory.
  * Return true if it is.
  */
  * Test to see if the passed file name is a directory.
  * Return true if it is.
  */
-
 isdir(name)
        char name[];
 {
 isdir(name)
        char name[];
 {
@@ -94,7 +88,6 @@ isdir(name)
 /*
  * Count the number of arguments in the given string raw list.
  */
 /*
  * Count the number of arguments in the given string raw list.
  */
-
 argcount(argv)
        char **argv;
 {
 argcount(argv)
        char **argv;
 {
@@ -109,7 +102,6 @@ argcount(argv)
  * Return the desired header line from the passed message
  * pointer (or NOSTR if the desired header field is not available).
  */
  * Return the desired header line from the passed message
  * pointer (or NOSTR if the desired header field is not available).
  */
-
 char *
 hfield(field, mp)
        char field[];
 char *
 hfield(field, mp)
        char field[];
@@ -141,7 +133,6 @@ hfield(field, mp)
  * "colon" is set to point to the colon in the header.
  * Must deal with \ continuations & other such fraud.
  */
  * "colon" is set to point to the colon in the header.
  * Must deal with \ continuations & other such fraud.
  */
-
 gethfield(f, linebuf, rem, colon)
        register FILE *f;
        char linebuf[];
 gethfield(f, linebuf, rem, colon)
        register FILE *f;
        char linebuf[];
@@ -208,7 +199,7 @@ ishfield(linebuf, colon, field)
        register char *cp = colon;
 
        *cp = 0;
        register char *cp = colon;
 
        *cp = 0;
-       if (!icequal(linebuf, field)) {
+       if (strcasecmp(linebuf, field) != 0) {
                *cp = ':';
                return 0;
        }
                *cp = ':';
                return 0;
        }
@@ -218,29 +209,6 @@ ishfield(linebuf, colon, field)
        return cp;
 }
 
        return cp;
 }
 
-/*
- * Compare two strings, ignoring case.
- */
-
-icequal(s1, s2)
-       register char *s1, *s2;
-{
-       register c1, c2;
-
-       for (;;) {
-               if ((c1 = (unsigned char)*s1++) !=
-                   (c2 = (unsigned char)*s2++)) {
-                       if (isupper(c1))
-                               c1 = tolower(c1);
-                       if (c1 != c2)
-                               return 0;
-               }
-               if (c1 == 0)
-                       return 1;
-       }
-       /*NOTREACHED*/
-}
-
 /*
  * Copy a string, lowercasing it as we go.
  */
 /*
  * Copy a string, lowercasing it as we go.
  */
@@ -262,7 +230,7 @@ istrcpy(dest, src)
  * the stack.
  */
 
  * the stack.
  */
 
-static int     ssp = -1;               /* Top of file stack */
+static int     ssp;                    /* 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 */
@@ -274,27 +242,27 @@ struct sstack {
  * Set the global flag "sourcing" so that others will realize
  * that they are no longer reading from a tty (in all probability).
  */
  * Set the global flag "sourcing" so that others will realize
  * that they are no longer reading from a tty (in all probability).
  */
-
-source(name)
-       char name[];
+source(arglist)
+       char **arglist;
 {
 {
-       register FILE *fi;
-       register char *cp;
+       FILE *fi;
+       char *cp;
 
 
-       if ((cp = expand(name)) == NOSTR)
+       if ((cp = expand(*arglist)) == NOSTR)
                return(1);
        if ((fi = fopen(cp, "r")) == NULL) {
                perror(cp);
                return(1);
        }
                return(1);
        if ((fi = fopen(cp, "r")) == NULL) {
                perror(cp);
                return(1);
        }
-       if (ssp >= NOFILE - 2) {
+       if (ssp >= NOFILE - 1) {
                printf("Too much \"sourcing\" going on.\n");
                fclose(fi);
                return(1);
        }
                printf("Too much \"sourcing\" going on.\n");
                fclose(fi);
                return(1);
        }
-       sstack[++ssp].s_file = input;
+       sstack[ssp].s_file = input;
        sstack[ssp].s_cond = cond;
        sstack[ssp].s_loading = loading;
        sstack[ssp].s_cond = cond;
        sstack[ssp].s_loading = loading;
+       ssp++;
        loading = 0;
        cond = CANY;
        input = fi;
        loading = 0;
        cond = CANY;
        input = fi;
@@ -306,10 +274,9 @@ source(name)
  * Pop the current input back to the previous level.
  * Update the "sourcing" flag as appropriate.
  */
  * Pop the current input back to the previous level.
  * Update the "sourcing" flag as appropriate.
  */
-
 unstack()
 {
 unstack()
 {
-       if (ssp < 0) {
+       if (ssp <= 0) {
                printf("\"Source\" stack over-pop.\n");
                sourcing = 0;
                return(1);
                printf("\"Source\" stack over-pop.\n");
                sourcing = 0;
                return(1);
@@ -317,10 +284,11 @@ unstack()
        fclose(input);
        if (cond != CANY)
                printf("Unmatched \"if\"\n");
        fclose(input);
        if (cond != CANY)
                printf("Unmatched \"if\"\n");
+       ssp--;
        cond = sstack[ssp].s_cond;
        loading = sstack[ssp].s_loading;
        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 = loading;
        return(0);
 }
                sourcing = loading;
        return(0);
 }
@@ -329,7 +297,6 @@ unstack()
  * Touch the indicated file.
  * This is nifty for the shell.
  */
  * Touch the indicated file.
  * This is nifty for the shell.
  */
-
 alter(name)
        char name[];
 {
 alter(name)
        char name[];
 {
@@ -348,7 +315,6 @@ alter(name)
  * Examine the passed line buffer and
  * return true if it is all blanks and tabs.
  */
  * Examine the passed line buffer and
  * return true if it is all blanks and tabs.
  */
-
 blankline(linebuf)
        char linebuf[];
 {
 blankline(linebuf)
        char linebuf[];
 {
@@ -513,7 +479,6 @@ done:
  *     1 -- get sender's name for reply
  *     2 -- get sender's name for Reply
  */
  *     1 -- get sender's name for reply
  *     2 -- get sender's name for Reply
  */
-
 char *
 name1(mp, reptype)
        register struct message *mp;
 char *
 name1(mp, reptype)
        register struct message *mp;
@@ -587,7 +552,6 @@ charcount(str, c)
 /*
  * Are any of the characters in the two strings the same?
  */
 /*
  * Are any of the characters in the two strings the same?
  */
-
 anyof(s1, s2)
        register char *s1, *s2;
 {
 anyof(s1, s2)
        register char *s1, *s2;
 {
@@ -601,7 +565,6 @@ anyof(s1, s2)
 /*
  * Convert c to upper case
  */
 /*
  * Convert c to upper case
  */
-
 raise(c)
        register c;
 {
 raise(c)
        register c;
 {
@@ -614,7 +577,6 @@ raise(c)
 /*
  * Copy s1 to s2, return pointer to null in s2.
  */
 /*
  * Copy s1 to s2, return pointer to null in s2.
  */
-
 char *
 copy(s1, s2)
        register char *s1, *s2;
 char *
 copy(s1, s2)
        register char *s1, *s2;
@@ -625,20 +587,6 @@ copy(s1, s2)
        return s2 - 1;
 }
 
        return s2 - 1;
 }
 
-/*
- * Add a single character onto a string.
- */
-
-stradd(str, c)
-       register char *str;
-{
-
-       while (*str++)
-               ;
-       str[-1] = c;
-       *str = 0;
-}
-
 /*
  * See if the given header field is supposed to be ignored.
  */
 /*
  * See if the given header field is supposed to be ignored.
  */
@@ -648,6 +596,8 @@ isign(field, ignore)
 {
        char realfld[BUFSIZ];
 
 {
        char realfld[BUFSIZ];
 
+       if (ignore == ignoreall)
+               return 1;
        /*
         * Lower-case the string, so that "Status" and "status"
         * will hash to the same place.
        /*
         * Lower-case the string, so that "Status" and "status"
         * will hash to the same place.