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