1 /* 2 * Copyright (c) 1987, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 04/02/94"; 10 #endif /* not lint */ 11 12 #include <ctype.h> 13 #include <limits.h> 14 #include <stdio.h> 15 #include <string.h> 16 17 #include "ctags.h" 18 19 /* 20 * y_entries: 21 * find the yacc tags and put them in. 22 */ 23 void 24 y_entries() 25 { 26 int c; 27 char *sp; 28 bool in_rule; 29 char tok[MAXTOKEN]; 30 31 in_rule = NO; 32 33 while (GETC(!=, EOF)) 34 switch (c) { 35 case '\n': 36 SETLINE; 37 /* FALLTHROUGH */ 38 case ' ': 39 case '\f': 40 case '\r': 41 case '\t': 42 break; 43 case '{': 44 if (skip_key('}')) 45 in_rule = NO; 46 break; 47 case '\'': 48 case '"': 49 if (skip_key(c)) 50 in_rule = NO; 51 break; 52 case '%': 53 if (GETC(==, '%')) 54 return; 55 (void)ungetc(c, inf); 56 break; 57 case '/': 58 if (GETC(==, '*')) 59 skip_comment(); 60 else 61 (void)ungetc(c, inf); 62 break; 63 case '|': 64 case ';': 65 in_rule = NO; 66 break; 67 default: 68 if (in_rule || !isalpha(c) && c != '.' && c != '_') 69 break; 70 sp = tok; 71 *sp++ = c; 72 while (GETC(!=, EOF) && (intoken(c) || c == '.')) 73 *sp++ = c; 74 *sp = EOS; 75 getline(); /* may change before ':' */ 76 while (iswhite(c)) { 77 if (c == '\n') 78 SETLINE; 79 if (GETC(==, EOF)) 80 return; 81 } 82 if (c == ':') { 83 pfnote(tok, lineno); 84 in_rule = YES; 85 } 86 else 87 (void)ungetc(c, inf); 88 } 89 } 90 91 /* 92 * toss_yysec -- 93 * throw away lines up to the next "\n%%\n" 94 */ 95 void 96 toss_yysec() 97 { 98 int c; /* read character */ 99 int state; 100 101 /* 102 * state == 0 : waiting 103 * state == 1 : received a newline 104 * state == 2 : received first % 105 * state == 3 : recieved second % 106 */ 107 lineftell = ftell(inf); 108 for (state = 0; GETC(!=, EOF);) 109 switch (c) { 110 case '\n': 111 ++lineno; 112 lineftell = ftell(inf); 113 if (state == 3) /* done! */ 114 return; 115 state = 1; /* start over */ 116 break; 117 case '%': 118 if (state) /* if 1 or 2 */ 119 ++state; /* goto 3 */ 120 break; 121 default: 122 state = 0; /* reset */ 123 break; 124 } 125 } 126