[BACK]Return to yacc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ctags

Annotation of src/usr.bin/ctags/yacc.c, Revision 1.1

1.1     ! deraadt     1: /*     $NetBSD: yacc.c,v 1.3 1995/03/26 20:14:12 glass Exp $   */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1987, 1993, 1994
        !             5:  *     The Regents of the University of California.  All rights reserved.
        !             6:  *
        !             7:  * Redistribution and use in source and binary forms, with or without
        !             8:  * modification, are permitted provided that the following conditions
        !             9:  * are met:
        !            10:  * 1. Redistributions of source code must retain the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer.
        !            12:  * 2. Redistributions in binary form must reproduce the above copyright
        !            13:  *    notice, this list of conditions and the following disclaimer in the
        !            14:  *    documentation and/or other materials provided with the distribution.
        !            15:  * 3. All advertising materials mentioning features or use of this software
        !            16:  *    must display the following acknowledgement:
        !            17:  *     This product includes software developed by the University of
        !            18:  *     California, Berkeley and its contributors.
        !            19:  * 4. Neither the name of the University nor the names of its contributors
        !            20:  *    may be used to endorse or promote products derived from this software
        !            21:  *    without specific prior written permission.
        !            22:  *
        !            23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            33:  * SUCH DAMAGE.
        !            34:  */
        !            35:
        !            36: #ifndef lint
        !            37: #if 0
        !            38: static char sccsid[] = "@(#)yacc.c     8.3 (Berkeley) 4/2/94";
        !            39: #else
        !            40: static char rcsid[] = "$NetBSD: yacc.c,v 1.3 1995/03/26 20:14:12 glass Exp $";
        !            41: #endif
        !            42: #endif /* not lint */
        !            43:
        !            44: #include <ctype.h>
        !            45: #include <limits.h>
        !            46: #include <stdio.h>
        !            47: #include <string.h>
        !            48:
        !            49: #include "ctags.h"
        !            50:
        !            51: /*
        !            52:  * y_entries:
        !            53:  *     find the yacc tags and put them in.
        !            54:  */
        !            55: void
        !            56: y_entries()
        !            57: {
        !            58:        int     c;
        !            59:        char    *sp;
        !            60:        bool    in_rule;
        !            61:        char    tok[MAXTOKEN];
        !            62:
        !            63:        in_rule = NO;
        !            64:
        !            65:        while (GETC(!=, EOF))
        !            66:                switch (c) {
        !            67:                case '\n':
        !            68:                        SETLINE;
        !            69:                        /* FALLTHROUGH */
        !            70:                case ' ':
        !            71:                case '\f':
        !            72:                case '\r':
        !            73:                case '\t':
        !            74:                        break;
        !            75:                case '{':
        !            76:                        if (skip_key('}'))
        !            77:                                in_rule = NO;
        !            78:                        break;
        !            79:                case '\'':
        !            80:                case '"':
        !            81:                        if (skip_key(c))
        !            82:                                in_rule = NO;
        !            83:                        break;
        !            84:                case '%':
        !            85:                        if (GETC(==, '%'))
        !            86:                                return;
        !            87:                        (void)ungetc(c, inf);
        !            88:                        break;
        !            89:                case '/':
        !            90:                        if (GETC(==, '*'))
        !            91:                                skip_comment();
        !            92:                        else
        !            93:                                (void)ungetc(c, inf);
        !            94:                        break;
        !            95:                case '|':
        !            96:                case ';':
        !            97:                        in_rule = NO;
        !            98:                        break;
        !            99:                default:
        !           100:                        if (in_rule || !isalpha(c) && c != '.' && c != '_')
        !           101:                                break;
        !           102:                        sp = tok;
        !           103:                        *sp++ = c;
        !           104:                        while (GETC(!=, EOF) && (intoken(c) || c == '.'))
        !           105:                                *sp++ = c;
        !           106:                        *sp = EOS;
        !           107:                        getline();              /* may change before ':' */
        !           108:                        while (iswhite(c)) {
        !           109:                                if (c == '\n')
        !           110:                                        SETLINE;
        !           111:                                if (GETC(==, EOF))
        !           112:                                        return;
        !           113:                        }
        !           114:                        if (c == ':') {
        !           115:                                pfnote(tok, lineno);
        !           116:                                in_rule = YES;
        !           117:                        }
        !           118:                        else
        !           119:                                (void)ungetc(c, inf);
        !           120:                }
        !           121: }
        !           122:
        !           123: /*
        !           124:  * toss_yysec --
        !           125:  *     throw away lines up to the next "\n%%\n"
        !           126:  */
        !           127: void
        !           128: toss_yysec()
        !           129: {
        !           130:        int     c;                      /* read character */
        !           131:        int     state;
        !           132:
        !           133:        /*
        !           134:         * state == 0 : waiting
        !           135:         * state == 1 : received a newline
        !           136:         * state == 2 : received first %
        !           137:         * state == 3 : recieved second %
        !           138:         */
        !           139:        lineftell = ftell(inf);
        !           140:        for (state = 0; GETC(!=, EOF);)
        !           141:                switch (c) {
        !           142:                case '\n':
        !           143:                        ++lineno;
        !           144:                        lineftell = ftell(inf);
        !           145:                        if (state == 3)         /* done! */
        !           146:                                return;
        !           147:                        state = 1;              /* start over */
        !           148:                        break;
        !           149:                case '%':
        !           150:                        if (state)              /* if 1 or 2 */
        !           151:                                ++state;        /* goto 3 */
        !           152:                        break;
        !           153:                default:
        !           154:                        state = 0;              /* reset */
        !           155:                        break;
        !           156:                }
        !           157: }