rationalized handling of child processes, cleaned up mail1 some more
[unix-history] / usr / src / usr.bin / from / from.c
index d2552b5..d5eb49d 100644 (file)
@@ -1,4 +1,19 @@
-static char *sccsid = "@(#)from.c      4.1 (Berkeley) %G%";
+/*
+ * 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
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)from.c     5.2 (Berkeley) %G%";
+#endif not lint
+
 #include <stdio.h>
 #include <ctype.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <pwd.h>
@@ -6,8 +21,8 @@ static char *sccsid = "@(#)from.c      4.1 (Berkeley) %G%";
 struct passwd *getpwuid();
 
 main(argc, argv)
 struct passwd *getpwuid();
 
 main(argc, argv)
-int argc;
-register char **argv;
+       int argc;
+       register char **argv;
 {
        char lbuf[BUFSIZ];
        char lbuf2[BUFSIZ];
 {
        char lbuf[BUFSIZ];
        char lbuf2[BUFSIZ];
@@ -28,8 +43,7 @@ register char **argv;
                        if (isupper(*name))
                                *name = tolower(*name);
 
                        if (isupper(*name))
                                *name = tolower(*name);
 
-       }
-       else
+       } else
                sender = NULL;
        if (chdir("/usr/spool/mail") < 0)
                exit(1);
                sender = NULL;
        if (chdir("/usr/spool/mail") < 0)
                exit(1);
@@ -46,14 +60,15 @@ register char **argv;
                        name = pp->pw_name;
                }
        }
                        name = pp->pw_name;
                }
        }
-       if (freopen(name, "r", stdin) == NULL)
+       if (freopen(name, "r", stdin) == NULL) {
+               fprintf(stderr, "Can't open /usr/spool/mail/%s\n", name);
                exit(0);
                exit(0);
-       while(fgets(lbuf, sizeof lbuf, stdin) != NULL)
+       }
+       while (fgets(lbuf, sizeof lbuf, stdin) != NULL)
                if (lbuf[0] == '\n' && stashed) {
                        stashed = 0;
                        printf("%s", lbuf2);
                if (lbuf[0] == '\n' && stashed) {
                        stashed = 0;
                        printf("%s", lbuf2);
-               }
-               else if (bufcmp(lbuf, "From ", 5) &&
+               } else if (strncmp(lbuf, "From ", 5) == 0 &&
                    (sender == NULL || match(&lbuf[4], sender))) {
                        strcpy(lbuf2, lbuf);
                        stashed = 1;
                    (sender == NULL || match(&lbuf[4], sender))) {
                        strcpy(lbuf2, lbuf);
                        stashed = 1;
@@ -63,18 +78,8 @@ register char **argv;
        exit(0);
 }
 
        exit(0);
 }
 
-bufcmp (b1, b2, n)
-register char *b1, *b2;
-register int n;
-{
-       while (n-- > 0)
-               if (*b1++ != *b2++)
-                       return (0);
-       return (1);
-}
-
 match (line, str)
 match (line, str)
-register char *line, *str;
+       register char *line, *str;
 {
        register char ch;
 
 {
        register char ch;