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

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

1.1     ! deraadt     1: /*     $NetBSD: tree.c,v 1.4 1995/03/26 20:14:11 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[] = "@(#)tree.c     8.3 (Berkeley) 4/2/94";
        !            39: #else
        !            40: static char rcsid[] = "$NetBSD: tree.c,v 1.4 1995/03/26 20:14:11 glass Exp $";
        !            41: #endif
        !            42: #endif /* not lint */
        !            43:
        !            44: #include <err.h>
        !            45: #include <limits.h>
        !            46: #include <stdio.h>
        !            47: #include <stdlib.h>
        !            48: #include <string.h>
        !            49:
        !            50: #include "ctags.h"
        !            51:
        !            52: static void    add_node __P((NODE *, NODE *));
        !            53: static void    free_tree __P((NODE *));
        !            54:
        !            55: /*
        !            56:  * pfnote --
        !            57:  *     enter a new node in the tree
        !            58:  */
        !            59: void
        !            60: pfnote(name, ln)
        !            61:        char    *name;
        !            62:        int     ln;
        !            63: {
        !            64:        NODE    *np;
        !            65:        char    *fp;
        !            66:        char    nbuf[MAXTOKEN];
        !            67:
        !            68:        /*NOSTRICT*/
        !            69:        if (!(np = (NODE *)malloc(sizeof(NODE)))) {
        !            70:                warnx("too many entries to sort");
        !            71:                put_entries(head);
        !            72:                free_tree(head);
        !            73:                /*NOSTRICT*/
        !            74:                if (!(head = np = (NODE *)malloc(sizeof(NODE))))
        !            75:                        err(1, "out of space");
        !            76:        }
        !            77:        if (!xflag && !strcmp(name, "main")) {
        !            78:                if (!(fp = strrchr(curfile, '/')))
        !            79:                        fp = curfile;
        !            80:                else
        !            81:                        ++fp;
        !            82:                (void)sprintf(nbuf, "M%s", fp);
        !            83:                fp = strrchr(nbuf, '.');
        !            84:                if (fp && !fp[2])
        !            85:                        *fp = EOS;
        !            86:                name = nbuf;
        !            87:        }
        !            88:        if (!(np->entry = strdup(name)))
        !            89:                err(1, NULL);
        !            90:        np->file = curfile;
        !            91:        np->lno = ln;
        !            92:        np->left = np->right = 0;
        !            93:        if (!(np->pat = strdup(lbuf)))
        !            94:                err(1, NULL);
        !            95:        if (!head)
        !            96:                head = np;
        !            97:        else
        !            98:                add_node(np, head);
        !            99: }
        !           100:
        !           101: static void
        !           102: add_node(node, cur_node)
        !           103:        NODE    *node,
        !           104:                *cur_node;
        !           105: {
        !           106:        int     dif;
        !           107:
        !           108:        dif = strcmp(node->entry, cur_node->entry);
        !           109:        if (!dif) {
        !           110:                if (node->file == cur_node->file) {
        !           111:                        if (!wflag)
        !           112:                                fprintf(stderr, "Duplicate entry in file %s, line %d: %s\nSecond entry ignored\n", node->file, lineno, node->entry);
        !           113:                        return;
        !           114:                }
        !           115:                if (!cur_node->been_warned)
        !           116:                        if (!wflag)
        !           117:                                fprintf(stderr, "Duplicate entry in files %s and %s: %s (Warning only)\n", node->file, cur_node->file, node->entry);
        !           118:                cur_node->been_warned = YES;
        !           119:        }
        !           120:        else if (dif < 0)
        !           121:                if (cur_node->left)
        !           122:                        add_node(node, cur_node->left);
        !           123:                else
        !           124:                        cur_node->left = node;
        !           125:        else if (cur_node->right)
        !           126:                add_node(node, cur_node->right);
        !           127:        else
        !           128:                cur_node->right = node;
        !           129: }
        !           130:
        !           131: static void
        !           132: free_tree(node)
        !           133:        NODE    *node;
        !           134: {
        !           135:        while (node) {
        !           136:                if (node->right)
        !           137:                        free_tree(node->right);
        !           138:                free(node);
        !           139:                node = node->left;
        !           140:        }
        !           141: }