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