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