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 * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes */ 291590Srgrimes 3087628Sdwmalone#if 0 3187628Sdwmalone#ifndef lint 3287628Sdwmalonestatic char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 4/2/94"; 3387628Sdwmalone#endif 3487628Sdwmalone#endif 3587628Sdwmalone 3687249Smarkm#include <sys/cdefs.h> 3787249Smarkm__FBSDID("$FreeBSD: releng/10.2/usr.bin/ctags/yacc.c 216370 2010-12-11 08:32:16Z joel $"); 3887249Smarkm 391590Srgrimes#include <ctype.h> 401590Srgrimes#include <limits.h> 411590Srgrimes#include <stdio.h> 421590Srgrimes 431590Srgrimes#include "ctags.h" 441590Srgrimes 451590Srgrimes/* 461590Srgrimes * y_entries: 471590Srgrimes * find the yacc tags and put them in. 481590Srgrimes */ 491590Srgrimesvoid 50100822Sdwmaloney_entries(void) 511590Srgrimes{ 521590Srgrimes int c; 531590Srgrimes char *sp; 541590Srgrimes bool in_rule; 551590Srgrimes char tok[MAXTOKEN]; 561590Srgrimes 571590Srgrimes in_rule = NO; 581590Srgrimes 591590Srgrimes while (GETC(!=, EOF)) 601590Srgrimes switch (c) { 611590Srgrimes case '\n': 621590Srgrimes SETLINE; 631590Srgrimes /* FALLTHROUGH */ 641590Srgrimes case ' ': 651590Srgrimes case '\f': 661590Srgrimes case '\r': 671590Srgrimes case '\t': 681590Srgrimes break; 691590Srgrimes case '{': 701590Srgrimes if (skip_key('}')) 711590Srgrimes in_rule = NO; 721590Srgrimes break; 731590Srgrimes case '\'': 741590Srgrimes case '"': 751590Srgrimes if (skip_key(c)) 761590Srgrimes in_rule = NO; 771590Srgrimes break; 781590Srgrimes case '%': 791590Srgrimes if (GETC(==, '%')) 801590Srgrimes return; 811590Srgrimes (void)ungetc(c, inf); 821590Srgrimes break; 831590Srgrimes case '/': 8491189Sgshapiro if (GETC(==, '*') || c == '/') 8591189Sgshapiro skip_comment(c); 861590Srgrimes else 871590Srgrimes (void)ungetc(c, inf); 881590Srgrimes break; 891590Srgrimes case '|': 901590Srgrimes case ';': 911590Srgrimes in_rule = NO; 921590Srgrimes break; 931590Srgrimes default: 9432069Salex if (in_rule || (!isalpha(c) && c != '.' && c != '_')) 951590Srgrimes break; 961590Srgrimes sp = tok; 971590Srgrimes *sp++ = c; 981590Srgrimes while (GETC(!=, EOF) && (intoken(c) || c == '.')) 991590Srgrimes *sp++ = c; 1001590Srgrimes *sp = EOS; 1011590Srgrimes getline(); /* may change before ':' */ 1021590Srgrimes while (iswhite(c)) { 1031590Srgrimes if (c == '\n') 1041590Srgrimes SETLINE; 1051590Srgrimes if (GETC(==, EOF)) 1061590Srgrimes return; 1071590Srgrimes } 1081590Srgrimes if (c == ':') { 1091590Srgrimes pfnote(tok, lineno); 1101590Srgrimes in_rule = YES; 1111590Srgrimes } 1121590Srgrimes else 1131590Srgrimes (void)ungetc(c, inf); 1141590Srgrimes } 1151590Srgrimes} 1161590Srgrimes 1171590Srgrimes/* 1181590Srgrimes * toss_yysec -- 1191590Srgrimes * throw away lines up to the next "\n%%\n" 1201590Srgrimes */ 1211590Srgrimesvoid 122100822Sdwmalonetoss_yysec(void) 1231590Srgrimes{ 1241590Srgrimes int c; /* read character */ 1251590Srgrimes int state; 1261590Srgrimes 1271590Srgrimes /* 1281590Srgrimes * state == 0 : waiting 1291590Srgrimes * state == 1 : received a newline 1301590Srgrimes * state == 2 : received first % 13187750Scharnier * state == 3 : received second % 1321590Srgrimes */ 1331590Srgrimes lineftell = ftell(inf); 1341590Srgrimes for (state = 0; GETC(!=, EOF);) 1351590Srgrimes switch (c) { 1361590Srgrimes case '\n': 1371590Srgrimes ++lineno; 1381590Srgrimes lineftell = ftell(inf); 1391590Srgrimes if (state == 3) /* done! */ 1401590Srgrimes return; 1411590Srgrimes state = 1; /* start over */ 1421590Srgrimes break; 1431590Srgrimes case '%': 1441590Srgrimes if (state) /* if 1 or 2 */ 1451590Srgrimes ++state; /* goto 3 */ 1461590Srgrimes break; 1471590Srgrimes default: 1481590Srgrimes state = 0; /* reset */ 1491590Srgrimes break; 1501590Srgrimes } 1511590Srgrimes} 152