less -> more
[unix-history] / usr / src / usr.bin / ctags / yacc.c
CommitLineData
3816d2d1
KB
1/*
2 * Copyright (c) 1987 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
2a5dd7cd 8static char sccsid[] = "@(#)yacc.c 5.2 (Berkeley) %G%";
3816d2d1
KB
9#endif not lint
10
11#include <ctags.h>
12#include <strings.h>
13
14/*
15 * y_entries:
16 * find the yacc tags and put them in.
17 */
18y_entries()
19{
20 register int c;
21 register char *sp;
22 register bool in_rule;
23 char tok[MAXTOKEN];
24
3816d2d1
KB
25 while (GETC(!=,EOF))
26 switch ((char)c) {
27 case '\n':
28 SETLINE;
29 /* FALLTHROUGH */
30 case ' ':
31 case '\f':
32 case '\r':
33 case '\t':
34 break;
35 case '{':
36 if (skip_key((int)'}'))
37 in_rule = NO;
38 break;
39 case '\'':
40 case '"':
41 if (skip_key(c))
42 in_rule = NO;
43 break;
44 case '%':
45 if (GETC(==,'%'))
46 return;
47 (void)ungetc(c,inf);
48 break;
49 case '/':
50 if (GETC(==,'*'))
51 skip_comment();
52 else
53 (void)ungetc(c,inf);
54 break;
55 case '|':
56 case ';':
57 in_rule = NO;
58 break;
59 default:
60 if (in_rule || !isalpha(c) && c != (int)'.'
61 && c != (int)'_')
62 break;
63 sp = tok;
64 *sp++ = c;
65 while (GETC(!=,EOF) && (intoken(c) || c == (int)'.'))
66 *sp++ = c;
67 *sp = EOS;
68 getline(); /* may change before ':' */
69 while (iswhite(c)) {
70 if (c == (int)'\n')
71 SETLINE;
72 if (GETC(==,EOF))
73 return;
74 }
75 if (c == (int)':') {
76 pfnote(tok,lineno);
77 in_rule = YES;
78 }
79 else
80 (void)ungetc(c,inf);
81 }
82}
83
84/*
85 * toss_yysec --
86 * throw away lines up to the next "\n%%\n"
87 */
88toss_yysec()
89{
90 register int c, /* read character */
91 state;
92
93 /*
94 * state == 0 : waiting
95 * state == 1 : received a newline
96 * state == 2 : received first %
97 * state == 3 : recieved second %
98 */
99 lineftell = ftell(inf);
100 for (state = 0;GETC(!=,EOF);)
101 switch ((char)c) {
102 case '\n':
103 ++lineno;
104 lineftell = ftell(inf);
105 if (state == 3) /* done! */
106 return;
107 state = 1; /* start over */
108 break;
109 case '%':
110 if (state) /* if 1 or 2 */
111 ++state; /* goto 3 */
112 break;
113 default:
114 state = 0; /* reset */
115 }
116}