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

Defined functions

main defined in line 23; never used
match defined in line 81; used 1 times
  • in line 72

Defined variables

copyright defined in line 8; never used
sccsid defined in line 14; never used
Last modified: 1985-11-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1221
Valid CSS Valid XHTML 1.0 Strict