update dev300-m58
[ooovba.git] / idlc / source / preproc / nlist.c
blob606a2230f3fbc569f682d5a841bb8cffd51e449f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: nlist.c,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include "cpp.h"
35 extern int cppgetopt(int, char *const *, const char *);
36 extern char *optarg;
37 extern int optind;
38 extern int Cplusplus;
39 Nlist *kwdefined;
40 char wd[128];
42 /*
43 ER: Tabelle extra gross gemacht, da es anscheinend ein Problem mit der
44 der Verkettung gibt, irgendwann irgendwo wird mal ein nlist->next
45 ueberschrieben, was in eineme SIGSEGV resultiert.
46 Den GDB mit watchpoint hab ich aber nach 2 Tagen abgebrochen..
47 so loeppt's jedenfalls erstmal..
49 #define NLSIZE 15000
51 static Nlist *nlist[NLSIZE];
53 struct kwtab
55 char *kw;
56 int val;
57 int flag;
58 } kwtab[] =
61 { "if", KIF, ISKW },
62 { "ifdef", KIFDEF, ISKW },
63 { "ifndef", KIFNDEF, ISKW },
64 { "elif", KELIF, ISKW },
65 { "else", KELSE, ISKW },
66 { "endif", KENDIF, ISKW },
67 { "include", KINCLUDE, ISKW },
68 { "include_next", KINCLUDENEXT, ISKW },
69 { "import", KIMPORT, ISKW },
70 { "define", KDEFINE, ISKW },
71 { "undef", KUNDEF, ISKW },
72 { "line", KLINE, ISKW },
73 { "error", KERROR, ISKW },
74 { "pragma", KPRAGMA, ISKW },
75 { "ident", KIDENT, ISKW },
76 { "eval", KEVAL, ISKW },
77 { "defined", KDEFINED, ISDEFINED + ISUNCHANGE },
78 { "machine", KMACHINE, ISDEFINED + ISUNCHANGE },
79 { "__LINE__", KLINENO, ISMAC + ISUNCHANGE },
80 { "__FILE__", KFILE, ISMAC + ISUNCHANGE },
81 { "__DATE__", KDATE, ISMAC + ISUNCHANGE },
82 { "__TIME__", KTIME, ISMAC + ISUNCHANGE },
83 { "__STDC__", KSTDC, ISUNCHANGE },
84 { NULL, 0, 0 }
87 unsigned long namebit[077 + 1];
89 void
90 setup_kwtab(void)
92 struct kwtab *kp;
93 Nlist *np;
94 Token t;
95 static Token deftoken[1] = {{NAME, 0, 0, 7, (uchar *) "defined"}};
96 static Tokenrow deftr = {deftoken, deftoken, deftoken + 1, 1};
98 for (kp = kwtab; kp->kw; kp++)
100 t.t = (uchar *) kp->kw;
101 t.len = strlen(kp->kw);
102 np = lookup(&t, 1);
103 np->flag = (char) kp->flag;
104 np->val = (char) kp->val;
105 if (np->val == KDEFINED)
107 kwdefined = np;
108 np->val = NAME;
109 np->vp = &deftr;
110 np->ap = 0;
115 Nlist *
116 lookup(Token * tp, int install)
118 unsigned int h;
119 Nlist *np;
120 uchar *cp, *cpe;
122 h = 0;
123 for (cp = tp->t, cpe = cp + tp->len; cp < cpe;)
124 h += *cp++;
125 h %= NLSIZE;
126 np = nlist[h];
127 while (np)
129 if (*tp->t == *np->name && tp->len == (unsigned int)np->len
130 && strncmp((char *)tp->t, (char *)np->name, tp->len) == 0)
131 return np;
132 np = np->next;
134 if (install)
136 np = new(Nlist);
137 np->vp = NULL;
138 np->ap = NULL;
139 np->flag = 0;
140 np->val = 0;
141 np->len = tp->len;
142 np->name = newstring(tp->t, tp->len, 0);
143 np->next = nlist[h];
144 nlist[h] = np;
145 quickset(tp->t[0], tp->len > 1 ? tp->t[1] : 0);
146 return np;
148 return NULL;