xref: /original-bsd/usr.bin/ctags/yacc.c (revision ee1b0b6c)
1 /*
2  * Copyright (c) 1987 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)yacc.c	5.4 (Berkeley) 05/15/90";
20 #endif /* not lint */
21 
22 #include <ctags.h>
23 #include <string.h>
24 
25 /*
26  * y_entries:
27  *	find the yacc tags and put them in.
28  */
29 y_entries()
30 {
31 	register int	c;
32 	register char	*sp;
33 	register bool	in_rule;
34 	char	tok[MAXTOKEN];
35 
36 	while (GETC(!=,EOF))
37 		switch ((char)c) {
38 		case '\n':
39 			SETLINE;
40 			/* FALLTHROUGH */
41 		case ' ':
42 		case '\f':
43 		case '\r':
44 		case '\t':
45 			break;
46 		case '{':
47 			if (skip_key((int)'}'))
48 				in_rule = NO;
49 			break;
50 		case '\'':
51 		case '"':
52 			if (skip_key(c))
53 				in_rule = NO;
54 			break;
55 		case '%':
56 			if (GETC(==,'%'))
57 				return;
58 			(void)ungetc(c,inf);
59 			break;
60 		case '/':
61 			if (GETC(==,'*'))
62 				skip_comment();
63 			else
64 				(void)ungetc(c,inf);
65 			break;
66 		case '|':
67 		case ';':
68 			in_rule = NO;
69 			break;
70 		default:
71 			if (in_rule || !isalpha(c) && c != (int)'.'
72 			    && c != (int)'_')
73 				break;
74 			sp = tok;
75 			*sp++ = c;
76 			while (GETC(!=,EOF) && (intoken(c) || c == (int)'.'))
77 				*sp++ = c;
78 			*sp = EOS;
79 			getline();		/* may change before ':' */
80 			while (iswhite(c)) {
81 				if (c == (int)'\n')
82 					SETLINE;
83 				if (GETC(==,EOF))
84 					return;
85 			}
86 			if (c == (int)':') {
87 				pfnote(tok,lineno);
88 				in_rule = YES;
89 			}
90 			else
91 				(void)ungetc(c,inf);
92 		}
93 }
94 
95 /*
96  * toss_yysec --
97  *	throw away lines up to the next "\n%%\n"
98  */
99 toss_yysec()
100 {
101 	register int	c,			/* read character */
102 			state;
103 
104 	/*
105 	 * state == 0 : waiting
106 	 * state == 1 : received a newline
107 	 * state == 2 : received first %
108 	 * state == 3 : recieved second %
109 	 */
110 	lineftell = ftell(inf);
111 	for (state = 0;GETC(!=,EOF);)
112 		switch ((char)c) {
113 			case '\n':
114 				++lineno;
115 				lineftell = ftell(inf);
116 				if (state == 3)		/* done! */
117 					return;
118 				state = 1;		/* start over */
119 				break;
120 			case '%':
121 				if (state)		/* if 1 or 2 */
122 					++state;	/* goto 3 */
123 				break;
124 			default:
125 				state = 0;		/* reset */
126 		}
127 }
128