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