|
|
1.1 root 1: /*
2: * Copyright (c) 1980, 1988 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted provided
6: * that: (1) source distributions retain this entire copyright notice and
7: * comment, and (2) distributions including binaries display the following
8: * acknowledgement: ``This product includes software developed by the
9: * University of California, Berkeley and its contributors'' in the
10: * documentation or other materials provided with the distribution and in
11: * all advertising materials mentioning features or use of this software.
12: * Neither the name of the University nor the names of its contributors may
13: * be used to endorse or promote products derived from this software without
14: * specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: char copyright[] =
22: "@(#) Copyright (c) 1980, 1988 The Regents of the University of California.\n\
23: All rights reserved.\n";
24: #endif /* not lint */
25:
26: #ifndef lint
27: static char sccsid[] = "@(#)from.c 5.6 (Berkeley) 7/21/90";
28: #endif /* not lint */
29:
30: #include <sys/types.h>
31: #include <ctype.h>
32: #include <pwd.h>
33: #include <stdio.h>
34: #include <paths.h>
35:
36: main(argc, argv)
37: int argc;
38: char **argv;
39: {
40: extern char *optarg;
41: extern int optind;
42: struct passwd *pwd, *getpwuid();
43: int ch, newline;
44: char *file, *sender, *p;
45: #if MAXPATHLEN > BUFSIZ
46: char buf[MAXPATHLEN];
47: #else
48: char buf[BUFSIZ];
49: #endif
50:
51: file = sender = NULL;
52: while ((ch = getopt(argc, argv, "f:s:")) != EOF)
53: switch((char)ch) {
54: case 'f':
55: file = optarg;
56: break;
57: case 's':
58: sender = optarg;
59: for (p = sender; *p; ++p)
60: if (isupper(*p))
61: *p = tolower(*p);
62: break;
63: case '?':
64: default:
65: fprintf(stderr, "usage: from [-f file] [-s sender] [user]\n");
66: exit(1);
67: }
68: argv += optind;
69:
70: if (!file) {
71: if (!(file = *argv)) {
72: if (!(pwd = getpwuid(getuid()))) {
73: fprintf(stderr,
74: "from: no password file entry for you.\n");
75: exit(1);
76: }
77: file = pwd->pw_name;
78: }
79: (void)sprintf(buf, "%s/%s", _PATH_MAILDIR, file);
80: file = buf;
81: }
82: if (!freopen(file, "r", stdin)) {
83: fprintf(stderr, "from: can't read %s.\n", file);
84: exit(1);
85: }
86: for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
87: if (*buf == '\n') {
88: newline = 1;
89: continue;
90: }
91: if (newline && !strncmp(buf, "From ", 5) &&
92: (!sender || match(buf + 5, sender)))
93: printf("%s", buf);
94: newline = 0;
95: }
96: exit(0);
97: }
98:
99: match(line, sender)
100: register char *line, *sender;
101: {
102: register char ch, pch, first, *p, *t;
103:
104: for (first = *sender++;;) {
105: if (isspace(ch = *line))
106: return(0);
107: ++line;
108: if (isupper(ch))
109: ch = tolower(ch);
110: if (ch != first)
111: continue;
112: for (p = sender, t = line;;) {
113: if (!(pch = *p++))
114: return(1);
115: if (isupper(ch = *t++))
116: ch = tolower(ch);
117: if (ch != pch)
118: break;
119: }
120: }
121: /* NOTREACHED */
122: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.