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

cpp.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  includelist
struct  nlist
struct  source
struct  token
struct  tokenrow

Defines

#define EOB   0xFE
#define EOF   (-1)
#define EOFC   0xFD
#define INS   32768
#define ISDEFINED   01
#define ISKW   02
#define ISMAC   010
#define ISUNCHANGE   04
#define NARG   32
#define new(t)   (t *)domalloc(sizeof(t))
#define NIF   32
#define NINCLUDE   32
#define NULL   0
#define OBS   4096
#define quicklook(a, b)   (namebit[(a)&077] & (1<<((b)&037)))
#define quickset(a, b)   namebit[(a)&077] |= (1<<((b)&037))
#define rowlen(tokrow)   ((tokrow)->lp - (tokrow)->bp)
#define XPWS   1

Typedefs

typedef includelist Includelist
typedef nlist Nlist
typedef source Source
typedef token Token
typedef tokenrow Tokenrow
typedef unsigned char uchar

Enumerations

enum  errtype { WARNING, ERROR, FATAL }
enum  kwtype {
  KIF, KIFDEF, KIFNDEF, KELIF,
  KELSE, KENDIF, KINCLUDE, KDEFINE,
  KUNDEF, KLINE, KERROR, KPRAGMA,
  KDEFINED, KLINENO, KFILE, KDATE,
  KTIME, KSTDC, KEVAL
}
enum  toktype {
  END, UNCLASS, NAME, NUMBER,
  STRING, CCON, NL, WS,
  DSHARP, EQ, NEQ, LEQ,
  GEQ, LSH, RSH, LAND,
  LOR, PPLUS, MMINUS, ARROW,
  SBRA, SKET, LP, RP,
  DOT, AND = 38<<4, STAR, PLUS,
  MINUS, TILDE, NOT, SLASH,
  PCT, LT, GT, CIRC,
  OR, QUEST, COLON, ASGN,
  COMMA, SHARP, SEMIC, CBRA,
  CKET, ASPLUS, ASMINUS, ASSTAR,
  ASSLASH, ASPCT, ASCIRC, ASLSH,
  ASRSH, ASOR, ASAND, ELLIPS,
  DSHARP1, NAME1, DEFINED, UMINUS
}

Functions

void adjustrow (Tokenrow *, int)
void builtin (Tokenrow *, int)
int checkhideset (int, Nlist *)
int close (int)
int comparetokens (Tokenrow *, Tokenrow *)
void control (Tokenrow *)
Tokenrowcopytokenrow (Tokenrow *, Tokenrow *)
int creat (char *, int)
int digit (int)
void doadefine (Tokenrow *, int)
void doconcat (Tokenrow *)
void dodefine (Tokenrow *)
void dofree (void *)
void doif (Tokenrow *, enum kwtype)
void doinclude (Tokenrow *)
void * domalloc (int)
int dup2 (int, int)
void error (enum errtype, char *,...)
long eval (Tokenrow *, int)
void expand (Tokenrow *, Nlist *)
void expandlex (void)
void expandrow (Tokenrow *, char *)
int fillbuf (Source *)
void fixlex (void)
void flushout (void)
int foldline (Source *)
int gatherargs (Tokenrow *, Tokenrow **, int *)
void genline (void)
int gettokens (Tokenrow *, int)
Tokengrowtokenrow (Tokenrow *)
void iniths (void)
void insertrow (Tokenrow *, int, Tokenrow *)
Nlistlookup (Token *, int)
int lookuparg (Nlist *, Token *)
void makespace (Tokenrow *)
void maketokenrow (int, Tokenrow *)
void movetokenrow (Tokenrow *, Tokenrow *)
int newhideset (int, Nlist *)
ucharnewstring (uchar *, int, int)
Tokenrownormtokenrow (Tokenrow *)
int open (char *, int)
char * outnum (char *, int)
void peektokens (Tokenrow *, char *)
void prhideset (int)
void process (Tokenrow *)
void puttokens (Tokenrow *)
int read (int, char *, size_t)
void setempty (Tokenrow *)
void setobjname (char *)
Sourcesetsource (char *, int, char *)
void setup (int, char **)
Tokenrowstringify (Tokenrow *)
void substargs (Nlist *, Tokenrow *, Tokenrow **)
int trigraph (Source *)
int unionhideset (int, int)
void unsetsource (void)
int write (int, char *, size_t)

Variables

int Cplusplus
Sourcecursource
char * curtime
int ifdepth
int ifsatisfied [NIF]
int incdepth
Includelist includelist [NINCLUDE]
Nlistkwdefined
int Mflag
unsigned long namebit [077+1]
Token nltoken
char * outp
int skipping
int verbose
char wd []


Define Documentation

#define EOB   0xFE
 

Definition at line 35 of file cpp.h.

Referenced by encode_mcu_AC_refine().

#define EOF   (-1)
 

Definition at line 7 of file cpp.h.

Referenced by getd(), getstr(), and yylex().

#define EOFC   0xFD
 

Definition at line 36 of file cpp.h.

#define INS   32768
 

Definition at line 1 of file cpp.h.

Referenced by fillbuf(), gettokens(), and setsource().

#define ISDEFINED   01
 

Definition at line 30 of file cpp.h.

Referenced by eval(), expandrow(), and tokval().

#define ISKW   02
 

Definition at line 31 of file cpp.h.

#define ISMAC   010
 

Definition at line 33 of file cpp.h.

#define ISUNCHANGE   04
 

Definition at line 32 of file cpp.h.

#define NARG   32
 

Definition at line 3 of file cpp.h.

Referenced by expand(), and gatherargs().

#define new t   )     (t *)domalloc(sizeof(t))
 

Definition at line 83 of file cpp.h.

#define NIF   32
 

Definition at line 5 of file cpp.h.

#define NINCLUDE   32
 

Definition at line 4 of file cpp.h.

Referenced by doinclude(), and setup().

#define NULL   0
 

Definition at line 10 of file cpp.h.

#define OBS   4096
 

Definition at line 2 of file cpp.h.

Referenced by puttokens().

#define quicklook a,
 )     (namebit[(a)&077] & (1<<((b)&037)))
 

Definition at line 84 of file cpp.h.

Referenced by expandrow(), and gettokens().

#define quickset a,
 )     namebit[(a)&077] |= (1<<((b)&037))
 

Definition at line 85 of file cpp.h.

Referenced by lookup().

#define rowlen tokrow   )     ((tokrow)->lp - (tokrow)->bp)
 

Definition at line 141 of file cpp.h.

Referenced by copytokenrow(), expand(), and insertrow().

#define XPWS   1
 

Definition at line 37 of file cpp.h.

Referenced by makespace().


Typedef Documentation

typedef struct includelist Includelist
 

Referenced by doinclude().

typedef struct nlist Nlist
 

Referenced by checkhideset(), control(), doadefine(), dodefine(), eval(), expand(), expandrow(), inserths(), lookup(), lookuparg(), newhideset(), setup_kwtab(), substargs(), and tokval().

typedef struct source Source
 

Referenced by builtin(), error(), fillbuf(), foldline(), gettokens(), setsource(), trigraph(), and unsetsource().

typedef struct token Token
 

Referenced by builtin(), comparetokens(), control(), doadefine(), doconcat(), dodefine(), error(), eval(), expand(), expandrow(), gatherargs(), genline(), gettokens(), growtokenrow(), lookup(), lookuparg(), makespace(), maketokenrow(), normtokenrow(), peektokens(), puttokens(), setup_kwtab(), stringify(), substargs(), and tokval().

typedef struct tokenrow Tokenrow
 

Referenced by adjustrow(), builtin(), comparetokens(), control(), copytokenrow(), doadefine(), doconcat(), dodefine(), doinclude(), error(), eval(), expand(), expandrow(), gatherargs(), genline(), gettokens(), growtokenrow(), insertrow(), main(), makespace(), maketokenrow(), movetokenrow(), normtokenrow(), peektokens(), process(), puttokens(), setempty(), setup(), setup_kwtab(), stringify(), and substargs().

typedef unsigned char uchar
 

Definition at line 14 of file cpp.h.

Referenced by builtin(), doadefine(), doinclude(), genline(), gettokens(), lookup(), makespace(), newstring(), puttokens(), setup(), setup_kwtab(), stringify(), and tokval().


Enumeration Type Documentation

enum errtype
 

Enumeration values:
WARNING 
ERROR 
FATAL 

Definition at line 88 of file cpp.h.

00088 { WARNING, ERROR, FATAL };

enum kwtype
 

Enumeration values:
KIF 
KIFDEF 
KIFNDEF 
KELIF 
KELSE 
KENDIF 
KINCLUDE 
KDEFINE 
KUNDEF 
KLINE 
KERROR 
KPRAGMA 
KDEFINED 
KLINENO 
KFILE 
KDATE 
KTIME 
KSTDC 
KEVAL 

Definition at line 26 of file cpp.h.

00026             { KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KDEFINE,
00027         KUNDEF, KLINE, KERROR, KPRAGMA, KDEFINED,
00028         KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL };

enum toktype
 

Enumeration values:
END 
UNCLASS 
NAME 
NUMBER 
STRING 
CCON 
NL 
WS 
DSHARP 
EQ 
NEQ 
LEQ 
GEQ 
LSH 
RSH 
LAND 
LOR 
PPLUS 
MMINUS 
ARROW 
SBRA 
SKET 
LP 
RP 
DOT 
AND 
STAR 
PLUS 
MINUS 
TILDE 
NOT 
SLASH 
PCT 
LT 
GT 
CIRC 
OR 
QUEST 
COLON 
ASGN 
COMMA 
SHARP 
SEMIC 
CBRA 
CKET 
ASPLUS 
ASMINUS 
ASSTAR 
ASSLASH 
ASPCT 
ASCIRC 
ASLSH 
ASRSH 
ASOR 
ASAND 
ELLIPS 
DSHARP1 
NAME1 
DEFINED 
UMINUS 

Definition at line 17 of file cpp.h.

00017              { END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
00018         EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,
00019         ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS,
00020         TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST,
00021         COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET,
00022         ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH,
00023         ASRSH, ASOR, ASAND, ELLIPS,
00024         DSHARP1, NAME1, DEFINED, UMINUS };


Function Documentation

void adjustrow Tokenrow ,
int 
 

Definition at line 195 of file tokens.c.

References tokenrow::bp, growtokenrow(), tokenrow::lp, tokenrow::max, memmove(), Tokenrow, and tokenrow::tp.

Referenced by gatherargs(), and insertrow().

00196 {
00197     int nby, size;
00198 
00199     if (nt==0)
00200         return;
00201     size = (trp->lp - trp->bp) + nt;
00202     while (size > trp->max)
00203         growtokenrow(trp);
00204     /* nby = sizeof(Token) * (trp->lp - trp->tp); */
00205     nby = (char *)trp->lp - (char *)trp->tp;
00206     if (nby)
00207         memmove(trp->tp+nt, trp->tp, nby);
00208     trp->lp += nt;
00209 }

Here is the call graph for this function:

void builtin Tokenrow ,
int 
 

Definition at line 457 of file macro.c.

References curtime, error(), ERROR, source::fd, source::filename, KDATE, KFILE, KLINENO, KTIME, token::len, source::line, source::next, op, outnum(), outp, s, Source, src, strncpy(), token::t, Token, Tokenrow, tokenrow::tp, token::type, uchar, and token::wslen.

Referenced by expandrow(), and PC_AddBuiltinDefines().

00458 {
00459     char *op;
00460     Token *tp;
00461     Source *s;
00462 
00463     tp = trp->tp;
00464     trp->tp++;
00465     /* need to find the real source */
00466     s = cursource;
00467     while (s && s->fd==-1)
00468         s = s->next;
00469     if (s==NULL)
00470         s = cursource;
00471     /* most are strings */
00472     tp->type = STRING;
00473     if (tp->wslen) {
00474         *outp++ = ' ';
00475         tp->wslen = 1;
00476     }
00477     op = outp;
00478     *op++ = '"';
00479     switch (biname) {
00480 
00481     case KLINENO:
00482         tp->type = NUMBER;
00483         op = outnum(op-1, s->line);
00484         break;
00485 
00486     case KFILE: {
00487         char *src = s->filename;
00488         while ((*op++ = *src++) != 0)
00489             if (src[-1] == '\\')
00490                 *op++ = '\\';
00491         op--;
00492         break;
00493         }
00494 
00495     case KDATE:
00496         strncpy(op, curtime+4, 7);
00497         strncpy(op+7, curtime+20, 4);
00498         op += 11;
00499         break;
00500 
00501     case KTIME:
00502         strncpy(op, curtime+11, 8);
00503         op += 8;
00504         break;
00505 
00506     default:
00507         error(ERROR, "cpp botch: unknown internal macro");
00508         return;
00509     }
00510     if (tp->type==STRING)
00511         *op++ = '"';
00512     tp->t = (uchar*)outp;
00513     tp->len = op - outp;
00514     outp = op;
00515 }

Here is the call graph for this function:

int checkhideset int  ,
Nlist
 

Definition at line 23 of file hideset.c.

References abort(), Hideset, hidesets, and Nlist.

Referenced by expandrow().

00024 {
00025     Hideset hsp;
00026 
00027     if (hs>=nhidesets)
00028         abort();
00029     for (hsp = hidesets[hs]; *hsp; hsp++) {
00030         if (*hsp == np)
00031             return 1;
00032     }
00033     return 0;
00034 }

Here is the call graph for this function:

int close int   ) 
 

Referenced by NET_IPSocket(), NET_Shutdown(), SNDDMA_GetDMAPos(), SNDDMA_Init(), Spk_Close(), and unsetsource().

int comparetokens Tokenrow ,
Tokenrow
 

Definition at line 107 of file tokens.c.

References token::len, tokenrow::lp, strncmp(), token::t, Token, Tokenrow, tokenrow::tp, token::type, and token::wslen.

Referenced by dodefine().

00108 {
00109     Token *tp1, *tp2;
00110 
00111     tp1 = tr1->tp;
00112     tp2 = tr2->tp;
00113     if (tr1->lp-tp1 != tr2->lp-tp2)
00114         return 1;
00115     for (; tp1<tr1->lp ; tp1++, tp2++) {
00116         if (tp1->type != tp2->type
00117          || (tp1->wslen==0) != (tp2->wslen==0)
00118          || tp1->len != tp2->len
00119          || strncmp((char*)tp1->t, (char*)tp2->t, tp1->len)!=0)
00120             return 1;
00121     }
00122     return 0;
00123 }

Here is the call graph for this function:

void control Tokenrow  ) 
 

Definition at line 90 of file cpp.c.

References atol(), tokenrow::bp, cursource, dodefine(), doinclude(), ERROR, error(), eval(), expandrow(), FATAL, source::filename, nlist::flag, source::ifdepth, ifdepth, ifsatisfied, KDEFINE, KDEFINED, KELIF, KELSE, KENDIF, KERROR, KEVAL, KIF, KIFDEF, KIFNDEF, KINCLUDE, KLINE, KPRAGMA, KUNDEF, token::len, source::line, lookup(), tokenrow::lp, NAME, newstring(), Nlist, np, NULL, NUMBER, setempty(), skipping, token::t, Token, Tokenrow, tokenrow::tp, token::type, nlist::val, and WARNING.

Referenced by AAS_ApplyFriction(), Controls_Update(), PM_Friction(), PM_NoclipMove(), and process().

00091 {
00092     Nlist *np;
00093     Token *tp;
00094 
00095     tp = trp->tp;
00096     if (tp->type!=NAME) {
00097         if (tp->type==NUMBER)
00098             goto kline;
00099         if (tp->type != NL)
00100             error(ERROR, "Unidentifiable control line");
00101         return;         /* else empty line */
00102     }
00103     if ((np = lookup(tp, 0))==NULL || (np->flag&ISKW)==0 && !skipping) {
00104         error(WARNING, "Unknown preprocessor control %t", tp);
00105         return;
00106     }
00107     if (skipping) {
00108         switch (np->val) {
00109         case KENDIF:
00110             if (--ifdepth<skipping)
00111                 skipping = 0;
00112             --cursource->ifdepth;
00113             setempty(trp);
00114             return;
00115 
00116         case KIFDEF:
00117         case KIFNDEF:
00118         case KIF:
00119             if (++ifdepth >= NIF)
00120                 error(FATAL, "#if too deeply nested");
00121             ++cursource->ifdepth;
00122             return;
00123 
00124         case KELIF:
00125         case KELSE:
00126             if (ifdepth<=skipping)
00127                 break;
00128             return;
00129 
00130         default:
00131             return;
00132         }
00133     }
00134     switch (np->val) {
00135     case KDEFINE:
00136         dodefine(trp);
00137         break;
00138 
00139     case KUNDEF:
00140         tp += 1;
00141         if (tp->type!=NAME || trp->lp - trp->bp != 4) {
00142             error(ERROR, "Syntax error in #undef");
00143             break;
00144         }
00145         if ((np = lookup(tp, 0)) != NULL)
00146             np->flag &= ~ISDEFINED;
00147         break;
00148 
00149     case KPRAGMA:
00150         return;
00151 
00152     case KIFDEF:
00153     case KIFNDEF:
00154     case KIF:
00155         if (++ifdepth >= NIF)
00156             error(FATAL, "#if too deeply nested");
00157         ++cursource->ifdepth;
00158         ifsatisfied[ifdepth] = 0;
00159         if (eval(trp, np->val))
00160             ifsatisfied[ifdepth] = 1;
00161         else
00162             skipping = ifdepth;
00163         break;
00164 
00165     case KELIF:
00166         if (ifdepth==0) {
00167             error(ERROR, "#elif with no #if");
00168             return;
00169         }
00170         if (ifsatisfied[ifdepth]==2)
00171             error(ERROR, "#elif after #else");
00172         if (eval(trp, np->val)) {
00173             if (ifsatisfied[ifdepth])
00174                 skipping = ifdepth;
00175             else {
00176                 skipping = 0;
00177                 ifsatisfied[ifdepth] = 1;
00178             }
00179         } else
00180             skipping = ifdepth;
00181         break;
00182 
00183     case KELSE:
00184         if (ifdepth==0 || cursource->ifdepth==0) {
00185             error(ERROR, "#else with no #if");
00186             return;
00187         }
00188         if (ifsatisfied[ifdepth]==2)
00189             error(ERROR, "#else after #else");
00190         if (trp->lp - trp->bp != 3)
00191             error(ERROR, "Syntax error in #else");
00192         skipping = ifsatisfied[ifdepth]? ifdepth: 0;
00193         ifsatisfied[ifdepth] = 2;
00194         break;
00195 
00196     case KENDIF:
00197         if (ifdepth==0 || cursource->ifdepth==0) {
00198             error(ERROR, "#endif with no #if");
00199             return;
00200         }
00201         --ifdepth;
00202         --cursource->ifdepth;
00203         if (trp->lp - trp->bp != 3)
00204             error(WARNING, "Syntax error in #endif");
00205         break;
00206 
00207     case KERROR:
00208         trp->tp = tp+1;
00209         error(WARNING, "#error directive: %r", trp);
00210         break;
00211 
00212     case KLINE:
00213         trp->tp = tp+1;
00214         expandrow(trp, "<line>");
00215         tp = trp->bp+2;
00216     kline:
00217         if (tp+1>=trp->lp || tp->type!=NUMBER || tp+3<trp->lp
00218          || (tp+3==trp->lp && ((tp+1)->type!=STRING)||*(tp+1)->t=='L')){
00219             error(ERROR, "Syntax error in #line");
00220             return;
00221         }
00222         cursource->line = atol((char*)tp->t)-1;
00223         if (cursource->line<0 || cursource->line>=32768)
00224             error(WARNING, "#line specifies number out of range");
00225         tp = tp+1;
00226         if (tp+1<trp->lp)
00227             cursource->filename=(char*)newstring(tp->t+1,tp->len-2,0);
00228         return;
00229 
00230     case KDEFINED:
00231         error(ERROR, "Bad syntax for control line");
00232         break;
00233 
00234     case KINCLUDE:
00235         doinclude(trp);
00236         trp->lp = trp->bp;
00237         return;
00238 
00239     case KEVAL:
00240         eval(trp, np->val);
00241         break;
00242 
00243     default:
00244         error(ERROR, "Preprocessor control `%t' not yet implemented", tp);
00245         break;
00246     }
00247     setempty(trp);
00248     return;
00249 }

Here is the call graph for this function:

Tokenrow* copytokenrow Tokenrow ,
Tokenrow
 

Definition at line 216 of file tokens.c.

References tokenrow::lp, maketokenrow(), movetokenrow(), rowlen, and Tokenrow.

Referenced by expand(), and substargs().

00217 {
00218     int len = rowlen(str);
00219 
00220     maketokenrow(len, dtr);
00221     movetokenrow(dtr, str);
00222     dtr->lp += len;
00223     return dtr;
00224 }

Here is the call graph for this function:

int creat char *  ,
int 
 

Referenced by setup().

int digit int   ) 
 

Definition at line 509 of file eval.c.

References i.

Referenced by tokval().

00510 {
00511     if ('0'<=i && i<='9')
00512         i -= '0';
00513     else if ('a'<=i && i<='f')
00514         i -= 'a'-10;
00515     else if ('A'<=i && i<='F')
00516         i -= 'A'-10;
00517     else
00518         i = -1;
00519     return i;
00520 }

void doadefine Tokenrow ,
int 
 

Definition at line 92 of file macro.c.

References tokenrow::bp, error(), FATAL, nlist::flag, lookup(), tokenrow::lp, Nlist, normtokenrow(), np, Token, Tokenrow, tokenrow::tp, type, token::type, uchar, and nlist::vp.

Referenced by setup().

00093 {
00094     Nlist *np;
00095     static Token onetoken[1] = {{ NUMBER, 0, 0, 0, 1, (uchar*)"1" }};
00096     static Tokenrow onetr = { onetoken, onetoken, onetoken+1, 1 };
00097 
00098     trp->tp = trp->bp;
00099     if (type=='U') {
00100         if (trp->lp-trp->tp != 2 || trp->tp->type!=NAME)
00101             goto syntax;
00102         if ((np = lookup(trp->tp, 0)) == NULL)
00103             return;
00104         np->flag &= ~ISDEFINED;
00105         return;
00106     }
00107     if (trp->tp >= trp->lp || trp->tp->type!=NAME)
00108         goto syntax;
00109     np = lookup(trp->tp, 1);
00110     np->flag |= ISDEFINED;
00111     trp->tp += 1;
00112     if (trp->tp >= trp->lp || trp->tp->type==END) {
00113         np->vp = &onetr;
00114         return;
00115     }
00116     if (trp->tp->type!=ASGN)
00117         goto syntax;
00118     trp->tp += 1;
00119     if ((trp->lp-1)->type == END)
00120         trp->lp -= 1;
00121     np->vp = normtokenrow(trp);
00122     return;
00123 syntax:
00124     error(FATAL, "Illegal -D or -U argument %r", trp);
00125 }

Here is the call graph for this function:

void doconcat Tokenrow  ) 
 

Definition at line 360 of file macro.c.

References tokenrow::bp, dofree(), error(), ERROR, gettokens(), insertrow(), token::len, tokenrow::lp, makespace(), maketokenrow(), setsource(), strncpy(), token::t, Token, Tokenrow, tokenrow::tp, token::type, unsetsource(), and WARNING.

Referenced by expand().

00361 {
00362     Token *ltp, *ntp;
00363     Tokenrow ntr;
00364     int len;
00365 
00366     for (trp->tp=trp->bp; trp->tp<trp->lp; trp->tp++) {
00367         if (trp->tp->type==DSHARP1)
00368             trp->tp->type = DSHARP;
00369         else if (trp->tp->type==DSHARP) {
00370             char tt[128];
00371             ltp = trp->tp-1;
00372             ntp = trp->tp+1;
00373             if (ltp<trp->bp || ntp>=trp->lp) {
00374                 error(ERROR, "## occurs at border of replacement");
00375                 continue;
00376             }
00377             len = ltp->len + ntp->len;
00378             strncpy((char*)tt, (char*)ltp->t, ltp->len);
00379             strncpy((char*)tt+ltp->len, (char*)ntp->t, ntp->len);
00380             tt[len] = '\0';
00381             setsource("<##>", -1, tt);
00382             maketokenrow(3, &ntr);
00383             gettokens(&ntr, 1);
00384             unsetsource();
00385             if (ntr.lp-ntr.bp!=2 || ntr.bp->type==UNCLASS)
00386                 error(WARNING, "Bad token %r produced by ##", &ntr);
00387             ntr.lp = ntr.bp+1;
00388             trp->tp = ltp;
00389             makespace(&ntr);
00390             insertrow(trp, (ntp-ltp)+1, &ntr);
00391             dofree(ntr.bp);
00392             trp->tp--;
00393         }
00394     }
00395 }

Here is the call graph for this function:

void dodefine Tokenrow  ) 
 

Definition at line 10 of file macro.c.

References nlist::ap, tokenrow::bp, comparetokens(), dofree(), err(), error(), ERROR, nlist::flag, growtokenrow(), token::len, lookup(), tokenrow::lp, LP, maketokenrow(), tokenrow::max, Nlist, normtokenrow(), np, strncmp(), token::t, Token, Tokenrow, tokenrow::tp, token::type, nlist::vp, and token::wslen.

Referenced by control().

00011 {
00012     Token *tp;
00013     Nlist *np;
00014     Tokenrow *def, *args;
00015 
00016     tp = trp->tp+1;
00017     if (tp>=trp->lp || tp->type!=NAME) {
00018         error(ERROR, "#defined token is not a name");
00019         return;
00020     }
00021     np = lookup(tp, 1);
00022     if (np->flag&ISUNCHANGE) {
00023         error(ERROR, "#defined token %t can't be redefined", tp);
00024         return;
00025     }
00026     /* collect arguments */
00027     tp += 1;
00028     args = NULL;
00029     if (tp<trp->lp && tp->type==LP && tp->wslen==0) {
00030         /* macro with args */
00031         int narg = 0;
00032         tp += 1;
00033         args = new(Tokenrow);
00034         maketokenrow(2, args);
00035         if (tp->type!=RP) {
00036             int err = 0;
00037             for (;;) {
00038                 Token *atp;
00039                 if (tp->type!=NAME) {
00040                     err++;
00041                     break;
00042                 }
00043                 if (narg>=args->max)
00044                     growtokenrow(args);
00045                 for (atp=args->bp; atp<args->lp; atp++)
00046                     if (atp->len==tp->len
00047                      && strncmp((char*)atp->t, (char*)tp->t, tp->len)==0)
00048                         error(ERROR, "Duplicate macro argument");
00049                 *args->lp++ = *tp;
00050                 narg++;
00051                 tp += 1;
00052                 if (tp->type==RP)
00053                     break;
00054                 if (tp->type!=COMMA) {
00055                     err++;
00056                     break;
00057                 }
00058                 tp += 1;
00059             }
00060             if (err) {
00061                 error(ERROR, "Syntax error in macro parameters");
00062                 return;
00063             }
00064         }
00065         tp += 1;
00066     }
00067     trp->tp = tp;
00068     if (((trp->lp)-1)->type==NL)
00069         trp->lp -= 1;
00070     def = normtokenrow(trp);
00071     if (np->flag&ISDEFINED) {
00072         if (comparetokens(def, np->vp)
00073          || (np->ap==NULL) != (args==NULL)
00074          || np->ap && comparetokens(args, np->ap))
00075             error(ERROR, "Macro redefinition of %t", trp->bp+2);
00076     }
00077     if (args) {
00078         Tokenrow *tap;
00079         tap = normtokenrow(args);
00080         dofree(args->bp);
00081         args = tap;
00082     }
00083     np->ap = args;
00084     np->vp = def;
00085     np->flag |= ISDEFINED;
00086 }

Here is the call graph for this function:

void dofree void *   ) 
 

Definition at line 262 of file cpp.c.

References free(), and p.

Referenced by doconcat(), dodefine(), expand(), substargs(), and unsetsource().

00263 {
00264     free(p);
00265 }

Here is the call graph for this function:

void doif Tokenrow ,
enum  kwtype
 

void doinclude Tokenrow  ) 
 

Definition at line 10 of file include.c.

References includelist::always, tokenrow::bp, includelist::deleted, error(), ERROR, expandrow(), FATAL, includelist::file, genline(), i, incdepth, Includelist, includelist, token::len, tokenrow::lp, Mflag, newstring(), NINCLUDE, NULL, objname, open(), setsource(), strcat(), strcpy(), STRING, strlen(), strncpy(), token::t, Tokenrow, tokenrow::tp, token::type, uchar, and write().

Referenced by control().

00011 {
00012     char fname[256], iname[256];
00013     Includelist *ip;
00014     int angled, len, fd, i;
00015 
00016     trp->tp += 1;
00017     if (trp->tp>=trp->lp)
00018         goto syntax;
00019     if (trp->tp->type!=STRING && trp->tp->type!=LT) {
00020         len = trp->tp - trp->bp;
00021         expandrow(trp, "<include>");
00022         trp->tp = trp->bp+len;
00023     }
00024     if (trp->tp->type==STRING) {
00025         len = trp->tp->len-2;
00026         if (len > sizeof(fname) - 1)
00027             len = sizeof(fname) - 1;
00028         strncpy(fname, (char*)trp->tp->t+1, len);
00029         angled = 0;
00030     } else if (trp->tp->type==LT) {
00031         len = 0;
00032         trp->tp++;
00033         while (trp->tp->type!=GT) {
00034             if (trp->tp>trp->lp || len+trp->tp->len+2 >= sizeof(fname))
00035                 goto syntax;
00036             strncpy(fname+len, (char*)trp->tp->t, trp->tp->len);
00037             len += trp->tp->len;
00038             trp->tp++;
00039         }
00040         angled = 1;
00041     } else
00042         goto syntax;
00043     trp->tp += 2;
00044     if (trp->tp < trp->lp || len==0)
00045         goto syntax;
00046     fname[len] = '\0';
00047     if (fname[0]=='/') {
00048         fd = open(fname, 0);
00049         strcpy(iname, fname);
00050     } else for (fd = -1,i=NINCLUDE-1; i>=0; i--) {
00051         ip = &includelist[i];
00052         if (ip->file==NULL || ip->deleted || (angled && ip->always==0))
00053             continue;
00054         if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname))
00055             continue;
00056         strcpy(iname, ip->file);
00057         strcat(iname, "/");
00058         strcat(iname, fname);
00059         if ((fd = open(iname, 0)) >= 0)
00060             break;
00061     }
00062     if ( Mflag>1 || !angled&&Mflag==1 ) {
00063         write(1,objname,strlen(objname));
00064         write(1,iname,strlen(iname));
00065         write(1,"\n",1);
00066     }
00067     if (fd >= 0) {
00068         if (++incdepth > 10)
00069             error(FATAL, "#include too deeply nested");
00070         setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL);
00071         genline();
00072     } else {
00073         trp->tp = trp->bp+2;
00074         error(ERROR, "Could not find include file %r", trp);
00075     }
00076     return;
00077 syntax:
00078     error(ERROR, "Syntax error in #include");
00079     return;
00080 }

Here is the call graph for this function:

void* domalloc int   ) 
 

Definition at line 252 of file cpp.c.

References error(), FATAL, malloc(), and p.

Referenced by iniths(), maketokenrow(), newhideset(), newstring(), setobjname(), and setsource().

00253 {
00254     void *p = malloc(size);
00255 
00256     if (p==NULL)
00257         error(FATAL, "Out of memory from malloc");
00258     return p;
00259 }

Here is the call graph for this function:

int dup2 int  ,
int 
 

Referenced by setup().

void error enum  errtype,
char *  ,
  ...
 

Definition at line 268 of file cpp.c.

References cp, exit(), fflush(), source::filename, fprintf(), fputc(), i, token::len, source::line, tokenrow::lp, nerrs, source::next, s, Source, stderr, string(), token::t, Token, Tokenrow, tokenrow::tp, type, token::type, va_arg, va_end, va_list, va_start, and token::wslen.

00269 {
00270     va_list ap;
00271     char *cp, *ep;
00272     Token *tp;
00273     Tokenrow *trp;
00274     Source *s;
00275     int i;
00276 
00277     fprintf(stderr, "cpp: ");
00278     for (s=cursource; s; s=s->next)
00279         if (*s->filename)
00280             fprintf(stderr, "%s:%d ", s->filename, s->line);
00281     va_start(ap, string);
00282     for (ep=string; *ep; ep++) {
00283         if (*ep=='%') {
00284             switch (*++ep) {
00285 
00286             case 's':
00287                 cp = va_arg(ap, char *);
00288                 fprintf(stderr, "%s", cp);
00289                 break;
00290             case 'd':
00291                 i = va_arg(ap, int);
00292                 fprintf(stderr, "%d", i);
00293                 break;
00294             case 't':
00295                 tp = va_arg(ap, Token *);
00296                 fprintf(stderr, "%.*s", tp->len, tp->t);
00297                 break;
00298 
00299             case 'r':
00300                 trp = va_arg(ap, Tokenrow *);
00301                 for (tp=trp->tp; tp<trp->lp&&tp->type!=NL; tp++) {
00302                     if (tp>trp->tp && tp->wslen)
00303                         fputc(' ', stderr);
00304                     fprintf(stderr, "%.*s", tp->len, tp->t);
00305                 }
00306                 break;
00307 
00308             default:
00309                 fputc(*ep, stderr);
00310                 break;
00311             }
00312         } else
00313             fputc(*ep, stderr);
00314     }
00315     va_end(ap);
00316     fputc('\n', stderr);
00317     if (type==FATAL)
00318         exit(1);
00319     if (type!=WARNING)
00320         nerrs = 1;
00321     fflush(stderr);
00322 }

Here is the call graph for this function:

long eval Tokenrow ,
int 
 

Definition at line 102 of file eval.c.

References AND, tokenrow::bp, CCON, CIRC, COLON, COMMA, DEFINED, END, EQ, error(), ERROR, evalop(), expandrow(), nlist::flag, GEQ, GT, ISDEFINED, KIFDEF, kwdefined, LAND, LEQ, lookup(), LOR, tokenrow::lp, LP, LSH, LT, MINUS, NAME, NAME1, NEQ, NL, Nlist, NOT, np, NUMBER, op, OR, PCT, PLUS, priority, QUEST, rand(), RP, RSH, SLASH, STAR, STRING, TILDE, Token, Tokenrow, tokval(), tokenrow::tp, token::type, value::type, nlist::val, value::val, vals, vp, and WS.

Referenced by control().

00103 {
00104     Token *tp;
00105     Nlist *np;
00106     int ntok, rand;
00107 
00108     trp->tp++;
00109     if (kw==KIFDEF || kw==KIFNDEF) {
00110         if (trp->lp - trp->bp != 4 || trp->tp->type!=NAME) {
00111             error(ERROR, "Syntax error in #ifdef/#ifndef");
00112             return 0;
00113         }
00114         np = lookup(trp->tp, 0);
00115         return (kw==KIFDEF) == (np && np->flag&(ISDEFINED|ISMAC));
00116     }
00117     ntok = trp->tp - trp->bp;
00118     kwdefined->val = KDEFINED;  /* activate special meaning of defined */
00119     expandrow(trp, "<if>");
00120     kwdefined->val = NAME;
00121     vp = vals;
00122     op = ops;
00123     *op++ = END;
00124     for (rand=0, tp = trp->bp+ntok; tp < trp->lp; tp++) {
00125         switch(tp->type) {
00126         case WS:
00127         case NL:
00128             continue;
00129 
00130         /* nilary */
00131         case NAME:
00132         case NAME1:
00133         case NUMBER:
00134         case CCON:
00135         case STRING:
00136             if (rand)
00137                 goto syntax;
00138             *vp++ = tokval(tp);
00139             rand = 1;
00140             continue;
00141 
00142         /* unary */
00143         case DEFINED:
00144         case TILDE:
00145         case NOT:
00146             if (rand)
00147                 goto syntax;
00148             *op++ = tp->type;
00149             continue;
00150 
00151         /* unary-binary */
00152         case PLUS: case MINUS: case STAR: case AND:
00153             if (rand==0) {
00154                 if (tp->type==MINUS)
00155                     *op++ = UMINUS;
00156                 if (tp->type==STAR || tp->type==AND) {
00157                     error(ERROR, "Illegal operator * or & in #if/#elsif");
00158                     return 0;
00159                 }
00160                 continue;
00161             }
00162             /* flow through */
00163 
00164         /* plain binary */
00165         case EQ: case NEQ: case LEQ: case GEQ: case LSH: case RSH:
00166         case LAND: case LOR: case SLASH: case PCT:
00167         case LT: case GT: case CIRC: case OR: case QUEST:
00168         case COLON: case COMMA:
00169             if (rand==0)
00170                 goto syntax;
00171             if (evalop(priority[tp->type])!=0)
00172                 return 0;
00173             *op++ = tp->type;
00174             rand = 0;
00175             continue;
00176 
00177         case LP:
00178             if (rand)
00179                 goto syntax;
00180             *op++ = LP;
00181             continue;
00182 
00183         case RP:
00184             if (!rand)
00185                 goto syntax;
00186             if (evalop(priority[RP])!=0)
00187                 return 0;
00188             if (op<=ops || op[-1]!=LP) {
00189                 goto syntax;
00190             }
00191             op--;
00192             continue;
00193 
00194         default:
00195             error(ERROR,"Bad operator (%t) in #if/#elsif", tp);
00196             return 0;
00197         }
00198     }
00199     if (rand==0)
00200         goto syntax;
00201     if (evalop(priority[END])!=0)
00202         return 0;
00203     if (op!=&ops[1] || vp!=&vals[1]) {
00204         error(ERROR, "Botch in #if/#elsif");
00205         return 0;
00206     }
00207     if (vals[0].type==UND)
00208         error(ERROR, "Undefined expression value");
00209     return vals[0].val;
00210 syntax:
00211     error(ERROR, "Syntax error in #if/#elsif");
00212     return 0;
00213 }

Here is the call graph for this function:

void expand Tokenrow ,
Nlist
 

Definition at line 178 of file macro.c.

References nlist::ap, tokenrow::bp, copytokenrow(), doconcat(), dofree(), error(), ERROR, gatherargs(), token::hideset, i, insertrow(), tokenrow::lp, NARG, newhideset(), Nlist, np, rowlen, substargs(), Token, Tokenrow, tokenrow::tp, token::type, unionhideset(), and nlist::vp.

Referenced by expandrow(), RemoveLinearMeshColumnsRows(), SubdivideMesh(), and SubdivideMeshQuads().

00179 {
00180     Tokenrow ntr;
00181     int ntokc, narg, i;
00182     Token *tp;
00183     Tokenrow *atr[NARG+1];
00184     int hs;
00185 
00186     copytokenrow(&ntr, np->vp);     /* copy macro value */
00187     if (np->ap==NULL)           /* parameterless */
00188         ntokc = 1;
00189     else {
00190         ntokc = gatherargs(trp, atr, &narg);
00191         if (narg<0) {           /* not actually a call (no '(') */
00192             trp->tp++;
00193             return;
00194         }
00195         if (narg != rowlen(np->ap)) {
00196             error(ERROR, "Disagreement in number of macro arguments");
00197             trp->tp->hideset = newhideset(trp->tp->hideset, np);
00198             trp->tp += ntokc;
00199             return;
00200         }
00201         substargs(np, &ntr, atr);   /* put args into replacement */
00202         for (i=0; i<narg; i++) {
00203             dofree(atr[i]->bp);
00204             dofree(atr[i]);
00205         }
00206     }
00207     doconcat(&ntr);             /* execute ## operators */
00208     hs = newhideset(trp->tp->hideset, np);
00209     for (tp=ntr.bp; tp<ntr.lp; tp++) {  /* distribute hidesets */
00210         if (tp->type==NAME) {
00211             if (tp->hideset==0)
00212                 tp->hideset = hs;
00213             else
00214                 tp->hideset = unionhideset(tp->hideset, hs);
00215         }
00216     }
00217     ntr.tp = ntr.bp;
00218     insertrow(trp, ntokc, &ntr);
00219     trp->tp -= rowlen(&ntr);
00220     dofree(ntr.bp);
00221     return;
00222 }   

Here is the call graph for this function:

void expandlex void   ) 
 

Definition at line 239 of file lex.c.

References bigfsm, C_ALPH, C_NUM, C_XX, fp, fsm, i, and j.

Referenced by main().

00240 {
00241     /*const*/ struct fsm *fp;
00242     int i, j, nstate;
00243 
00244     for (fp = fsm; fp->state>=0; fp++) {
00245         for (i=0; fp->ch[i]; i++) {
00246             nstate = fp->nextstate;
00247             if (nstate >= S_SELF)
00248                 nstate = ~nstate;
00249             switch (fp->ch[i]) {
00250 
00251             case C_XX:      /* random characters */
00252                 for (j=0; j<256; j++)
00253                     bigfsm[j][fp->state] = nstate;
00254                 continue;
00255             case C_ALPH:
00256                 for (j=0; j<=256; j++)
00257                     if ('a'<=j&&j<='z' || 'A'<=j&&j<='Z'
00258                       || j=='_')
00259                         bigfsm[j][fp->state] = nstate;
00260                 continue;
00261             case C_NUM:
00262                 for (j='0'; j<='9'; j++)
00263                     bigfsm[j][fp->state] = nstate;
00264                 continue;
00265             default:
00266                 bigfsm[fp->ch[i]][fp->state] = nstate;
00267             }
00268         }
00269     }
00270     /* install special cases for ? (trigraphs),  \ (splicing), runes, and EOB */
00271     for (i=0; i<MAXSTATE; i++) {
00272         for (j=0; j<0xFF; j++)
00273             if (j=='?' || j=='\\') {
00274                 if (bigfsm[j][i]>0)
00275                     bigfsm[j][i] = ~bigfsm[j][i];
00276                 bigfsm[j][i] &= ~QBSBIT;
00277             }
00278         bigfsm[EOB][i] = ~S_EOB;
00279         if (bigfsm[EOFC][i]>=0)
00280             bigfsm[EOFC][i] = ~S_EOF;
00281     }
00282 }

void expandrow Tokenrow ,
char * 
 

Definition at line 132 of file macro.c.

References builtin(), checkhideset(), error(), ERROR, expand(), nlist::flag, token::hideset, ISDEFINED, token::len, lookup(), tokenrow::lp, LP, NAME, Nlist, np, NULL, quicklook, setsource(), token::t, Token, Tokenrow, tokenrow::tp, token::type, unsetsource(), and nlist::val.

Referenced by control(), doinclude(), eval(), process(), and substargs().

00133 {
00134     Token *tp;
00135     Nlist *np;
00136 
00137     if (flag)
00138         setsource(flag, -1, "");
00139     for (tp = trp->tp; tp<trp->lp; ) {
00140         if (tp->type!=NAME
00141          || quicklook(tp->t[0], tp->len>1?tp->t[1]:0)==0
00142          || (np = lookup(tp, 0))==NULL
00143          || (np->flag&(ISDEFINED|ISMAC))==0
00144          || tp->hideset && checkhideset(tp->hideset, np)) {
00145             tp++;
00146             continue;
00147         }
00148         trp->tp = tp;
00149         if (np->val==KDEFINED) {
00150             tp->type = DEFINED;
00151             if ((tp+1)<trp->lp && (tp+1)->type==NAME)
00152                 (tp+1)->type = NAME1;
00153             else if ((tp+3)<trp->lp && (tp+1)->type==LP
00154              && (tp+2)->type==NAME && (tp+3)->type==RP)
00155                 (tp+2)->type = NAME1;
00156             else
00157                 error(ERROR, "Incorrect syntax for `defined'");
00158             tp++;
00159             continue;
00160         }
00161         if (np->flag&ISMAC)
00162             builtin(trp, np->val);
00163         else {
00164             expand(trp, np);
00165         }
00166         tp = trp->tp;
00167     }
00168     if (flag)
00169         unsetsource();
00170 }

Here is the call graph for this function:

int fillbuf Source  ) 
 

Definition at line 516 of file lex.c.

00517 {
00518     int n, nr;
00519 
00520     nr = INS/8;
00521     if ((char *)s->inl+nr > (char *)s->inb+INS)
00522         error(FATAL, "Input buffer overflow");
00523     if (s->fd<0 || (n=read(s->fd, (char *)s->inl, INS/8)) <= 0)
00524         n = 0;
00525     if ((*s->inp&0xff) == EOB) /* sentinel character appears in input */
00526         *s->inp = EOFC;
00527     s->inl += n;
00528     s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOB;
00529     if (n==0) {
00530         s->inl[0] = s->inl[1]= s->inl[2]= s->inl[3] = EOFC;
00531         return EOF;
00532     }
00533     return 0;
00534 }

void fixlex void   ) 
 

Definition at line 285 of file lex.c.

References bigfsm, and Cplusplus.

Referenced by main().

00286 {
00287     /* do C++ comments? */
00288     if (Cplusplus==0)
00289         bigfsm['/'][COM1] = bigfsm['x'][COM1];
00290 }

void flushout void   ) 
 

Definition at line 328 of file tokens.c.

References wbp, wbuf, and write().

Referenced by main(), peektokens(), and puttokens().

00329 {
00330     if (wbp>wbuf) {
00331         write(1, wbuf, wbp-wbuf);
00332         wbp = wbuf;
00333     }
00334 }

Here is the call graph for this function:

int foldline Source  ) 
 

Definition at line 503 of file lex.c.

References fillbuf(), source::inl, source::inp, memmove(), s, and Source.

Referenced by gettokens().

00504 {
00505     while (s->inp+1 >= s->inl && fillbuf(s)!=EOF)
00506         ;
00507     if (s->inp[1] == '\n') {
00508         memmove(s->inp, s->inp+2, s->inl-s->inp+3);
00509         s->inl -= 2;
00510         return 1;
00511     }
00512     return 0;
00513 }

Here is the call graph for this function:

int gatherargs Tokenrow ,
Tokenrow **  ,
int * 
 

Definition at line 230 of file macro.c.

References adjustrow(), tokenrow::bp, COMMA, error(), ERROR, FATAL, gettokens(), tokenrow::lp, makespace(), NARG, normtokenrow(), Token, Tokenrow, tokenrow::tp, and token::type.

Referenced by expand().

00231 {
00232     int parens = 1;
00233     int ntok = 0;
00234     Token *bp, *lp;
00235     Tokenrow ttr;
00236     int ntokp;
00237     int needspace;
00238 
00239     *narg = -1;         /* means that there is no macro call */
00240     /* look for the ( */
00241     for (;;) {
00242         trp->tp++;
00243         ntok++;
00244         if (trp->tp >= trp->lp) {
00245             gettokens(trp, 0);
00246             if ((trp->lp-1)->type==END) {
00247                 trp->lp -= 1;
00248                 trp->tp -= ntok;
00249                 return ntok;
00250             }
00251         }
00252         if (trp->tp->type==LP)
00253             break;
00254         if (trp->tp->type!=NL)
00255             return ntok;
00256     }
00257     *narg = 0;
00258     ntok++;
00259     ntokp = ntok;
00260     trp->tp++;
00261     /* search for the terminating ), possibly extending the row */
00262     needspace = 0;
00263     while (parens>0) {
00264         if (trp->tp >= trp->lp)
00265             gettokens(trp, 0);
00266         if (needspace) {
00267             needspace = 0;
00268             makespace(trp);
00269         }
00270         if (trp->tp->type==END) {
00271             trp->lp -= 1;
00272             trp->tp -= ntok;
00273             error(ERROR, "EOF in macro arglist");
00274             return ntok;
00275         }
00276         if (trp->tp->type==NL) {
00277             trp->tp += 1;
00278             adjustrow(trp, -1);
00279             trp->tp -= 1;
00280             makespace(trp);
00281             needspace = 1;
00282             continue;
00283         }
00284         if (trp->tp->type==LP)
00285             parens++;
00286         else if (trp->tp->type==RP)
00287             parens--;
00288         trp->tp++;
00289         ntok++;
00290     }
00291     trp->tp -= ntok;
00292     /* Now trp->tp won't move underneath us */
00293     lp = bp = trp->tp+ntokp;
00294     for (; parens>=0; lp++) {
00295         if (lp->type == LP) {
00296             parens++;
00297             continue;
00298         }
00299         if (lp->type==RP)
00300             parens--;
00301         if (lp->type==DSHARP)
00302             lp->type = DSHARP1; /* ## not special in arg */
00303         if (lp->type==COMMA && parens==0 || parens<0 && (lp-1)->type!=LP) {
00304             if (*narg>=NARG-1)
00305                 error(FATAL, "Sorry, too many macro arguments");
00306             ttr.bp = ttr.tp = bp;
00307             ttr.lp = lp;
00308             atr[(*narg)++] = normtokenrow(&ttr);
00309             bp = lp+1;
00310         }
00311     }
00312     return ntok;
00313 }

Here is the call graph for this function:

void genline void   ) 
 

Definition at line 86 of file include.c.

References cursource, source::filename, token::len, source::line, outnum(), outp, p, puttokens(), strcpy(), strlen(), token::t, Token, Tokenrow, tr, uchar, UNCLASS, and wd.

Referenced by doinclude(), main(), and process().

00087 {
00088     static Token ta = { UNCLASS };
00089     static Tokenrow tr = { &ta, &ta, &ta+1, 1 };
00090     uchar *p;
00091 
00092     ta.t = p = (uchar*)outp;
00093     strcpy((char*)p, "#line ");
00094     p += sizeof("#line ")-1;
00095     p = (uchar*)outnum((char*)p, cursource->line);
00096     *p++ = ' '; *p++ = '"';
00097     if (cursource->filename[0]!='/' && wd[0]) {
00098         strcpy((char*)p, wd);
00099         p += strlen(wd);
00100         *p++ = '/';
00101     }
00102     strcpy((char*)p, cursource->filename);
00103     p += strlen((char*)p);
00104     *p++ = '"'; *p++ = '\n';
00105     ta.len = (char*)p-outp;
00106     outp = (char*)p;
00107     tr.tp = tr.bp;
00108     puttokens(&tr);
00109 }

Here is the call graph for this function:

int gettokens Tokenrow ,
int 
 

Definition at line 300 of file lex.c.

References bigfsm, tokenrow::bp, c, cursource, error(), ERROR, FATAL, source::fd, fillbuf(), token::flag, foldline(), GETACT, growtokenrow(), token::hideset, source::inb, source::inl, source::inp, INS, token::len, source::lineinc, tokenrow::lp, tokenrow::max, memmove(), NL, outbuf, quicklook, s, S_COMMENT, S_COMNL, S_EOB, S_EOF, S_EOFCOM, S_EOFSTR, S_NAME, S_NL, S_SELF, S_SELFB, S_STNL, S_WS, Source, state, token::t, Token, Tokenrow, trigraph(), token::type, uchar, WARNING, and token::wslen.

Referenced by doconcat(), gatherargs(), process(), and setup().

00301 {
00302     register int c, state, oldstate;
00303     register uchar *ip;
00304     register Token *tp, *maxp;
00305     int runelen;
00306     Source *s = cursource;
00307     int nmac = 0;
00308     extern char outbuf[];
00309 
00310     tp = trp->lp;
00311     ip = s->inp;
00312     if (reset) {
00313         s->lineinc = 0;
00314         if (ip>=s->inl) {       /* nothing in buffer */
00315             s->inl = s->inb;
00316             fillbuf(s);
00317             ip = s->inp = s->inb;
00318         } else if (ip >= s->inb+(3*INS/4)) {
00319             memmove(s->inb, ip, 4+s->inl-ip);
00320             s->inl = s->inb+(s->inl-ip);
00321             ip = s->inp = s->inb;
00322         }
00323     }
00324     maxp = &trp->bp[trp->max];
00325     runelen = 1;
00326     for (;;) {
00327        continue2:
00328         if (tp>=maxp) {
00329             trp->lp = tp;
00330             tp = growtokenrow(trp);
00331             maxp = &trp->bp[trp->max];
00332         }
00333         tp->type = UNCLASS;
00334         tp->hideset = 0;
00335         tp->t = ip;
00336         tp->wslen = 0;
00337         tp->flag = 0;
00338         state = START;
00339         for (;;) {
00340             oldstate = state;
00341             c = *ip;
00342             if ((state = bigfsm[c][state]) >= 0) {
00343                 ip += runelen;
00344                 runelen = 1;
00345                 continue;
00346             }
00347             state = ~state;
00348         reswitch:
00349             switch (state&0177) {
00350             case S_SELF:
00351                 ip += runelen;
00352                 runelen = 1;
00353             case S_SELFB:
00354                 tp->type = GETACT(state);
00355                 tp->len = ip - tp->t;
00356                 tp++;
00357                 goto continue2;
00358 
00359             case S_NAME:    /* like S_SELFB but with nmac check */
00360                 tp->type = NAME;
00361                 tp->len = ip - tp->t;
00362                 nmac |= quicklook(tp->t[0], tp->len>1?tp->t[1]:0);
00363                 tp++;
00364                 goto continue2;
00365 
00366             case S_WS:
00367                 tp->wslen = ip - tp->t;
00368                 tp->t = ip;
00369                 state = START;
00370                 continue;
00371 
00372             default:
00373                 if ((state&QBSBIT)==0) {
00374                     ip += runelen;
00375                     runelen = 1;
00376                     continue;
00377                 }
00378                 state &= ~QBSBIT;
00379                 s->inp = ip;
00380                 if (c=='?') {   /* check trigraph */
00381                     if (trigraph(s)) {
00382                         state = oldstate;
00383                         continue;
00384                     }
00385                     goto reswitch;
00386                 }
00387                 if (c=='\\') { /* line-folding */
00388                     if (foldline(s)) {
00389                         s->lineinc++;
00390                         state = oldstate;
00391                         continue;
00392                     }
00393                     goto reswitch;
00394                 }
00395                 error(WARNING, "Lexical botch in cpp");
00396                 ip += runelen;
00397                 runelen = 1;
00398                 continue;
00399 
00400             case S_EOB:
00401                 s->inp = ip;
00402                 fillbuf(cursource);
00403                 state = oldstate;
00404                 continue;
00405 
00406             case S_EOF:
00407                 tp->type = END;
00408                 tp->len = 0;
00409                 s->inp = ip;
00410                 if (tp!=trp->bp && (tp-1)->type!=NL && cursource->fd!=-1)
00411                     error(WARNING,"No newline at end of file");
00412                 trp->lp = tp+1;
00413                 return nmac;
00414 
00415             case S_STNL:
00416                 error(ERROR, "Unterminated string or char const");
00417             case S_NL:
00418                 tp->t = ip;
00419                 tp->type = NL;
00420                 tp->len = 1;
00421                 tp->wslen = 0;
00422                 s->lineinc++;
00423                 s->inp = ip+1;
00424                 trp->lp = tp+1;
00425                 return nmac;
00426 
00427             case S_EOFSTR:
00428                 error(FATAL, "EOF in string or char constant");
00429                 break;
00430 
00431             case S_COMNL:
00432                 s->lineinc++;
00433                 state = COM2;
00434                 ip += runelen;
00435                 runelen = 1;
00436                 if (ip >= s->inb+(7*INS/8)) { /* very long comment */
00437                     memmove(tp->t, ip, 4+s->inl-ip);
00438                     s->inl -= ip-tp->t;
00439                     ip = tp->t+1;
00440                 }
00441                 continue;
00442 
00443             case S_EOFCOM:
00444                 error(WARNING, "EOF inside comment");
00445                 --ip;
00446             case S_COMMENT:
00447                 ++ip;
00448                 tp->t = ip;
00449                 tp->t[-1] = ' ';
00450                 tp->wslen = 1;
00451                 state = START;
00452                 continue;
00453             }
00454             break;
00455         }
00456         ip += runelen;
00457         runelen = 1;
00458         tp->len = ip - tp->t;
00459         tp++;
00460     }
00461 }

Here is the call graph for this function:

Token* growtokenrow Tokenrow  ) 
 

Definition at line 89 of file tokens.c.

References tokenrow::bp, error(), FATAL, tokenrow::lp, tokenrow::max, realloc(), Token, Tokenrow, and tokenrow::tp.

Referenced by adjustrow(), dodefine(), and gettokens().

00090 {
00091     int ncur = trp->tp - trp->bp;
00092     int nlast = trp->lp - trp->bp;
00093 
00094     trp->max = 3*trp->max/2 + 1;
00095     trp->bp = (Token *)realloc(trp->bp, trp->max*sizeof(Token));
00096     if (trp->bp == NULL)
00097         error(FATAL, "Out of memory from realloc");
00098     trp->lp = &trp->bp[nlast];
00099     trp->tp = &trp->bp[ncur];
00100     return trp->lp;
00101 }

Here is the call graph for this function:

void iniths void   ) 
 

Definition at line 95 of file hideset.c.

References domalloc(), Hideset, hidesets, maxhidesets, and nhidesets.

Referenced by main().

00096 {
00097     hidesets = (Hideset *)domalloc(maxhidesets*sizeof(Hideset *));
00098     hidesets[0] = (Hideset)domalloc(sizeof(Hideset));
00099     *hidesets[0] = NULL;
00100     nhidesets++;
00101 }

Here is the call graph for this function:

void insertrow Tokenrow ,
int  ,
Tokenrow
 

Definition at line 131 of file tokens.c.

References adjustrow(), makespace(), movetokenrow(), rowlen, Tokenrow, and tokenrow::tp.

Referenced by doconcat(), expand(), and substargs().

00132 {
00133     int nrtok = rowlen(str);
00134 
00135     dtr->tp += ntok;
00136     adjustrow(dtr, nrtok-ntok);
00137     dtr->tp -= ntok;
00138     movetokenrow(dtr, str);
00139     makespace(dtr);
00140     dtr->tp += nrtok;
00141     makespace(dtr);
00142 }

Here is the call graph for this function:

Nlist* lookup Token ,
int 
 

Definition at line 73 of file nlist.c.

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 }

int lookuparg Nlist ,
Token
 

Definition at line 403 of file macro.c.

References nlist::ap, tokenrow::bp, token::len, tokenrow::lp, NAME, Nlist, strncmp(), token::t, Token, and token::type.

Referenced by substargs().

00404 {
00405     Token *ap;
00406 
00407     if (tp->type!=NAME || mac->ap==NULL)
00408         return -1;
00409     for (ap=mac->ap->bp; ap<mac->ap->lp; ap++) {
00410         if (ap->len==tp->len && strncmp((char*)ap->t,(char*)tp->t,ap->len)==0)
00411             return ap - mac->ap->bp;
00412     }
00413     return -1;
00414 }

Here is the call graph for this function:

void makespace Tokenrow  ) 
 

Definition at line 148 of file tokens.c.

References tokenrow::bp, token::flag, token::len, tokenrow::lp, newstring(), token::t, Token, Tokenrow, tokenrow::tp, token::type, uchar, token::wslen, wstab, and XPWS.

Referenced by doconcat(), gatherargs(), and insertrow().

00149 {
00150     uchar *tt;
00151     Token *tp = trp->tp;
00152 
00153     if (tp >= trp->lp)
00154         return;
00155     if (tp->wslen) {
00156         if (tp->flag&XPWS
00157          && (wstab[tp->type] || trp->tp>trp->bp && wstab[(tp-1)->type])) {
00158             tp->wslen = 0;
00159             return;
00160         }
00161         tp->t[-1] = ' ';
00162         return;
00163     }
00164     if (wstab[tp->type] || trp->tp>trp->bp && wstab[(tp-1)->type])
00165         return;
00166     tt = newstring(tp->t, tp->len, 1);
00167     *tt++ = ' ';
00168     tp->t = tt;
00169     tp->wslen = 1;
00170     tp->flag |= XPWS;
00171 }

Here is the call graph for this function:

void maketokenrow int  ,
Tokenrow
 

Definition at line 77 of file tokens.c.

References tokenrow::bp, domalloc(), tokenrow::lp, tokenrow::max, Token, Tokenrow, and tokenrow::tp.

Referenced by copytokenrow(), doconcat(), dodefine(), main(), normtokenrow(), and setup().

00078 {
00079     trp->max = size;
00080     if (size>0)
00081         trp->bp = (Token *)domalloc(size*sizeof(Token));
00082     else
00083         trp->bp = NULL;
00084     trp->tp = trp->bp;
00085     trp->lp = trp->bp;
00086 }

Here is the call graph for this function:

void movetokenrow Tokenrow ,
Tokenrow
 

Definition at line 179 of file tokens.c.

References tokenrow::bp, tokenrow::lp, memmove(), Tokenrow, and tokenrow::tp.

Referenced by copytokenrow(), and insertrow().

00180 {
00181     int nby;
00182 
00183     /* nby = sizeof(Token) * (str->lp - str->bp); */
00184     nby = (char *)str->lp - (char *)str->bp;
00185     memmove(dtr->tp, str->bp, nby);
00186 }

Here is the call graph for this function:

int newhideset int  ,
Nlist
 

Definition at line 40 of file hideset.c.

References domalloc(), error(), FATAL, Hideset, hidesets, HSSIZ, i, inserths(), maxhidesets, memmove(), nhidesets, Nlist, np, and realloc().

Referenced by expand(), and unionhideset().

00041 {
00042     int i, len;
00043     Nlist *nhs[HSSIZ+3];
00044     Hideset hs1, hs2;
00045 
00046     len = inserths(nhs, hidesets[hs], np);
00047     for (i=0; i<nhidesets; i++) {
00048         for (hs1=nhs, hs2=hidesets[i]; *hs1==*hs2; hs1++, hs2++)
00049             if (*hs1 == NULL)
00050                 return i;
00051     }
00052     if (len>=HSSIZ)
00053         return hs;
00054     if (nhidesets >= maxhidesets) {
00055         maxhidesets = 3*maxhidesets/2+1;
00056         hidesets = (Hideset *)realloc(hidesets, (sizeof (Hideset *))*maxhidesets);
00057         if (hidesets == NULL)
00058             error(FATAL, "Out of memory from realloc");
00059     }
00060     hs1 = (Hideset)domalloc(len*sizeof(Hideset));
00061     memmove(hs1, nhs, len*sizeof(Hideset));
00062     hidesets[nhidesets] = hs1;
00063     return nhidesets++;
00064 }

Here is the call graph for this function:

uchar* newstring uchar ,
int  ,
int 
 

Definition at line 364 of file tokens.c.

References domalloc(), l, s, strncpy(), and uchar.

Referenced by control(), doinclude(), lookup(), makespace(), normtokenrow(), setup(), and stringify().

00365 {
00366     uchar *ns = (uchar *)domalloc(l+o+1);
00367 
00368     ns[l+o] = '\0';
00369     return (uchar*)strncpy((char*)ns+o, (char*)s, l) - o;
00370 }

Here is the call graph for this function:

Tokenrow* normtokenrow Tokenrow  ) 
 

Definition at line 232 of file tokens.c.

References tokenrow::bp, token::len, tokenrow::lp, maketokenrow(), newstring(), token::t, Token, Tokenrow, tokenrow::tp, and token::wslen.

Referenced by doadefine(), dodefine(), and gatherargs().

00233 {
00234     Token *tp;
00235     Tokenrow *ntrp = new(Tokenrow);
00236     int len;
00237 
00238     len = trp->lp - trp->tp;
00239     if (len<=0)
00240         len = 1;
00241     maketokenrow(len, ntrp);
00242     for (tp=trp->tp; tp < trp->lp; tp++) {
00243         *ntrp->lp = *tp;
00244         if (tp->len) {
00245             ntrp->lp->t = newstring(tp->t, tp->len, 1);
00246             *ntrp->lp->t++ = ' ';
00247             if (tp->wslen)
00248                 ntrp->lp->wslen = 1;
00249         }
00250         ntrp->lp++;
00251     }
00252     if (ntrp->lp > ntrp->bp)
00253         ntrp->bp->wslen = 0;
00254     return ntrp;
00255 }

Here is the call graph for this function:

int open char *  ,
int 
 

Referenced by doinclude(), IN_StartupJoystick(), setup(), SNDDMA_Init(), Spk_Open(), SV_AdjustAreaPortalState(), and trap_AdjustAreaPortalState().

char* outnum char *  ,
int 
 

Definition at line 351 of file tokens.c.

References n, and p.

Referenced by builtin(), and genline().

00352 {
00353     if (n>=10)
00354         p = outnum(p, n/10);
00355     *p++ = n%10 + '0';
00356     return p;
00357 }

void peektokens Tokenrow ,
char * 
 

Definition at line 261 of file tokens.c.

References tokenrow::bp, c, fflush(), flushout(), fprintf(), token::hideset, token::len, tokenrow::lp, prhideset(), stderr, token::t, Token, Tokenrow, tokenrow::tp, and token::type.

Referenced by puttokens().

00262 {
00263     Token *tp;
00264 
00265     tp = trp->tp;
00266     flushout();
00267     if (str)
00268         fprintf(stderr, "%s ", str);
00269     if (tp<trp->bp || tp>trp->lp)
00270         fprintf(stderr, "(tp offset %d) ", tp-trp->bp);
00271     for (tp=trp->bp; tp<trp->lp && tp<trp->bp+32; tp++) {
00272         if (tp->type!=NL) {
00273             int c = tp->t[tp->len];
00274             tp->t[tp->len] = 0;
00275             fprintf(stderr, "%s", tp->t);
00276             tp->t[tp->len] = c;
00277         }
00278         if (tp->type==NAME) {
00279             fprintf(stderr, tp==trp->tp?"{*":"{");
00280             prhideset(tp->hideset);
00281             fprintf(stderr, "} ");
00282         } else
00283             fprintf(stderr, tp==trp->tp?"{%x*} ":"{%x} ", tp->type);
00284     }
00285     fprintf(stderr, "\n");
00286     fflush(stderr);
00287 }

Here is the call graph for this function:

void prhideset int   ) 
 

Definition at line 104 of file hideset.c.

References fprintf(), Hideset, hidesets, np, and stderr.

Referenced by peektokens().

00105 {
00106     Hideset np;
00107 
00108     for (np = hidesets[hs]; *np; np++) {
00109         fprintf(stderr, (char*)(*np)->name, (*np)->len);
00110         fprintf(stderr, " ");
00111     }
00112 }

Here is the call graph for this function:

void process Tokenrow  ) 
 

Definition at line 47 of file cpp.c.

References tokenrow::bp, control(), cursource, ERROR, error(), expandrow(), genline(), gettokens(), source::ifdepth, incdepth, source::line, source::lineinc, tokenrow::lp, NULL, outp, puttokens(), setempty(), skipping, Tokenrow, tokenrow::tp, token::type, and unsetsource().

00048 {
00049     int anymacros = 0;
00050 
00051     for (;;) {
00052         if (trp->tp >= trp->lp) {
00053             trp->tp = trp->lp = trp->bp;
00054             outp = outbuf;
00055             anymacros |= gettokens(trp, 1);
00056             trp->tp = trp->bp;
00057         }
00058         if (trp->tp->type == END) {
00059             if (--incdepth>=0) {
00060                 if (cursource->ifdepth)
00061                     error(ERROR,
00062                      "Unterminated conditional in #include");
00063                 unsetsource();
00064                 cursource->line += cursource->lineinc;
00065                 trp->tp = trp->lp;
00066                 genline();
00067                 continue;
00068             }
00069             if (ifdepth)
00070                 error(ERROR, "Unterminated #if/#ifdef/#ifndef");
00071             break;
00072         }
00073         if (trp->tp->type==SHARP) {
00074             trp->tp += 1;
00075             control(trp);
00076         } else if (!skipping && anymacros)
00077             expandrow(trp, NULL);
00078         if (skipping)
00079             setempty(trp);
00080         puttokens(trp);
00081         anymacros = 0;
00082         cursource->line += cursource->lineinc;
00083         if (cursource->lineinc>1) {
00084             genline();
00085         }
00086     }
00087 }

Here is the call graph for this function:

void puttokens Tokenrow  ) 
 

Definition at line 290 of file tokens.c.

References tokenrow::bp, cursource, source::fd, flushout(), token::len, tokenrow::lp, memcpy(), OBS, p, peektokens(), token::t, Token, Tokenrow, tokenrow::tp, uchar, wbp, wbuf, write(), and token::wslen.

Referenced by genline(), and process().

00291 {
00292     Token *tp;
00293     int len;
00294     uchar *p;
00295 
00296     if (verbose)
00297         peektokens(trp, "");
00298     tp = trp->bp;
00299     for (; tp<trp->lp; tp++) {
00300         len = tp->len+tp->wslen;
00301         p = tp->t-tp->wslen;
00302         while (tp<trp->lp-1 && p+len == (tp+1)->t - (tp+1)->wslen) {
00303             tp++;
00304             len += tp->wslen+tp->len;
00305         }
00306         if (len>OBS/2) {        /* handle giant token */
00307             if (wbp > wbuf)
00308                 write(1, wbuf, wbp-wbuf);
00309             write(1, (char *)p, len);
00310             wbp = wbuf;
00311         } else {    
00312             memcpy(wbp, p, len);
00313             wbp += len;
00314         }
00315         if (wbp >= &wbuf[OBS]) {
00316             write(1, wbuf, OBS);
00317             if (wbp > &wbuf[OBS])
00318                 memcpy(wbuf, wbuf+OBS, wbp - &wbuf[OBS]);
00319             wbp -= OBS;
00320         }
00321     }
00322     trp->tp = tp;
00323     if (cursource->fd==0)
00324         flushout();
00325 }

Here is the call graph for this function:

int read int  ,
char *  ,
size_t 
 

Referenced by fillbuf(), FS_Read(), IN_JoyMove(), IN_StartupJoystick(), main(), Pause(), ReadQuakeFile(), Sys_ConsoleInput(), and tty_FlushIn().

void setempty Tokenrow  ) 
 

Definition at line 340 of file tokens.c.

References tokenrow::bp, tokenrow::lp, Tokenrow, and tokenrow::tp.

Referenced by control(), and process().

00341 {
00342     trp->tp = trp->bp;
00343     trp->lp = trp->bp+1;
00344     *trp->bp = nltoken;
00345 }

void setobjname char *   ) 
 

Definition at line 112 of file include.c.

References domalloc(), f, n, objname, strcpy(), and strlen().

Referenced by setup().

00113 {
00114     int n = strlen(f);
00115     objname = (char*)domalloc(n+5);
00116     strcpy(objname,f);
00117     if(objname[n-2]=='.'){
00118         strcpy(objname+n-1,"$O: ");
00119     }else{
00120         strcpy(objname+n,"$O: ");
00121     }
00122 }

Here is the call graph for this function:

Source* setsource char *  ,
int  ,
char * 
 

Definition at line 542 of file lex.c.

References cursource, domalloc(), source::fd, source::filename, source::ifdepth, source::inb, source::inl, source::inp, INS, source::line, source::lineinc, source::next, s, Source, strlen(), and strncpy().

Referenced by doconcat(), doinclude(), expandrow(), and setup().

00543 {
00544     Source *s = new(Source);
00545     int len;
00546 
00547     s->line = 1;
00548     s->lineinc = 0;
00549     s->fd = fd;
00550     s->filename = name;
00551     s->next = cursource;
00552     s->ifdepth = 0;
00553     cursource = s;
00554     /* slop at right for EOB */
00555     if (str) {
00556         len = strlen(str);
00557         s->inb = domalloc(len+4);
00558         s->inp = s->inb;
00559         strncpy((char *)s->inp, str, len);
00560     } else {
00561         s->inb = domalloc(INS+4);
00562         s->inp = s->inb;
00563         len = 0;
00564     }
00565     s->inl = s->inp+len;
00566     s->inl[0] = s->inl[1] = EOB;
00567     return s;
00568 }

Here is the call graph for this function:

void setup int  ,
char ** 
 

Definition at line 16 of file unix.c.

References argc, argv, c, Cplusplus, creat(), doadefine(), dup2(), error(), FATAL, fp, fprintf(), getopt(), gettokens(), i, maketokenrow(), Mflag, newstring(), NINCLUDE, NULL, open(), optarg, optind, rcsid, setobjname(), setsource(), setup_kwtab(), stderr, strlen(), strrchr(), Tokenrow, tr, uchar, unsetsource(), and verbose.

Referenced by main().

00017 {
00018     int c, fd, i;
00019     char *fp, *dp;
00020     Tokenrow tr;
00021     extern void setup_kwtab(void);
00022 
00023     setup_kwtab();
00024     while ((c = getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
00025         switch (c) {
00026         case 'N':
00027             for (i=0; i<NINCLUDE; i++)
00028                 if (includelist[i].always==1)
00029                     includelist[i].deleted = 1;
00030             break;
00031         case 'I':
00032             for (i=NINCLUDE-2; i>=0; i--) {
00033                 if (includelist[i].file==NULL) {
00034                     includelist[i].always = 1;
00035                     includelist[i].file = optarg;
00036                     break;
00037                 }
00038             }
00039             if (i<0)
00040                 error(FATAL, "Too many -I directives");
00041             break;
00042         case 'D':
00043         case 'U':
00044             setsource("<cmdarg>", -1, optarg);
00045             maketokenrow(3, &tr);
00046             gettokens(&tr, 1);
00047             doadefine(&tr, c);
00048             unsetsource();
00049             break;
00050         case 'M':
00051             Mflag++;
00052             break;
00053         case 'v':
00054             fprintf(stderr, "%s %s\n", argv[0], rcsid);
00055             break;
00056         case 'V':
00057             verbose++;
00058             break;
00059         case '+':
00060             Cplusplus++;
00061             break;
00062         default:
00063             break;
00064         }
00065     dp = ".";
00066     fp = "<stdin>";
00067     fd = 0;
00068     if (optind<argc) {
00069         if ((fp = strrchr(argv[optind], '/')) != NULL) {
00070             int len = fp - argv[optind];
00071             dp = (char*)newstring((uchar*)argv[optind], len+1, 0);
00072             dp[len] = '\0';
00073         }
00074         fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
00075         if ((fd = open(fp, 0)) <= 0)
00076             error(FATAL, "Can't open input file %s", fp);
00077     }
00078     if (optind+1<argc) {
00079         int fdo = creat(argv[optind+1], 0666);
00080         if (fdo<0)
00081             error(FATAL, "Can't open output file %s", argv[optind+1]);
00082         dup2(fdo, 1);
00083     }
00084     if(Mflag)
00085         setobjname(fp);
00086     includelist[NINCLUDE-1].always = 0;
00087     includelist[NINCLUDE-1].file = dp;
00088     setsource(fp, fd, NULL);
00089 }

Here is the call graph for this function:

Tokenrow* stringify Tokenrow  ) 
 

Definition at line 421 of file macro.c.

References cp, error(), ERROR, token::flag, i, token::len, newstring(), s, STRING, STRLEN, strlen(), t, token::t, Token, Tokenrow, tr, token::type, uchar, vp, and token::wslen.

Referenced by substargs().

00422 {
00423     static Token t = { STRING };
00424     static Tokenrow tr = { &t, &t, &t+1, 1 };
00425     Token *tp;
00426     uchar s[STRLEN];
00427     uchar *sp = s, *cp;
00428     int i, instring;
00429 
00430     *sp++ = '"';
00431     for (tp = vp->bp; tp < vp->lp; tp++) {
00432         instring = tp->type==STRING || tp->type==CCON;
00433         if (sp+2*tp->len >= &s[STRLEN-10]) {
00434             error(ERROR, "Stringified macro arg is too long");
00435             break;
00436         }
00437         if (tp->wslen && (tp->flag&XPWS)==0)
00438             *sp++ = ' ';
00439         for (i=0, cp=tp->t; i<tp->len; i++) {   
00440             if (instring && (*cp=='"' || *cp=='\\'))
00441                 *sp++ = '\\';
00442             *sp++ = *cp++;
00443         }
00444     }
00445     *sp++ = '"';
00446     *sp = '\0';
00447     sp = s;
00448     t.len = strlen((char*)sp);
00449     t.t = newstring(sp, t.len, 0);
00450     return &tr;
00451 }

Here is the call graph for this function:

void substargs Nlist ,
Tokenrow ,
Tokenrow ** 
 

Definition at line 320 of file macro.c.

References tokenrow::bp, copytokenrow(), dofree(), DSHARP, error(), ERROR, expandrow(), insertrow(), lookuparg(), tokenrow::lp, NAME, Nlist, np, stringify(), Token, Tokenrow, tokenrow::tp, and token::type.

Referenced by expand().

00321 {
00322     Tokenrow tatr;
00323     Token *tp;
00324     int ntok, argno;
00325 
00326     for (rtr->tp=rtr->bp; rtr->tp<rtr->lp; ) {
00327         if (rtr->tp->type==SHARP) { /* string operator */
00328             tp = rtr->tp;
00329             rtr->tp += 1;
00330             if ((argno = lookuparg(np, rtr->tp))<0) {
00331                 error(ERROR, "# not followed by macro parameter");
00332                 continue;
00333             }
00334             ntok = 1 + (rtr->tp - tp);
00335             rtr->tp = tp;
00336             insertrow(rtr, ntok, stringify(atr[argno]));
00337             continue;
00338         }
00339         if (rtr->tp->type==NAME
00340          && (argno = lookuparg(np, rtr->tp)) >= 0) {
00341             if ((rtr->tp+1)->type==DSHARP
00342              || rtr->tp!=rtr->bp && (rtr->tp-1)->type==DSHARP)
00343                 insertrow(rtr, 1, atr[argno]);
00344             else {
00345                 copytokenrow(&tatr, atr[argno]);
00346                 expandrow(&tatr, "<macro>");
00347                 insertrow(rtr, 1, &tatr);
00348                 dofree(tatr.bp);
00349             }
00350             continue;
00351         }
00352         rtr->tp++;
00353     }
00354 }

Here is the call graph for this function:

int trigraph Source  ) 
 

Definition at line 465 of file lex.c.

References c, fillbuf(), source::inl, source::inp, memmove(), s, and Source.

Referenced by gettokens().

00466 {
00467     int c;
00468 
00469     while (s->inp+2 >= s->inl && fillbuf(s)!=EOF)
00470         ;
00471     if (s->inp[1]!='?')
00472         return 0;
00473     c = 0;
00474     switch(s->inp[2]) {
00475     case '=':
00476         c = '#'; break;
00477     case '(':
00478         c = '['; break;
00479     case '/':
00480         c = '\\'; break;
00481     case ')':
00482         c = ']'; break;
00483     case '\'':
00484         c = '^'; break;
00485     case '<':
00486         c = '{'; break;
00487     case '!':
00488         c = '|'; break;
00489     case '>':
00490         c = '}'; break;
00491     case '-':
00492         c = '~'; break;
00493     }
00494     if (c) {
00495         *s->inp = c;
00496         memmove(s->inp+1, s->inp+3, s->inl-s->inp+2);
00497         s->inl -= 2;
00498     }
00499     return c;
00500 }

Here is the call graph for this function:

int unionhideset int  ,
int 
 

Definition at line 85 of file hideset.c.

References Hideset, hidesets, and newhideset().

Referenced by expand().

00086 {
00087     Hideset hp;
00088 
00089     for (hp = hidesets[hs2]; *hp; hp++)
00090         hs1 = newhideset(hs1, *hp);
00091     return hs1;
00092 }

Here is the call graph for this function:

void unsetsource void   ) 
 

Definition at line 571 of file lex.c.

References close(), cursource, dofree(), source::fd, source::inb, source::next, s, and Source.

Referenced by doconcat(), expandrow(), process(), and setup().

00572 {
00573     Source *s = cursource;
00574 
00575     if (s->fd>=0) {
00576         close(s->fd);
00577         dofree(s->inb);
00578     }
00579     cursource = s->next;
00580     dofree(s);
00581 }

Here is the call graph for this function:

int write int  ,
char *  ,
size_t 
 

Referenced by doinclude(), flushout(), puttokens(), Spk_Printf(), Sys_ConsoleInput(), tty_Back(), and tty_Show().


Variable Documentation

int Cplusplus
 

Definition at line 13 of file unix.c.

Referenced by fixlex(), and setup().

Source* cursource
 

Definition at line 13 of file cpp.c.

Referenced by control(), genline(), gettokens(), process(), puttokens(), setsource(), and unsetsource().

char* curtime
 

Definition at line 61 of file unix_shared.c.

int ifdepth
 

Definition at line 18 of file cpp.c.

Referenced by control().

int ifsatisfied[NIF]
 

Definition at line 19 of file cpp.c.

Referenced by control().

int incdepth
 

Definition at line 17 of file cpp.c.

Referenced by doinclude(), and process().

Includelist includelist[NINCLUDE]
 

Definition at line 5 of file include.c.

Referenced by doinclude().

Nlist* kwdefined
 

Definition at line 11 of file nlist.c.

Referenced by eval(), and setup_kwtab().

int Mflag
 

Definition at line 11 of file unix.c.

Referenced by doinclude(), and setup().

unsigned long namebit[077+1]
 

Definition at line 45 of file nlist.c.

Token nltoken
 

Definition at line 15 of file cpp.c.

char* outp
 

Definition at line 12 of file cpp.c.

Referenced by builtin(), genline(), process(), S_AdpcmDecode(), and S_AdpcmEncode().

int skipping
 

Definition at line 20 of file cpp.c.

Referenced by control(), and process().

int verbose
 

Definition at line 210 of file l_cmd.c.

char wd[]
 

Definition at line 12 of file nlist.c.

Referenced by genline().


Generated on Thu Aug 25 15:47:30 2005 for Quake III Arena by  doxygen 1.3.9.1