yacc.c revision 1591
1/* 2 * Copyright (c) 1987, 1993, 1994 3 * The Regents of the University of California. 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 8.3 (Berkeley) 4/2/94"; 36#endif /* not lint */ 37 38#include <ctype.h> 39#include <limits.h> 40#include <stdio.h> 41#include <string.h> 42 43#include "ctags.h" 44 45/* 46 * y_entries: 47 * find the yacc tags and put them in. 48 */ 49void 50y_entries() 51{ 52 int c; 53 char *sp; 54 bool in_rule; 55 char tok[MAXTOKEN]; 56 57 in_rule = NO; 58 59 while (GETC(!=, EOF)) 60 switch (c) { 61 case '\n': 62 SETLINE; 63 /* FALLTHROUGH */ 64 case ' ': 65 case '\f': 66 case '\r': 67 case '\t': 68 break; 69 case '{': 70 if (skip_key('}')) 71 in_rule = NO; 72 break; 73 case '\'': 74 case '"': 75 if (skip_key(c)) 76 in_rule = NO; 77 break; 78 case '%': 79 if (GETC(==, '%')) 80 return; 81 (void)ungetc(c, inf); 82 break; 83 case '/': 84 if (GETC(==, '*')) 85 skip_comment(); 86 else 87 (void)ungetc(c, inf); 88 break; 89 case '|': 90 case ';': 91 in_rule = NO; 92 break; 93 default: 94 if (in_rule || !isalpha(c) && c != '.' && c != '_') 95 break; 96 sp = tok; 97 *sp++ = c; 98 while (GETC(!=, EOF) && (intoken(c) || c == '.')) 99 *sp++ = c; 100 *sp = EOS; 101 getline(); /* may change before ':' */ 102 while (iswhite(c)) { 103 if (c == '\n') 104 SETLINE; 105 if (GETC(==, EOF)) 106 return; 107 } 108 if (c == ':') { 109 pfnote(tok, lineno); 110 in_rule = YES; 111 } 112 else 113 (void)ungetc(c, inf); 114 } 115} 116 117/* 118 * toss_yysec -- 119 * throw away lines up to the next "\n%%\n" 120 */ 121void 122toss_yysec() 123{ 124 int c; /* read character */ 125 int state; 126 127 /* 128 * state == 0 : waiting 129 * state == 1 : received a newline 130 * state == 2 : received first % 131 * state == 3 : recieved second % 132 */ 133 lineftell = ftell(inf); 134 for (state = 0; GETC(!=, EOF);) 135 switch (c) { 136 case '\n': 137 ++lineno; 138 lineftell = ftell(inf); 139 if (state == 3) /* done! */ 140 return; 141 state = 1; /* start over */ 142 break; 143 case '%': 144 if (state) /* if 1 or 2 */ 145 ++state; /* goto 3 */ 146 break; 147 default: 148 state = 0; /* reset */ 149 break; 150 } 151} 152