xref: /csrg-svn/usr.bin/what/what.c (revision 62439)
121589Sdist /*
2*62439Sbostic  * Copyright (c) 1980, 1988, 1993
3*62439Sbostic  *	The Regents of the University of California.  All rights reserved.
435223Sbostic  *
542786Sbostic  * %sccs.include.redist.c%
621589Sdist  */
721589Sdist 
821589Sdist #ifndef lint
9*62439Sbostic static char copyright[] =
10*62439Sbostic "@(#) Copyright (c) 1980, 1988, 1993\n\
11*62439Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1235223Sbostic #endif /* not lint */
1321589Sdist 
1421589Sdist #ifndef lint
15*62439Sbostic static char sccsid[] = "@(#)what.c	8.1 (Berkeley) 06/06/93";
1635223Sbostic #endif /* not lint */
1721589Sdist 
181452Sroot #include <stdio.h>
191452Sroot 
201452Sroot /*
211452Sroot  * what
221452Sroot  */
2335223Sbostic /* ARGSUSED */
main(argc,argv)241452Sroot main(argc, argv)
251452Sroot 	int argc;
2635223Sbostic 	char **argv;
271452Sroot {
2835223Sbostic 	if (!*++argv)
2935223Sbostic 		search();
3035223Sbostic 	else do {
3135223Sbostic 		if (!freopen(*argv, "r", stdin)) {
3235223Sbostic 			perror(*argv);
3335223Sbostic 			exit(1);
341452Sroot 		}
3535223Sbostic 		printf("%s\n", *argv);
3635223Sbostic 		search();
3735223Sbostic 	} while(*++argv);
384799Sroot 	exit(0);
391452Sroot }
401452Sroot 
search()4135223Sbostic search()
421452Sroot {
4335223Sbostic 	register int c;
441452Sroot 
4535223Sbostic 	while ((c = getchar()) != EOF) {
4635350Sbostic loop:		if (c != '@')
4735223Sbostic 			continue;
4835223Sbostic 		if ((c = getchar()) != '(')
4935350Sbostic 			goto loop;
5035223Sbostic 		if ((c = getchar()) != '#')
5135350Sbostic 			goto loop;
5235223Sbostic 		if ((c = getchar()) != ')')
5335350Sbostic 			goto loop;
5435223Sbostic 		putchar('\t');
5535223Sbostic 		while ((c = getchar()) != EOF && c && c != '"' &&
5635223Sbostic 		    c != '>' && c != '\n')
5735223Sbostic 			putchar(c);
5835223Sbostic 		putchar('\n');
5935223Sbostic 	}
601452Sroot }
61