BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / mail / names.c
index fd1a386..a9f3dbb 100644 (file)
@@ -2,21 +2,23 @@
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * 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.
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * 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
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)names.c    5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)names.c    5.16 (Berkeley) 6/25/90";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -176,7 +178,7 @@ yankword(ap, wbuf)
                for (cp2 = wbuf; *cp && (*cp2++ = *cp++) != '>';)
                        ;
        else
                for (cp2 = wbuf; *cp && (*cp2++ = *cp++) != '>';)
                        ;
        else
-               for (cp2 = wbuf; *cp && !any(*cp, " \t,("); *cp2++ = *cp++)
+               for (cp2 = wbuf; *cp && !index(" \t,(", *cp); *cp2++ = *cp++)
                        ;
        *cp2 = '\0';
        return cp;
                        ;
        *cp2 = '\0';
        return cp;
@@ -225,7 +227,7 @@ outof(names, fo, hp)
                 */
 
                if (image < 0) {
                 */
 
                if (image < 0) {
-                       if ((fout = fopen(tempEdit, "a")) == NULL) {
+                       if ((fout = Fopen(tempEdit, "a")) == NULL) {
                                perror(tempEdit);
                                senderr++;
                                goto cant;
                                perror(tempEdit);
                                senderr++;
                                goto cant;
@@ -235,20 +237,19 @@ outof(names, fo, hp)
                        if (image < 0) {
                                perror(tempEdit);
                                senderr++;
                        if (image < 0) {
                                perror(tempEdit);
                                senderr++;
+                               (void) Fclose(fout);
                                goto cant;
                        }
                                goto cant;
                        }
-                       else {
-                               fprintf(fout, "From %s %s", myname, date);
-                               puthead(hp, fout, GTO|GSUBJECT|GCC|GNL);
-                               while ((c = getc(fo)) != EOF)
-                                       (void) putc(c, fout);
-                               rewind(fo);
-                               (void) putc('\n', fout);
-                               (void) fflush(fout);
-                               if (ferror(fout))
-                                       perror(tempEdit);
-                               (void) fclose(fout);
-                       }
+                       fprintf(fout, "From %s %s", myname, date);
+                       puthead(hp, fout, GTO|GSUBJECT|GCC|GNL);
+                       while ((c = getc(fo)) != EOF)
+                               (void) putc(c, fout);
+                       rewind(fo);
+                       (void) putc('\n', fout);
+                       (void) fflush(fout);
+                       if (ferror(fout))
+                               perror(tempEdit);
+                       (void) Fclose(fout);
                }
 
                /*
                }
 
                /*
@@ -261,9 +262,15 @@ outof(names, fo, hp)
                        int pid;
                        char *shell;
 
                        int pid;
                        char *shell;
 
-                       /* XXX, can't really reuse the same image file */
+                       /*
+                        * XXX
+                        * We can't really reuse the same image file,
+                        * because multiple piped recipients will
+                        * share the same lseek location and trample
+                        * on one another.
+                        */
                        if ((shell = value("SHELL")) == NOSTR)
                        if ((shell = value("SHELL")) == NOSTR)
-                               shell = SHELL;
+                               shell = _PATH_CSHELL;
                        pid = start_command(shell, sigmask(SIGHUP)|
                                        sigmask(SIGINT)|sigmask(SIGQUIT),
                                image, -1, "-c", fname, NOSTR);
                        pid = start_command(shell, sigmask(SIGHUP)|
                                        sigmask(SIGINT)|sigmask(SIGQUIT),
                                image, -1, "-c", fname, NOSTR);
@@ -273,15 +280,20 @@ outof(names, fo, hp)
                        }
                        free_child(pid);
                } else {
                        }
                        free_child(pid);
                } else {
-                       if ((fout = fopen(fname, "a")) == NULL) {
+                       int f;
+                       if ((fout = Fopen(fname, "a")) == NULL) {
                                perror(fname);
                                senderr++;
                                goto cant;
                        }
                                perror(fname);
                                senderr++;
                                goto cant;
                        }
-                       fin = Fdopen(image, "r");
+                       if ((f = dup(image)) < 0) {
+                               perror("dup");
+                               fin = NULL;
+                       } else
+                               fin = Fdopen(f, "r");
                        if (fin == NULL) {
                                fprintf(stderr, "Can't reopen image\n");
                        if (fin == NULL) {
                                fprintf(stderr, "Can't reopen image\n");
-                               (void) fclose(fout);
+                               (void) Fclose(fout);
                                senderr++;
                                goto cant;
                        }
                                senderr++;
                                goto cant;
                        }
@@ -290,8 +302,8 @@ outof(names, fo, hp)
                                (void) putc(c, fout);
                        if (ferror(fout))
                                senderr++, perror(fname);
                                (void) putc(c, fout);
                        if (ferror(fout))
                                senderr++, perror(fname);
-                       (void) fclose(fout);
-                       (void) fclose(fin);
+                       (void) Fclose(fout);
+                       (void) Fclose(fin);
                }
 cant:
                /*
                }
 cant:
                /*
@@ -500,7 +512,7 @@ elide(names)
        new->n_flink = NIL;
        while (np != NIL) {
                t = new;
        new->n_flink = NIL;
        while (np != NIL) {
                t = new;
-               while (nstrcmp(t->n_name, np->n_name) < 0) {
+               while (strcasecmp(t->n_name, np->n_name) < 0) {
                        if (t->n_flink == NIL)
                                break;
                        t = t->n_flink;
                        if (t->n_flink == NIL)
                                break;
                        t = t->n_flink;
@@ -511,7 +523,7 @@ elide(names)
                 * the current value of t.
                 */
 
                 * the current value of t.
                 */
 
-               if (nstrcmp(t->n_name, np->n_name) < 0) {
+               if (strcasecmp(t->n_name, np->n_name) < 0) {
                        t->n_flink = np;
                        np->n_blink = t;
                        t = np;
                        t->n_flink = np;
                        np->n_blink = t;
                        t = np;
@@ -557,8 +569,8 @@ elide(names)
        np = new;
        while (np != NIL) {
                t = np;
        np = new;
        while (np != NIL) {
                t = np;
-               while (t->n_flink!=NIL &&
-                   icequal(np->n_name,t->n_flink->n_name))
+               while (t->n_flink != NIL &&
+                      strcasecmp(np->n_name, t->n_flink->n_name) == 0)
                        t = t->n_flink;
                if (t == np || t == NIL) {
                        np = np->n_flink;
                        t = t->n_flink;
                if (t == np || t == NIL) {
                        np = np->n_flink;
@@ -578,21 +590,6 @@ elide(names)
        return(new);
 }
 
        return(new);
 }
 
-/*
- * Version of strcmp which ignores case differences.
- */
-nstrcmp(s1, s2)
-       register char *s1, *s2;
-{
-       register int c1, c2;
-
-       do {
-               c1 = *s1++;
-               c2 = *s2++;
-       } while (c1 && c1 == c2);
-       return(c1 - c2);
-}
-
 /*
  * Put another node onto a list of names and return
  * the list.
 /*
  * Put another node onto a list of names and return
  * the list.
@@ -624,19 +621,17 @@ count(np)
 }
 
 /*
 }
 
 /*
- * Delete the given name from a namelist, using the passed
- * function to compare the names.
+ * Delete the given name from a namelist.
  */
 struct name *
  */
 struct name *
-delname(np, name, cmpfun)
+delname(np, name)
        register struct name *np;
        char name[];
        register struct name *np;
        char name[];
-       int (* cmpfun)();
 {
        register struct name *p;
 
        for (p = np; p != NIL; p = p->n_flink)
 {
        register struct name *p;
 
        for (p = np; p != NIL; p = p->n_flink)
-               if ((* cmpfun)(p->n_name, name)) {
+               if (strcasecmp(p->n_name, name) == 0) {
                        if (p->n_blink == NIL) {
                                if (p->n_flink != NIL)
                                        p->n_flink->n_blink = NIL;
                        if (p->n_blink == NIL) {
                                if (p->n_flink != NIL)
                                        p->n_flink->n_blink = NIL;
@@ -651,7 +646,7 @@ delname(np, name, cmpfun)
                        p->n_blink->n_flink = p->n_flink;
                        p->n_flink->n_blink = p->n_blink;
                }
                        p->n_blink->n_flink = p->n_flink;
                        p->n_flink->n_blink = p->n_blink;
                }
-       return(np);
+       return np;
 }
 
 /*
 }
 
 /*