version 1.15, 2000/03/26 16:21:32 |
version 1.16, 2000/04/17 23:50:45 |
|
|
|
|
#define MAXIF 30 /* greatest depth of #if'ing */ |
#define MAXIF 30 /* greatest depth of #if'ing */ |
|
|
static Boolean condStack[MAXIF]; /* Stack of conditionals's values */ |
static struct { |
|
Boolean value; |
|
unsigned long lineno; |
|
const char *filename; |
|
} condStack[MAXIF]; /* Stack of conditionals */ |
static int condTop = MAXIF; /* Top-most conditional */ |
static int condTop = MAXIF; /* Top-most conditional */ |
static int skipIfLevel=0; /* Depth of skipped conditionals */ |
static int skipIfLevel=0; /* Depth of skipped conditionals */ |
static Boolean skipLine = FALSE; /* Whether the parse module is skipping |
static Boolean skipLine = FALSE; /* Whether the parse module is skipping |
|
|
Parse_Error (level, "if-less else"); |
Parse_Error (level, "if-less else"); |
return (COND_INVALID); |
return (COND_INVALID); |
} else if (skipIfLevel == 0) { |
} else if (skipIfLevel == 0) { |
value = !condStack[condTop]; |
value = !condStack[condTop].value; |
} else { |
} else { |
return (COND_SKIP); |
return (COND_SKIP); |
} |
} |
|
|
} |
} |
if (!isElse) { |
if (!isElse) { |
condTop -= 1; |
condTop -= 1; |
} else if ((skipIfLevel != 0) || condStack[condTop]) { |
} else if ((skipIfLevel != 0) || condStack[condTop].value) { |
/* |
/* |
* If this is an else-type conditional, it should only take effect |
* If this is an else-type conditional, it should only take effect |
* if its corresponding if was evaluated and FALSE. If its if was |
* if its corresponding if was evaluated and FALSE. If its if was |
|
|
Parse_Error (PARSE_FATAL, "Too many nested if's. %d max.", MAXIF); |
Parse_Error (PARSE_FATAL, "Too many nested if's. %d max.", MAXIF); |
return (COND_INVALID); |
return (COND_INVALID); |
} else { |
} else { |
condStack[condTop] = value; |
condStack[condTop].value = value; |
|
condStack[condTop].lineno = Parse_Getlineno(); |
|
condStack[condTop].filename = Parse_Getfilename(); |
skipLine = !value; |
skipLine = !value; |
return (value ? COND_PARSE : COND_SKIP); |
return (value ? COND_PARSE : COND_SKIP); |
} |
} |
|
|
void |
void |
Cond_End() |
Cond_End() |
{ |
{ |
|
int i; |
|
|
if (condTop != MAXIF) { |
if (condTop != MAXIF) { |
Parse_Error(PARSE_FATAL, "%d open conditional%s", MAXIF-condTop, |
Parse_Error(PARSE_FATAL, "%d open conditional%s", MAXIF-condTop, |
MAXIF-condTop == 1 ? "" : "s"); |
MAXIF-condTop == 1 ? "" : "s"); |
|
for (i = MAXIF-1; i >= condTop; i--) { |
|
fprintf(stderr, "\t at line %lu of %s\n", condStack[i].lineno, |
|
condStack[i].filename); |
|
} |
} |
} |
condTop = MAXIF; |
condTop = MAXIF; |
} |
} |