Annotation of src/usr.bin/ctags/yacc.c, Revision 1.7
1.7 ! deraadt 1: /* $OpenBSD: yacc.c,v 1.6 2003/06/03 02:56:07 millert Exp $ */
1.1 deraadt 2: /* $NetBSD: yacc.c,v 1.3 1995/03/26 20:14:12 glass Exp $ */
3:
4: /*
5: * Copyright (c) 1987, 1993, 1994
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
1.6 millert 16: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: */
32:
33: #ifndef lint
34: #if 0
35: static char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 4/2/94";
36: #else
1.7 ! deraadt 37: static char rcsid[] = "$OpenBSD: yacc.c,v 1.6 2003/06/03 02:56:07 millert Exp $";
1.1 deraadt 38: #endif
39: #endif /* not lint */
40:
41: #include <ctype.h>
42: #include <limits.h>
43: #include <stdio.h>
44: #include <string.h>
45:
46: #include "ctags.h"
47:
48: /*
49: * y_entries:
50: * find the yacc tags and put them in.
51: */
52: void
1.7 ! deraadt 53: y_entries(void)
1.1 deraadt 54: {
55: int c;
56: char *sp;
57: bool in_rule;
58: char tok[MAXTOKEN];
59:
60: in_rule = NO;
61:
62: while (GETC(!=, EOF))
63: switch (c) {
64: case '\n':
65: SETLINE;
66: /* FALLTHROUGH */
67: case ' ':
68: case '\f':
69: case '\r':
70: case '\t':
71: break;
72: case '{':
73: if (skip_key('}'))
74: in_rule = NO;
75: break;
76: case '\'':
77: case '"':
78: if (skip_key(c))
79: in_rule = NO;
80: break;
81: case '%':
82: if (GETC(==, '%'))
83: return;
84: (void)ungetc(c, inf);
85: break;
86: case '/':
87: if (GETC(==, '*'))
1.5 pjanzen 88: skip_comment('*');
1.1 deraadt 89: else
90: (void)ungetc(c, inf);
91: break;
92: case '|':
93: case ';':
94: in_rule = NO;
95: break;
96: default:
1.3 deraadt 97: if (in_rule || (!isalpha(c) && c != '.' && c != '_'))
1.1 deraadt 98: break;
99: sp = tok;
100: *sp++ = c;
101: while (GETC(!=, EOF) && (intoken(c) || c == '.'))
102: *sp++ = c;
103: *sp = EOS;
104: getline(); /* may change before ':' */
105: while (iswhite(c)) {
106: if (c == '\n')
107: SETLINE;
108: if (GETC(==, EOF))
109: return;
110: }
111: if (c == ':') {
112: pfnote(tok, lineno);
113: in_rule = YES;
114: }
115: else
116: (void)ungetc(c, inf);
117: }
118: }
119:
120: /*
121: * toss_yysec --
122: * throw away lines up to the next "\n%%\n"
123: */
124: void
1.7 ! deraadt 125: toss_yysec(void)
1.1 deraadt 126: {
127: int c; /* read character */
128: int state;
129:
130: /*
131: * state == 0 : waiting
132: * state == 1 : received a newline
133: * state == 2 : received first %
1.4 aaron 134: * state == 3 : received second %
1.1 deraadt 135: */
136: lineftell = ftell(inf);
137: for (state = 0; GETC(!=, EOF);)
138: switch (c) {
139: case '\n':
140: ++lineno;
141: lineftell = ftell(inf);
142: if (state == 3) /* done! */
143: return;
144: state = 1; /* start over */
145: break;
146: case '%':
147: if (state) /* if 1 or 2 */
148: ++state; /* goto 3 */
149: break;
150: default:
151: state = 0; /* reset */
152: break;
153: }
154: }