1
/************************************************************************/
5
/* Conditional processing. */
9
/* 3420 NW Elmwood Dr. */
11
/* Corvallis, Oregon 97339 */
17
/* Corvallis, OR 97339 */
20
/* This program is hereby placed in the public domain. In */
21
/* contrast to other claims of "public domain", this means no */
22
/* copyright is claimed and you may do anything you like with PP, */
23
/* including selling it! As a gesture of courtesy, please retain */
24
/* the authorship information in the source code and */
27
/* Functions contained within this module: */
29
/* doelse Process #else/#elif directive. */
30
/* doendif Process #endif directive. */
31
/* doif Process #if directive. */
32
/* doifs Do work for #ifdef/#ifndef stuff. */
34
/************************************************************************/
39
/************************************************************************/
43
/* Process #else/#elif statement. */
45
/************************************************************************/
49
int elif; /* TRUE if #elif; FALSE if #else */
52
if(Debug) printf("doelse: %d\n",Iflevel);
56
/* We are processing an if */
57
if(Ifstack[Iflevel].i_else)
58
non_fatal("\"#else\" already encountered","");
62
Ifstate = Ifstack[Iflevel].i_state = IFNEVER;
63
else if(Ifstate == IFFALSE)
68
* Note that we first need to pretend that we are in a TRUE branch so
69
* that routines which "eval" causes to be called will correctly process
70
* the "elif" expression (in particular "_docall").
72
Ifstate = Ifstack[Iflevel].i_state =
74
Ifstate = Ifstack[Iflevel].i_state =
75
eval() ? IFTRUE : IFFALSE;
79
Ifstate = Ifstack[Iflevel].i_state =
83
/* If have seen an #else */
84
Ifstack[Iflevel].i_else = !elif;
90
non_fatal("\"#elif\" outside of \"#if\"","");
92
non_fatal("\"#else\" outside of \"#if\"","");
96
/************************************************************************/
100
/* Process #endif statement. */
102
/************************************************************************/
108
if(Debug) printf("doendif: %d\n",Iflevel);
111
Ifstate = Ifstack[--Iflevel].i_state; /* Pop stack */
113
non_fatal("\"#endif\" outside of \"#if\"","");
116
/************************************************************************/
120
/* Process #if statement. */
122
/************************************************************************/
127
if(Iflevel >= IFSTACKSIZE)
128
non_fatal("\"#if\" stack overflow","");
131
if(Ifstate == IFTRUE)
133
Ifstate = Ifstack[++Iflevel].i_state =
134
eval() ? IFTRUE : IFFALSE;
138
Ifstate = Ifstack[++Iflevel].i_state =
139
IFNEVER; /* NO #else */
140
scaneol(); /* Just absorb the rest */
142
Ifstack[Iflevel].i_else = FALSE; /* No #else seen */
146
/************************************************************************/
150
/* Process some kind of #ifxdef statement. */
152
/* Lookup token and set Ifstack to inform output routine to */
153
/* emit code or not. */
155
/************************************************************************/
159
int t; /* Type of if TRUE if #ifdef */
163
if(Ifstate == IFTRUE)
165
/* Get next non-space token */
166
if(getnstoken(GT_STR) == LETTER)
169
if(Debug) printf("doifs: %d %s",t,Token);
171
iftype = (lookup(Token,NULL) ? TRUE : FALSE) ^
172
(t ? FALSE : TRUE) ? IFTRUE : IFFALSE;
181
iftype = IFNEVER; /* Inside false #if -- No #else */
183
if(Iflevel >= IFSTACKSIZE)
184
non_fatal("\"#if\" stack overflow","");
187
Ifstate = Ifstack[++Iflevel].i_state = iftype;
188
Ifstack[Iflevel].i_else = FALSE;
192
if(Debug) printf("doifs: %d %d %d\n",t,iftype,Iflevel);