yacc.c revision 87628
11590Srgrimes/* 21590Srgrimes * Copyright (c) 1987, 1993, 1994 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 3. All advertising materials mentioning features or use of this software 141590Srgrimes * must display the following acknowledgement: 151590Srgrimes * This product includes software developed by the University of 161590Srgrimes * California, Berkeley and its contributors. 171590Srgrimes * 4. Neither the name of the University nor the names of its contributors 181590Srgrimes * may be used to endorse or promote products derived from this software 191590Srgrimes * without specific prior written permission. 201590Srgrimes * 211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311590Srgrimes * SUCH DAMAGE. 321590Srgrimes */ 331590Srgrimes 3487628Sdwmalone#if 0 3587628Sdwmalone#ifndef lint 3687628Sdwmalonestatic char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 4/2/94"; 3787628Sdwmalone#endif 3887628Sdwmalone#endif 3987628Sdwmalone 4087249Smarkm#include <sys/cdefs.h> 4187249Smarkm__FBSDID("$FreeBSD: head/usr.bin/ctags/yacc.c 87628 2001-12-10 21:13:08Z dwmalone $"); 4287249Smarkm 431590Srgrimes#include <ctype.h> 441590Srgrimes#include <limits.h> 451590Srgrimes#include <stdio.h> 461590Srgrimes#include <string.h> 471590Srgrimes 481590Srgrimes#include "ctags.h" 491590Srgrimes 501590Srgrimes/* 511590Srgrimes * y_entries: 521590Srgrimes * find the yacc tags and put them in. 531590Srgrimes */ 541590Srgrimesvoid 551590Srgrimesy_entries() 561590Srgrimes{ 571590Srgrimes int c; 581590Srgrimes char *sp; 591590Srgrimes bool in_rule; 601590Srgrimes char tok[MAXTOKEN]; 611590Srgrimes 621590Srgrimes in_rule = NO; 631590Srgrimes 641590Srgrimes while (GETC(!=, EOF)) 651590Srgrimes switch (c) { 661590Srgrimes case '\n': 671590Srgrimes SETLINE; 681590Srgrimes /* FALLTHROUGH */ 691590Srgrimes case ' ': 701590Srgrimes case '\f': 711590Srgrimes case '\r': 721590Srgrimes case '\t': 731590Srgrimes break; 741590Srgrimes case '{': 751590Srgrimes if (skip_key('}')) 761590Srgrimes in_rule = NO; 771590Srgrimes break; 781590Srgrimes case '\'': 791590Srgrimes case '"': 801590Srgrimes if (skip_key(c)) 811590Srgrimes in_rule = NO; 821590Srgrimes break; 831590Srgrimes case '%': 841590Srgrimes if (GETC(==, '%')) 851590Srgrimes return; 861590Srgrimes (void)ungetc(c, inf); 871590Srgrimes break; 881590Srgrimes case '/': 891590Srgrimes if (GETC(==, '*')) 901590Srgrimes skip_comment(); 911590Srgrimes else 921590Srgrimes (void)ungetc(c, inf); 931590Srgrimes break; 941590Srgrimes case '|': 951590Srgrimes case ';': 961590Srgrimes in_rule = NO; 971590Srgrimes break; 981590Srgrimes default: 9932069Salex if (in_rule || (!isalpha(c) && c != '.' && c != '_')) 1001590Srgrimes break; 1011590Srgrimes sp = tok; 1021590Srgrimes *sp++ = c; 1031590Srgrimes while (GETC(!=, EOF) && (intoken(c) || c == '.')) 1041590Srgrimes *sp++ = c; 1051590Srgrimes *sp = EOS; 1061590Srgrimes getline(); /* may change before ':' */ 1071590Srgrimes while (iswhite(c)) { 1081590Srgrimes if (c == '\n') 1091590Srgrimes SETLINE; 1101590Srgrimes if (GETC(==, EOF)) 1111590Srgrimes return; 1121590Srgrimes } 1131590Srgrimes if (c == ':') { 1141590Srgrimes pfnote(tok, lineno); 1151590Srgrimes in_rule = YES; 1161590Srgrimes } 1171590Srgrimes else 1181590Srgrimes (void)ungetc(c, inf); 1191590Srgrimes } 1201590Srgrimes} 1211590Srgrimes 1221590Srgrimes/* 1231590Srgrimes * toss_yysec -- 1241590Srgrimes * throw away lines up to the next "\n%%\n" 1251590Srgrimes */ 1261590Srgrimesvoid 1271590Srgrimestoss_yysec() 1281590Srgrimes{ 1291590Srgrimes int c; /* read character */ 1301590Srgrimes int state; 1311590Srgrimes 1321590Srgrimes /* 1331590Srgrimes * state == 0 : waiting 1341590Srgrimes * state == 1 : received a newline 1351590Srgrimes * state == 2 : received first % 1361590Srgrimes * state == 3 : recieved second % 1371590Srgrimes */ 1381590Srgrimes lineftell = ftell(inf); 1391590Srgrimes for (state = 0; GETC(!=, EOF);) 1401590Srgrimes switch (c) { 1411590Srgrimes case '\n': 1421590Srgrimes ++lineno; 1431590Srgrimes lineftell = ftell(inf); 1441590Srgrimes if (state == 3) /* done! */ 1451590Srgrimes return; 1461590Srgrimes state = 1; /* start over */ 1471590Srgrimes break; 1481590Srgrimes case '%': 1491590Srgrimes if (state) /* if 1 or 2 */ 1501590Srgrimes ++state; /* goto 3 */ 1511590Srgrimes break; 1521590Srgrimes default: 1531590Srgrimes state = 0; /* reset */ 1541590Srgrimes break; 1551590Srgrimes } 1561590Srgrimes} 157