add "tell" command
[unix-history] / usr / src / usr.bin / what / what.c
CommitLineData
a479dbc0
BJ
1static char *sccsid = "@(#)what.c 4.1 (Berkeley) %G%";
2#include <stdio.h>
3
4/*
5 * what
6 */
7
8char *infile = "Standard input";
9
10main(argc, argv)
11 int argc;
12 char *argv[];
13{
14
15 argc--, argv++;
16 do {
17 if (argc > 0) {
18 if (freopen(argv[0], "r", stdin) == NULL) {
19 perror(argv[0]);
20 exit(1);
21 }
22 infile = argv[0];
23 printf("%s\n", infile);
24 argc--, argv++;
25 }
26 fseek(stdin, (long) 0, 0);
27 find();
28 } while (argc > 0);
29}
30
31find()
32{
33 static char buf[BUFSIZ];
34 register char *cp;
35 register int c, cc;
36 register char *pat;
37
38contin:
39 while ((c = getchar()) != EOF)
40 if (c == '@') {
41 for (pat = "(#)"; *pat; pat++)
42 if ((c = getchar()) != *pat)
43 goto contin;
44 putchar('\t');
45 while ((c = getchar()) != EOF && c && c != '"' &&
46 c != '>' && c != '\n')
47 putchar(c);
48 putchar('\n');
49 }
50}