mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-09-22 10:43:39 -04:00
preproc: add %ifenv
Add %ifenv to test for the presence of an environment variable. The environment variable can, but does not have to be, prefixed with %!. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
## --------------------------------------------------------------------------
|
## --------------------------------------------------------------------------
|
||||||
##
|
##
|
||||||
## Copyright 1996-2009 The NASM Authors - All Rights Reserved
|
## Copyright 1996-2010 The NASM Authors - All Rights Reserved
|
||||||
## See the file AUTHORS included with the NASM distribution for
|
## See the file AUTHORS included with the NASM distribution for
|
||||||
## the specific copyright holders.
|
## the specific copyright holders.
|
||||||
##
|
##
|
||||||
@@ -39,6 +39,7 @@
|
|||||||
*ctx
|
*ctx
|
||||||
*def
|
*def
|
||||||
*empty
|
*empty
|
||||||
|
*env
|
||||||
*id
|
*id
|
||||||
*idn
|
*idn
|
||||||
*idni
|
*idni
|
||||||
|
21
preproc.c
21
preproc.c
@@ -1610,6 +1610,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
|
|||||||
struct tokenval tokval;
|
struct tokenval tokval;
|
||||||
expr *evalresult;
|
expr *evalresult;
|
||||||
enum pp_token_type needtype;
|
enum pp_token_type needtype;
|
||||||
|
const char *p;
|
||||||
|
|
||||||
origline = tline;
|
origline = tline;
|
||||||
|
|
||||||
@@ -1649,6 +1650,26 @@ static bool if_condition(Token * tline, enum preproc_token ct)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PPC_IFENV:
|
||||||
|
tline = expand_smacro(tline);
|
||||||
|
j = false; /* have we matched yet? */
|
||||||
|
while (tline) {
|
||||||
|
skip_white_(tline);
|
||||||
|
if (!tline || (tline->type != TOK_ID &&
|
||||||
|
(tline->type != TOK_PREPROC_ID ||
|
||||||
|
tline->text[1] != '!'))) {
|
||||||
|
error(ERR_NONFATAL,
|
||||||
|
"`%s' expects environment variable names",
|
||||||
|
pp_directives[ct]);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
p = tline->type == TOK_ID ? tline->text : tline->text + 2;
|
||||||
|
if (getenv(p))
|
||||||
|
j = true;
|
||||||
|
tline = tline->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case PPC_IFIDN:
|
case PPC_IFIDN:
|
||||||
case PPC_IFIDNI:
|
case PPC_IFIDNI:
|
||||||
tline = expand_smacro(tline);
|
tline = expand_smacro(tline);
|
||||||
|
Reference in New Issue
Block a user