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