# HG changeset patch # User David A. Holland # Date 1370915769 14400 # Node ID 2b153df78214538d0dd937717f907d5842d2944a # Parent 70d7ebeb45238583193e80ea4e65371cca18ae1a Don't bomb out if a function-like macro is given no arguments. Instead, do the traditional thing and just emit the macro name. diff -r 70d7ebeb4523 -r 2b153df78214 macro.c --- a/macro.c Mon Jun 10 21:37:01 2013 -0400 +++ b/macro.c Mon Jun 10 21:56:09 2013 -0400 @@ -823,6 +823,27 @@ es->curmacro->inuse = false; } +/* + * The traditional behavior if a function-like macro appears without + * arguments is to pretend it isn't a macro; that is, just emit its + * name. + */ +static +void +expand_missingargs(struct expstate *es, struct place *p, bool needspace) +{ + if (es->curmacro == NULL) { + /* defined */ + expand_send(es, p, "defined", 7); + return; + } + expand_send(es, p, es->curmacro->name, strlen(es->curmacro->name)); + /* send a space in case we ate whitespace after the macro name */ + if (needspace) { + expand_send(es, p, " ", 1); + } +} + static void expand_got_ws(struct expstate *es, struct place *p, char *buf, size_t len) @@ -877,15 +898,15 @@ break; case ES_WANTLPAREN: if (es->curmacro != NULL) { - complain(p, "Expected arguments for macro %s", - es->curmacro->name); - complain_fail(); + expand_missingargs(es, p, true); + es->state = ES_NORMAL; + /* try again */ + expand_got_word(es, p, buf, len); } else { /* "defined foo" means "defined(foo)" */ expand_newarg(es, buf, len); es->state = ES_NORMAL; expand_domacro(es, p); - break; } break; case ES_NOARG: @@ -930,13 +951,10 @@ expand_send(es, p, buf, len); break; case ES_WANTLPAREN: - if (es->curmacro) { - complain(p, "Expected arguments for macro %s", - es->curmacro->name); - } else { - complain(p, "Expected arguments for defined()"); - } - complain_fail(); + expand_missingargs(es, p, false); + es->state = ES_NORMAL; + /* try again */ + expand_got_rparen(es, p, buf, len); break; case ES_NOARG: assert(es->argparens == 0); @@ -964,13 +982,10 @@ expand_send(es, p, buf, len); break; case ES_WANTLPAREN: - if (es->curmacro) { - complain(p, "Expected arguments for macro %s", - es->curmacro->name); - } else { - complain(p, "Expected arguments for defined()"); - } - complain_fail(); + expand_missingargs(es, p, false); + es->state = ES_NORMAL; + /* try again */ + expand_got_comma(es, p, buf, len); break; case ES_NOARG: assert(es->argparens == 0); @@ -995,13 +1010,10 @@ expand_send(es, p, buf, len); break; case ES_WANTLPAREN: - if (es->curmacro) { - complain(p, "Expected arguments for macro %s", - es->curmacro->name); - } else { - complain(p, "Expected arguments for defined()"); - } - complain_fail(); + expand_missingargs(es, p, false); + es->state = ES_NORMAL; + /* try again */ + expand_got_other(es, p, buf, len); break; case ES_NOARG: expand_newarg(es, buf, len); @@ -1022,13 +1034,7 @@ expand_send_eof(es, p); break; case ES_WANTLPAREN: - if (es->curmacro) { - complain(p, "Expected arguments for macro %s", - es->curmacro->name); - } else { - complain(p, "Expected arguments for defined()"); - } - complain_fail(); + expand_missingargs(es, p, false); break; case ES_NOARG: case ES_HAVEARG: