xref: /aoo41x/main/soltools/cpp/_nlist.c (revision cdf0e10c)
1*cdf0e10cSrcweir #include <stdio.h>
2*cdf0e10cSrcweir #include <stdlib.h>
3*cdf0e10cSrcweir #include <string.h>
4*cdf0e10cSrcweir #include "cpp.h"
5*cdf0e10cSrcweir 
6*cdf0e10cSrcweir extern int Cplusplus;
7*cdf0e10cSrcweir Nlist *kwdefined;
8*cdf0e10cSrcweir char wd[128];
9*cdf0e10cSrcweir 
10*cdf0e10cSrcweir /*
11*cdf0e10cSrcweir 	ER: Tabelle extra gross gemacht, da es anscheinend ein Problem mit der
12*cdf0e10cSrcweir 	der Verkettung gibt, irgendwann irgendwo wird mal ein nlist->next
13*cdf0e10cSrcweir 	ueberschrieben, was in eineme SIGSEGV resultiert.
14*cdf0e10cSrcweir 	Den GDB mit watchpoint hab ich aber nach 2 Tagen abgebrochen..
15*cdf0e10cSrcweir 	so loeppt's jedenfalls erstmal..
16*cdf0e10cSrcweir  */
17*cdf0e10cSrcweir #define	NLSIZE 15000
18*cdf0e10cSrcweir 
19*cdf0e10cSrcweir static Nlist *nlist[NLSIZE];
20*cdf0e10cSrcweir 
21*cdf0e10cSrcweir struct kwtab
22*cdf0e10cSrcweir {
23*cdf0e10cSrcweir     char *kw;
24*cdf0e10cSrcweir     int val;
25*cdf0e10cSrcweir     int flag;
26*cdf0e10cSrcweir }   kwtab[] =
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir {
29*cdf0e10cSrcweir 		{"if", KIF, ISKW},
30*cdf0e10cSrcweir 		{"ifdef", KIFDEF, ISKW},
31*cdf0e10cSrcweir 		{"ifndef", KIFNDEF, ISKW},
32*cdf0e10cSrcweir 		{"elif", KELIF, ISKW},
33*cdf0e10cSrcweir 		{"else", KELSE, ISKW},
34*cdf0e10cSrcweir 		{"endif", KENDIF, ISKW},
35*cdf0e10cSrcweir 		{"include", KINCLUDE, ISKW},
36*cdf0e10cSrcweir 		{"include_next", KINCLUDENEXT, ISKW},
37*cdf0e10cSrcweir 		{"import", KIMPORT, ISKW},
38*cdf0e10cSrcweir 		{"define", KDEFINE, ISKW},
39*cdf0e10cSrcweir 		{"undef", KUNDEF, ISKW},
40*cdf0e10cSrcweir 		{"line", KLINE, ISKW},
41*cdf0e10cSrcweir 		{"error", KERROR, ISKW},
42*cdf0e10cSrcweir 		{"pragma", KPRAGMA, ISKW},
43*cdf0e10cSrcweir 		{"ident", KIDENT, ISKW},
44*cdf0e10cSrcweir 		{"eval", KEVAL, ISKW},
45*cdf0e10cSrcweir 		{"defined", KDEFINED, ISDEFINED + ISUNCHANGE},
46*cdf0e10cSrcweir 		{"machine", KMACHINE, ISDEFINED + ISUNCHANGE},
47*cdf0e10cSrcweir 		{"__LINE__", KLINENO, ISMAC + ISUNCHANGE},
48*cdf0e10cSrcweir 		{"__FILE__", KFILE, ISMAC + ISUNCHANGE},
49*cdf0e10cSrcweir 		{"__DATE__", KDATE, ISMAC + ISUNCHANGE},
50*cdf0e10cSrcweir 		{"__TIME__", KTIME, ISMAC + ISUNCHANGE},
51*cdf0e10cSrcweir 		{"__STDC__", KSTDC, ISUNCHANGE},
52*cdf0e10cSrcweir 		{NULL, 0, 0}
53*cdf0e10cSrcweir };
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir unsigned long namebit[077 + 1];
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir void
58*cdf0e10cSrcweir     setup_kwtab(void)
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir     struct kwtab *kp;
61*cdf0e10cSrcweir     Nlist *np;
62*cdf0e10cSrcweir     Token t;
63*cdf0e10cSrcweir     static Token deftoken[1] = {{NAME, 0, 0, 7, (uchar *) "defined", 0}};
64*cdf0e10cSrcweir     static Tokenrow deftr = {deftoken, deftoken, deftoken + 1, 1};
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     for (kp = kwtab; kp->kw; kp++)
67*cdf0e10cSrcweir     {
68*cdf0e10cSrcweir         t.t = (uchar *) kp->kw;
69*cdf0e10cSrcweir         t.len = strlen(kp->kw);
70*cdf0e10cSrcweir         np = lookup(&t, 1);
71*cdf0e10cSrcweir         np->flag = (char) kp->flag;
72*cdf0e10cSrcweir         np->val = (char) kp->val;
73*cdf0e10cSrcweir         if (np->val == KDEFINED)
74*cdf0e10cSrcweir         {
75*cdf0e10cSrcweir             kwdefined = np;
76*cdf0e10cSrcweir             np->val = NAME;
77*cdf0e10cSrcweir             np->vp = &deftr;
78*cdf0e10cSrcweir             np->ap = 0;
79*cdf0e10cSrcweir         }
80*cdf0e10cSrcweir     }
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir Nlist *
84*cdf0e10cSrcweir     lookup(Token * tp, int install)
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     unsigned int h;
87*cdf0e10cSrcweir     Nlist *np;
88*cdf0e10cSrcweir     uchar *cp, *cpe;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     h = 0;
91*cdf0e10cSrcweir     for (cp = tp->t, cpe = cp + tp->len; cp < cpe;)
92*cdf0e10cSrcweir         h += *cp++;
93*cdf0e10cSrcweir     h %= NLSIZE;
94*cdf0e10cSrcweir     np = nlist[h];
95*cdf0e10cSrcweir     while (np)
96*cdf0e10cSrcweir     {
97*cdf0e10cSrcweir         if (*tp->t == *np->name && tp->len == (unsigned int)np->len
98*cdf0e10cSrcweir             && strncmp((char *)tp->t, (char *)np->name, tp->len) == 0)
99*cdf0e10cSrcweir             return np;
100*cdf0e10cSrcweir         np = np->next;
101*cdf0e10cSrcweir     }
102*cdf0e10cSrcweir     if (install)
103*cdf0e10cSrcweir     {
104*cdf0e10cSrcweir         np = new(Nlist);
105*cdf0e10cSrcweir         np->vp = NULL;
106*cdf0e10cSrcweir         np->ap = NULL;
107*cdf0e10cSrcweir         np->flag = 0;
108*cdf0e10cSrcweir         np->val = 0;
109*cdf0e10cSrcweir         np->len = tp->len;
110*cdf0e10cSrcweir         np->name = newstring(tp->t, tp->len, 0);
111*cdf0e10cSrcweir         np->next = nlist[h];
112*cdf0e10cSrcweir         nlist[h] = np;
113*cdf0e10cSrcweir         quickset(tp->t[0], tp->len > 1 ? tp->t[1] : 0);
114*cdf0e10cSrcweir         return np;
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir     return NULL;
117*cdf0e10cSrcweir }
118