Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

nlist.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include "cpp.h"
00005 
00006 extern  int getopt(int, char *const *, const char *);
00007 extern  char    *optarg;
00008 extern  int optind;
00009 extern  int verbose;
00010 extern  int Cplusplus;
00011 Nlist   *kwdefined;
00012 char    wd[128];
00013 
00014 #define NLSIZE  128
00015 
00016 static Nlist    *nlist[NLSIZE];
00017 
00018 struct  kwtab {
00019     char    *kw;
00020     int val;
00021     int flag;
00022 } kwtab[] = {
00023     "if",       KIF,        ISKW,
00024     "ifdef",    KIFDEF,     ISKW,
00025     "ifndef",   KIFNDEF,    ISKW,
00026     "elif",     KELIF,      ISKW,
00027     "else",     KELSE,      ISKW,
00028     "endif",    KENDIF,     ISKW,
00029     "include",  KINCLUDE,   ISKW,
00030     "define",   KDEFINE,    ISKW,
00031     "undef",    KUNDEF,     ISKW,
00032     "line",     KLINE,      ISKW,
00033     "error",    KERROR,     ISKW,
00034     "pragma",   KPRAGMA,    ISKW,
00035     "eval",     KEVAL,      ISKW,
00036     "defined",  KDEFINED,   ISDEFINED+ISUNCHANGE,
00037     "__LINE__", KLINENO,    ISMAC+ISUNCHANGE,
00038     "__FILE__", KFILE,      ISMAC+ISUNCHANGE,
00039     "__DATE__", KDATE,      ISMAC+ISUNCHANGE,
00040     "__TIME__", KTIME,      ISMAC+ISUNCHANGE,
00041     "__STDC__", KSTDC,      ISUNCHANGE,
00042     NULL
00043 };
00044 
00045 unsigned long   namebit[077+1];
00046 Nlist   *np;
00047 
00048 void
00049 setup_kwtab(void)
00050 {
00051     struct kwtab *kp;
00052     Nlist *np;
00053     Token t;
00054     static Token deftoken[1] = {{ NAME, 0, 0, 0, 7, (uchar*)"defined" }};
00055     static Tokenrow deftr = { deftoken, deftoken, deftoken+1, 1 };
00056 
00057     for (kp=kwtab; kp->kw; kp++) {
00058         t.t = (uchar*)kp->kw;
00059         t.len = strlen(kp->kw);
00060         np = lookup(&t, 1);
00061         np->flag = kp->flag;
00062         np->val = kp->val;
00063         if (np->val == KDEFINED) {
00064             kwdefined = np;
00065             np->val = NAME;
00066             np->vp = &deftr;
00067             np->ap = 0;
00068         }
00069     }
00070 }
00071 
00072 Nlist *
00073 lookup(Token *tp, int install)
00074 {
00075     unsigned int h;
00076     Nlist *np;
00077     uchar *cp, *cpe;
00078 
00079     h = 0;
00080     for (cp=tp->t, cpe=cp+tp->len; cp<cpe; )
00081         h += *cp++;
00082     h %= NLSIZE;
00083     np = nlist[h];
00084     while (np) {
00085         if (*tp->t==*np->name && tp->len==np->len 
00086          && strncmp((char*)tp->t, (char*)np->name, tp->len)==0)
00087             return np;
00088         np = np->next;
00089     }
00090     if (install) {
00091         np = new(Nlist);
00092         np->vp = NULL;
00093         np->ap = NULL;
00094         np->flag = 0;
00095         np->val = 0;
00096         np->len = tp->len;
00097         np->name = newstring(tp->t, tp->len, 0);
00098         np->next = nlist[h];
00099         nlist[h] = np;
00100         quickset(tp->t[0], tp->len>1? tp->t[1]:0);
00101         return np;
00102     }
00103     return NULL;
00104 }

Generated on Thu Aug 25 12:38:09 2005 for Quake III Arena by  doxygen 1.3.9.1