2010-10-27 06:38:25 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-04-19 02:20:23 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
extern int Cplusplus;
|
|
|
|
Nlist *kwdefined;
|
|
|
|
char wd[128];
|
|
|
|
|
|
|
|
/*
|
|
|
|
ER: Tabelle extra gross gemacht, da es anscheinend ein Problem mit der
|
|
|
|
der Verkettung gibt, irgendwann irgendwo wird mal ein nlist->next
|
|
|
|
ueberschrieben, was in eineme SIGSEGV resultiert.
|
|
|
|
Den GDB mit watchpoint hab ich aber nach 2 Tagen abgebrochen..
|
2006-06-19 23:06:54 -05:00
|
|
|
so loeppt's jedenfalls erstmal..
|
2001-04-19 02:20:23 -05:00
|
|
|
*/
|
|
|
|
#define NLSIZE 15000
|
|
|
|
|
|
|
|
static Nlist *nlist[NLSIZE];
|
|
|
|
|
|
|
|
struct kwtab
|
|
|
|
{
|
|
|
|
char *kw;
|
|
|
|
int val;
|
|
|
|
int flag;
|
|
|
|
} kwtab[] =
|
|
|
|
|
|
|
|
{
|
2004-04-21 07:25:20 -05:00
|
|
|
{"if", KIF, ISKW},
|
|
|
|
{"ifdef", KIFDEF, ISKW},
|
|
|
|
{"ifndef", KIFNDEF, ISKW},
|
|
|
|
{"elif", KELIF, ISKW},
|
|
|
|
{"else", KELSE, ISKW},
|
|
|
|
{"endif", KENDIF, ISKW},
|
|
|
|
{"include", KINCLUDE, ISKW},
|
|
|
|
{"include_next", KINCLUDENEXT, ISKW},
|
|
|
|
{"import", KIMPORT, ISKW},
|
|
|
|
{"define", KDEFINE, ISKW},
|
|
|
|
{"undef", KUNDEF, ISKW},
|
|
|
|
{"line", KLINE, ISKW},
|
|
|
|
{"error", KERROR, ISKW},
|
|
|
|
{"pragma", KPRAGMA, ISKW},
|
|
|
|
{"ident", KIDENT, ISKW},
|
|
|
|
{"eval", KEVAL, ISKW},
|
|
|
|
{"defined", KDEFINED, ISDEFINED + ISUNCHANGE},
|
|
|
|
{"machine", KMACHINE, ISDEFINED + ISUNCHANGE},
|
|
|
|
{"__LINE__", KLINENO, ISMAC + ISUNCHANGE},
|
|
|
|
{"__FILE__", KFILE, ISMAC + ISUNCHANGE},
|
|
|
|
{"__DATE__", KDATE, ISMAC + ISUNCHANGE},
|
|
|
|
{"__TIME__", KTIME, ISMAC + ISUNCHANGE},
|
|
|
|
{"__STDC__", KSTDC, ISUNCHANGE},
|
2006-06-19 23:06:54 -05:00
|
|
|
{NULL, 0, 0}
|
2001-04-19 02:20:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
unsigned long namebit[077 + 1];
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_kwtab(void)
|
|
|
|
{
|
|
|
|
struct kwtab *kp;
|
|
|
|
Nlist *np;
|
|
|
|
Token t;
|
2006-06-19 23:06:54 -05:00
|
|
|
static Token deftoken[1] = {{NAME, 0, 0, 7, (uchar *) "defined", 0}};
|
2001-04-19 02:20:23 -05:00
|
|
|
static Tokenrow deftr = {deftoken, deftoken, deftoken + 1, 1};
|
|
|
|
|
|
|
|
for (kp = kwtab; kp->kw; kp++)
|
|
|
|
{
|
|
|
|
t.t = (uchar *) kp->kw;
|
|
|
|
t.len = strlen(kp->kw);
|
|
|
|
np = lookup(&t, 1);
|
2006-06-19 23:06:54 -05:00
|
|
|
np->flag = (char) kp->flag;
|
|
|
|
np->val = (char) kp->val;
|
2001-04-19 02:20:23 -05:00
|
|
|
if (np->val == KDEFINED)
|
|
|
|
{
|
|
|
|
kwdefined = np;
|
|
|
|
np->val = NAME;
|
|
|
|
np->vp = &deftr;
|
|
|
|
np->ap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Nlist *
|
|
|
|
lookup(Token * tp, int install)
|
|
|
|
{
|
|
|
|
unsigned int h;
|
|
|
|
Nlist *np;
|
|
|
|
uchar *cp, *cpe;
|
|
|
|
|
|
|
|
h = 0;
|
|
|
|
for (cp = tp->t, cpe = cp + tp->len; cp < cpe;)
|
|
|
|
h += *cp++;
|
|
|
|
h %= NLSIZE;
|
|
|
|
np = nlist[h];
|
|
|
|
while (np)
|
|
|
|
{
|
|
|
|
if (*tp->t == *np->name && tp->len == (unsigned int)np->len
|
|
|
|
&& strncmp((char *)tp->t, (char *)np->name, tp->len) == 0)
|
|
|
|
return np;
|
|
|
|
np = np->next;
|
|
|
|
}
|
|
|
|
if (install)
|
|
|
|
{
|
|
|
|
np = new(Nlist);
|
|
|
|
np->vp = NULL;
|
|
|
|
np->ap = NULL;
|
|
|
|
np->flag = 0;
|
|
|
|
np->val = 0;
|
|
|
|
np->len = tp->len;
|
|
|
|
np->name = newstring(tp->t, tp->len, 0);
|
|
|
|
np->next = nlist[h];
|
|
|
|
nlist[h] = np;
|
|
|
|
quickset(tp->t[0], tp->len > 1 ? tp->t[1] : 0);
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-27 06:38:25 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|