xref: /csrg-svn/usr.bin/what/what.c (revision 21589)
1*21589Sdist /*
2*21589Sdist  * Copyright (c) 1980, 1988 Regents of the University of California.
3*21589Sdist  * All rights reserved.  The Berkeley software License Agreement
4*21589Sdist  * specifies the terms and conditions for redistribution.
5*21589Sdist  */
6*21589Sdist 
7*21589Sdist #ifndef lint
8*21589Sdist char copyright[] =
9*21589Sdist "@(#) Copyright (c) 1980, 1988 Regents of the University of California.\n\
10*21589Sdist  All rights reserved.\n";
11*21589Sdist #endif not lint
12*21589Sdist 
13*21589Sdist #ifndef lint
14*21589Sdist static char sccsid[] = "@(#)what.c	5.1 (Berkeley) 05/31/85";
15*21589Sdist #endif not lint
16*21589Sdist 
171452Sroot #include <stdio.h>
181452Sroot 
191452Sroot /*
201452Sroot  * what
211452Sroot  */
221452Sroot 
231452Sroot char	*infile = "Standard input";
241452Sroot 
251452Sroot main(argc, argv)
261452Sroot 	int argc;
271452Sroot 	char *argv[];
281452Sroot {
291452Sroot 
301452Sroot 	argc--, argv++;
311452Sroot 	do {
321452Sroot 		if (argc > 0) {
331452Sroot 			if (freopen(argv[0], "r", stdin) == NULL) {
341452Sroot 				perror(argv[0]);
351452Sroot 				exit(1);
361452Sroot 			}
371452Sroot 			infile = argv[0];
381452Sroot 			printf("%s\n", infile);
391452Sroot 			argc--, argv++;
401452Sroot 		}
411452Sroot 		fseek(stdin, (long) 0, 0);
421452Sroot 		find();
431452Sroot 	} while (argc > 0);
444799Sroot 	exit(0);
451452Sroot }
461452Sroot 
471452Sroot find()
481452Sroot {
491452Sroot 	static char buf[BUFSIZ];
501452Sroot 	register char *cp;
511452Sroot 	register int c, cc;
521452Sroot 	register char *pat;
531452Sroot 
541452Sroot contin:
551452Sroot 	while ((c = getchar()) != EOF)
561452Sroot 		if (c == '@') {
571452Sroot 			for (pat = "(#)"; *pat; pat++)
581452Sroot 				if ((c = getchar()) != *pat)
591452Sroot 					goto contin;
601452Sroot 			putchar('\t');
611452Sroot 			while ((c = getchar()) != EOF && c && c != '"' &&
621452Sroot 			    c != '>' && c != '\n')
631452Sroot 				putchar(c);
641452Sroot 			putchar('\n');
651452Sroot 		}
661452Sroot }
67