Commit | Line | Data |
---|---|---|
6516bc59 | 1 | /* |
ffa8a268 KB |
2 | * Copyright (c) 1987 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
a3bb5b82 | 5 | * %sccs.include.redist.c% |
6516bc59 KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
a3bb5b82 | 9 | static char sccsid[] = "@(#)tree.c 5.4 (Berkeley) %G%"; |
ffa8a268 | 10 | #endif /* not lint */ |
6516bc59 KB |
11 | |
12 | #include <ctags.h> | |
38dde0cd | 13 | #include <string.h> |
6516bc59 KB |
14 | |
15 | /* | |
16 | * pfnote -- | |
17 | * enter a new node in the tree | |
18 | */ | |
19 | pfnote(name,ln) | |
20 | char *name; | |
21 | int ln; | |
22 | { | |
23 | extern NODE *head; /* head of the sorted binary tree */ | |
24 | extern char *curfile; /* current input file name */ | |
25 | register NODE *np; | |
26 | register char *fp; | |
27 | char nbuf[MAXTOKEN], | |
28 | *malloc(), *savestr(); | |
29 | ||
30 | /*NOSTRICT*/ | |
31 | if (!(np = (NODE *)malloc(sizeof(NODE)))) { | |
32 | fputs("ctags: too many entries to sort\n",stderr); | |
33 | put_entries(head); | |
34 | free_tree(head); | |
35 | /*NOSTRICT*/ | |
36 | if (!(head = np = (NODE *)malloc(sizeof(NODE)))) { | |
37 | fputs("ctags: out of space.\n",stderr); | |
38 | exit(1); | |
39 | } | |
40 | } | |
41 | if (!xflag && !strcmp(name,"main")) { | |
42 | if (!(fp = rindex(curfile,'/'))) | |
43 | fp = curfile; | |
44 | else | |
45 | ++fp; | |
46 | (void)sprintf(nbuf,"M%s",fp); | |
47 | fp = rindex(nbuf,'.'); | |
48 | if (fp && !fp[2]) | |
49 | *fp = EOS; | |
50 | name = nbuf; | |
51 | } | |
52 | np->entry = savestr(name); | |
53 | np->file = curfile; | |
54 | np->lno = ln; | |
55 | np->left = np->right = 0; | |
56 | np->pat = savestr(lbuf); | |
57 | if (!head) | |
58 | head = np; | |
59 | else | |
60 | add_node(np,head); | |
61 | } | |
62 | ||
63 | add_node(node,cur_node) | |
64 | register NODE *node, | |
65 | *cur_node; | |
66 | { | |
67 | extern int wflag; /* -w: suppress warnings */ | |
68 | register int dif; | |
69 | ||
70 | dif = strcmp(node->entry,cur_node->entry); | |
71 | if (!dif) { | |
72 | if (node->file == cur_node->file) { | |
73 | if (!wflag) | |
74 | fprintf(stderr,"Duplicate entry in file %s, line %d: %s\nSecond entry ignored\n",node->file,lineno,node->entry); | |
75 | return; | |
76 | } | |
77 | if (!cur_node->been_warned) | |
78 | if (!wflag) | |
79 | fprintf(stderr,"Duplicate entry in files %s and %s: %s (Warning only)\n",node->file,cur_node->file,node->entry); | |
80 | cur_node->been_warned = YES; | |
81 | } | |
82 | else if (dif < 0) | |
83 | if (cur_node->left) | |
84 | add_node(node,cur_node->left); | |
85 | else | |
86 | cur_node->left = node; | |
87 | else if (cur_node->right) | |
88 | add_node(node,cur_node->right); | |
89 | else | |
90 | cur_node->right = node; | |
91 | } | |
92 | ||
93 | free_tree(node) | |
94 | register NODE *node; | |
95 | { | |
96 | while (node) { | |
97 | if (node->right) | |
98 | free_tree(node->right); | |
99 | cfree(node); | |
100 | node = node->left; | |
101 | } | |
102 | } |