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