version 1.11, 1998/09/18 20:35:11 |
version 1.15, 2003/04/17 15:57:52 |
Line 61 __RCSID("$NetBSD$"); |
|
Line 61 __RCSID("$NetBSD$"); |
|
*/ |
*/ |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <math.h> |
|
#include "make.h" |
#include "make.h" |
#include "hash.h" |
#include "hash.h" |
#include "dir.h" |
#include "dir.h" |
Line 78 __RCSID("$NetBSD$"); |
|
Line 78 __RCSID("$NetBSD$"); |
|
* T -> exists(file) |
* T -> exists(file) |
* T -> empty(varspec) |
* T -> empty(varspec) |
* T -> target(name) |
* T -> target(name) |
|
* T -> commands(name) |
* T -> symbol |
* T -> symbol |
* T -> $(varspec) op value |
* T -> $(varspec) op value |
* T -> $(varspec) == "string" |
* T -> $(varspec) == "string" |
|
|
* Structures to handle elegantly the different forms of #if's. The |
* Structures to handle elegantly the different forms of #if's. The |
* last two fields are stored in condInvert and condDefProc, respectively. |
* last two fields are stored in condInvert and condDefProc, respectively. |
*/ |
*/ |
static void CondPushBack __P((Token)); |
static void CondPushBack(Token); |
static int CondGetArg __P((char **, char **, char *, Boolean)); |
static int CondGetArg(char **, char **, char *, Boolean); |
static Boolean CondDoDefined __P((int, char *)); |
static Boolean CondDoDefined(int, char *); |
static int CondStrMatch __P((ClientData, ClientData)); |
static int CondStrMatch(ClientData, ClientData); |
static Boolean CondDoMake __P((int, char *)); |
static Boolean CondDoMake(int, char *); |
static Boolean CondDoExists __P((int, char *)); |
static Boolean CondDoExists(int, char *); |
static Boolean CondDoTarget __P((int, char *)); |
static Boolean CondDoTarget(int, char *); |
static Boolean CondCvtArg __P((char *, double *)); |
static Boolean CondDoCommands(int, char *); |
static Token CondToken __P((Boolean)); |
static Boolean CondCvtArg(char *, double *); |
static Token CondT __P((Boolean)); |
static Token CondToken(Boolean); |
static Token CondF __P((Boolean)); |
static Token CondT(Boolean); |
static Token CondE __P((Boolean)); |
static Token CondF(Boolean); |
|
static Token CondE(Boolean); |
|
|
static struct If { |
static struct If { |
char *form; /* Form of if */ |
char *form; /* Form of if */ |
int formlen; /* Length of form */ |
int formlen; /* Length of form */ |
Boolean doNot; /* TRUE if default function should be negated */ |
Boolean doNot; /* TRUE if default function should be negated */ |
Boolean (*defProc) __P((int, char *)); /* Default function to apply */ |
Boolean (*defProc)(int, char *); /* Default function to apply */ |
} ifs[] = { |
} ifs[] = { |
{ "ifdef", 5, FALSE, CondDoDefined }, |
{ "ifdef", 5, FALSE, CondDoDefined }, |
{ "ifndef", 6, TRUE, CondDoDefined }, |
{ "ifndef", 6, TRUE, CondDoDefined }, |
Line 133 static struct If { |
|
Line 135 static struct If { |
|
}; |
}; |
|
|
static Boolean condInvert; /* Invert the default function */ |
static Boolean condInvert; /* Invert the default function */ |
static Boolean (*condDefProc) /* Default function to apply */ |
static Boolean (*condDefProc)(int, char *); /* Default function to apply */ |
__P((int, char *)); |
|
static char *condExpr; /* The expression to parse */ |
static char *condExpr; /* The expression to parse */ |
static Token condPushBack=None; /* Single push-back token used in |
static Token condPushBack=None; /* Single push-back token used in |
* parsing */ |
* parsing */ |
Line 153 static Boolean skipLine = FALSE; /* W |
|
Line 154 static Boolean skipLine = FALSE; /* W |
|
* Push back the most recent token read. We only need one level of |
* Push back the most recent token read. We only need one level of |
* this, so the thing is just stored in 'condPushback'. |
* this, so the thing is just stored in 'condPushback'. |
* |
* |
|
* Input: |
|
* t Token to push back into the "stream" |
|
* |
* Results: |
* Results: |
* None. |
* None. |
* |
* |
Line 162 static Boolean skipLine = FALSE; /* W |
|
Line 166 static Boolean skipLine = FALSE; /* W |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static void |
static void |
CondPushBack (t) |
CondPushBack(Token t) |
Token t; /* Token to push back into the "stream" */ |
|
{ |
{ |
condPushBack = t; |
condPushBack = t; |
} |
} |
Line 173 CondPushBack (t) |
|
Line 176 CondPushBack (t) |
|
* CondGetArg -- |
* CondGetArg -- |
* Find the argument of a built-in function. |
* Find the argument of a built-in function. |
* |
* |
|
* Input: |
|
* parens TRUE if arg should be bounded by parens |
|
* |
* Results: |
* Results: |
* The length of the argument and the address of the argument. |
* The length of the argument and the address of the argument. |
* |
* |
Line 183 CondPushBack (t) |
|
Line 189 CondPushBack (t) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static int |
static int |
CondGetArg (linePtr, argPtr, func, parens) |
CondGetArg(char **linePtr, char **argPtr, char *func, Boolean parens) |
char **linePtr; |
|
char **argPtr; |
|
char *func; |
|
Boolean parens; /* TRUE if arg should be bounded by parens */ |
|
{ |
{ |
register char *cp; |
char *cp; |
int argLen; |
int argLen; |
register Buffer buf; |
Buffer buf; |
|
|
cp = *linePtr; |
cp = *linePtr; |
if (parens) { |
if (parens) { |
Line 285 CondGetArg (linePtr, argPtr, func, paren |
|
Line 287 CondGetArg (linePtr, argPtr, func, paren |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Boolean |
static Boolean |
CondDoDefined (argLen, arg) |
CondDoDefined(int argLen, char *arg) |
int argLen; |
|
char *arg; |
|
{ |
{ |
char savec = arg[argLen]; |
char savec = arg[argLen]; |
char *p1; |
char *p1; |
Line 320 CondDoDefined (argLen, arg) |
|
Line 320 CondDoDefined (argLen, arg) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static int |
static int |
CondStrMatch(string, pattern) |
CondStrMatch(ClientData string, ClientData pattern) |
ClientData string; |
|
ClientData pattern; |
|
{ |
{ |
return(!Str_Match((char *) string,(char *) pattern)); |
return(!Str_Match((char *) string,(char *) pattern)); |
} |
} |
Line 341 CondStrMatch(string, pattern) |
|
Line 339 CondStrMatch(string, pattern) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Boolean |
static Boolean |
CondDoMake (argLen, arg) |
CondDoMake(int argLen, char *arg) |
int argLen; |
|
char *arg; |
|
{ |
{ |
char savec = arg[argLen]; |
char savec = arg[argLen]; |
Boolean result; |
Boolean result; |
Line 372 CondDoMake (argLen, arg) |
|
Line 368 CondDoMake (argLen, arg) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Boolean |
static Boolean |
CondDoExists (argLen, arg) |
CondDoExists(int argLen, char *arg) |
int argLen; |
|
char *arg; |
|
{ |
{ |
char savec = arg[argLen]; |
char savec = arg[argLen]; |
Boolean result; |
Boolean result; |
Line 406 CondDoExists (argLen, arg) |
|
Line 400 CondDoExists (argLen, arg) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Boolean |
static Boolean |
CondDoTarget (argLen, arg) |
CondDoTarget(int argLen, char *arg) |
int argLen; |
|
char *arg; |
|
{ |
{ |
char savec = arg[argLen]; |
char savec = arg[argLen]; |
Boolean result; |
Boolean result; |
Line 425 CondDoTarget (argLen, arg) |
|
Line 417 CondDoTarget (argLen, arg) |
|
return (result); |
return (result); |
} |
} |
|
|
|
/*- |
|
*----------------------------------------------------------------------- |
|
* CondDoCommands -- |
|
* See if the given node exists and is an actual target with commands |
|
* associated with it. |
|
* |
|
* Results: |
|
* TRUE if the node exists as a target and has commands associated with |
|
* it and FALSE if it does not. |
|
* |
|
* Side Effects: |
|
* None. |
|
* |
|
*----------------------------------------------------------------------- |
|
*/ |
|
static Boolean |
|
CondDoCommands(int argLen, char *arg) |
|
{ |
|
char savec = arg[argLen]; |
|
Boolean result; |
|
GNode *gn; |
|
|
|
arg[argLen] = '\0'; |
|
gn = Targ_FindNode(arg, TARG_NOCREATE); |
|
if ((gn != NILGNODE) && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands)) { |
|
result = TRUE; |
|
} else { |
|
result = FALSE; |
|
} |
|
arg[argLen] = savec; |
|
return (result); |
|
} |
|
|
/*- |
/*- |
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
Line 445 CondDoTarget (argLen, arg) |
|
Line 469 CondDoTarget (argLen, arg) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Boolean |
static Boolean |
CondCvtArg(str, value) |
CondCvtArg(char *str, double *value) |
register char *str; |
|
double *value; |
|
{ |
{ |
if ((*str == '0') && (str[1] == 'x')) { |
if ((*str == '0') && (str[1] == 'x')) { |
register long i; |
long i; |
|
|
for (str += 2, i = 0; *str; str++) { |
for (str += 2, i = 0; *str; str++) { |
int x; |
int x; |
Line 486 CondCvtArg(str, value) |
|
Line 508 CondCvtArg(str, value) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Token |
static Token |
CondToken(doEval) |
CondToken(Boolean doEval) |
Boolean doEval; |
|
{ |
{ |
Token t; |
Token t; |
|
|
Line 522 CondToken(doEval) |
|
Line 543 CondToken(doEval) |
|
t = Not; |
t = Not; |
condExpr++; |
condExpr++; |
break; |
break; |
|
case '#': |
case '\n': |
case '\n': |
case '\0': |
case '\0': |
t = EndOfFile; |
t = EndOfFile; |
|
|
break; |
break; |
} |
} |
default: { |
default: { |
Boolean (*evalProc) __P((int, char *)); |
Boolean (*evalProc)(int, char *); |
Boolean invert = FALSE; |
Boolean invert = FALSE; |
char *arg; |
char *arg; |
int arglen; |
int arglen; |
|
|
condExpr -= 6; |
condExpr -= 6; |
goto use_default; |
goto use_default; |
} |
} |
|
} else if (strncmp (condExpr, "commands", 8) == 0) { |
|
/* |
|
* Use CondDoCommands to evaluate the argument and |
|
* CondGetArg to extract the argument from the |
|
* 'function call'. |
|
*/ |
|
evalProc = CondDoCommands; |
|
condExpr += 8; |
|
arglen = CondGetArg(&condExpr, &arg, "commands", TRUE); |
|
if (arglen == 0) { |
|
condExpr -= 8; |
|
goto use_default; |
|
} |
} else { |
} else { |
/* |
/* |
* The symbol is itself the argument to the default |
* The symbol is itself the argument to the default |
|
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Token |
static Token |
CondT(doEval) |
CondT(Boolean doEval) |
Boolean doEval; |
|
{ |
{ |
Token t; |
Token t; |
|
|
|
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Token |
static Token |
CondF(doEval) |
CondF(Boolean doEval) |
Boolean doEval; |
|
{ |
{ |
Token l, o; |
Token l, o; |
|
|
|
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
static Token |
static Token |
CondE(doEval) |
CondE(Boolean doEval) |
Boolean doEval; |
|
{ |
{ |
Token l, o; |
Token l, o; |
|
|
|
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
int |
int |
Cond_EvalExpression(dosetup, line, value, eprint) |
Cond_EvalExpression(int dosetup, char *line, Boolean *value, int eprint) |
int dosetup; |
|
char *line; |
|
Boolean *value; |
|
int eprint; |
|
{ |
{ |
if (dosetup) { |
if (dosetup) { |
condDefProc = CondDoDefined; |
condDefProc = CondDoDefined; |
|
|
* and <expr> consists of &&, ||, !, make(target), defined(variable) |
* and <expr> consists of &&, ||, !, make(target), defined(variable) |
* and parenthetical groupings thereof. |
* and parenthetical groupings thereof. |
* |
* |
|
* Input: |
|
* line Line to parse |
|
* |
* Results: |
* Results: |
* COND_PARSE if should parse lines after the conditional |
* COND_PARSE if should parse lines after the conditional |
* COND_SKIP if should skip lines after the conditional |
* COND_SKIP if should skip lines after the conditional |
|
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
int |
int |
Cond_Eval (line) |
Cond_Eval(char *line) |
char *line; /* Line to parse */ |
|
{ |
{ |
struct If *ifp; |
struct If *ifp; |
Boolean isElse; |
Boolean isElse; |
Line 1293 Cond_Eval (line) |
|
Line 1323 Cond_Eval (line) |
|
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
void |
void |
Cond_End() |
Cond_End(void) |
{ |
{ |
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, |