1: #ifndef lint
   2: static char *sccsid = "@(#)from.c	4.1 (Berkeley) 10/1/80";
   3: #endif
   4: #include <stdio.h>
   5: #include <ctype.h>
   6: #include <pwd.h>
   7: 
   8: struct  passwd *getpwuid();
   9: 
  10: main(argc, argv)
  11: int argc;
  12: register char **argv;
  13: {
  14:     char lbuf[BUFSIZ];
  15:     char lbuf2[BUFSIZ];
  16:     register struct passwd *pp;
  17:     int stashed = 0;
  18:     register char *name;
  19:     char *sender;
  20: 
  21:     if (argc > 1 && *(argv[1]) == '-' && (*++argv)[1] == 's') {
  22:         if (--argc <= 1) {
  23:             fprintf (stderr, "Usage: from [-s sender] [user]\n");
  24:             exit (1);
  25:         }
  26:         --argc;
  27:         sender = *++argv;
  28:         for (name = sender; *name; name++)
  29:             if (isupper(*name))
  30:                 *name = tolower(*name);
  31: 
  32:     }
  33:     else
  34:         sender = NULL;
  35:     if (chdir("/usr/spool/mail") < 0)
  36:         exit(1);
  37:     if (argc > 1)
  38:         name = argv[1];
  39:     else {
  40:         if (name == NULL || strlen(name) == 0) {
  41:             pp = getpwuid(getuid());
  42:             if (pp == NULL) {
  43:                 fprintf(stderr, "Who are you?\n");
  44:                 exit(1);
  45:             }
  46:             name = pp->pw_name;
  47:         }
  48:     }
  49:     if (freopen(name, "r", stdin) == NULL)
  50:         exit(0);
  51:     while(fgets(lbuf, sizeof lbuf, stdin) != NULL)
  52:         if (lbuf[0] == '\n' && stashed) {
  53:             stashed = 0;
  54:             printf("%s", lbuf2);
  55:         }
  56:         else if (bufcmp(lbuf, "From ", 5) &&
  57:             (sender == NULL || match(&lbuf[4], sender))) {
  58:             strcpy(lbuf2, lbuf);
  59:             stashed = 1;
  60:         }
  61:     if (stashed)
  62:         printf("%s", lbuf2);
  63:     exit(0);
  64: }
  65: 
  66: bufcmp (b1, b2, n)
  67: register char *b1, *b2;
  68: register int n;
  69: {
  70:     while (n-- > 0)
  71:         if (*b1++ != *b2++)
  72:             return (0);
  73:     return (1);
  74: }
  75: 
  76: match (line, str)
  77: register char *line, *str;
  78: {
  79:     register char ch;
  80: 
  81:     while (*line == ' ' || *line == '\t')
  82:         ++line;
  83:     if (*line == '\n')
  84:         return (0);
  85:     while (*str && *line != ' ' && *line != '\t' && *line != '\n') {
  86:         ch = isupper(*line) ? tolower(*line) : *line;
  87:         if (ch != *str++)
  88:             return (0);
  89:         line++;
  90:     }
  91:     return (*str == '\0');
  92: }

Defined functions

bufcmp defined in line 66; used 1 times
  • in line 56
main defined in line 10; never used
match defined in line 76; used 1 times
  • in line 57

Defined variables

sccsid defined in line 2; never used
Last modified: 1983-06-29
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 715
Valid CSS Valid XHTML 1.0 Strict