diff --git a/macros.c b/macros.c index 4dd3e12..44179c1 100644 --- a/macros.c +++ b/macros.c @@ -414,14 +414,16 @@ STREAM *expandmacro( STREAM *str; BUFFER *buf; int nargs; + int onemore; args = NULL; arg = NULL; nargs = 0; /* for the .NARG directive */ + onemore = 0; /* Parse the arguments */ - while (!EOL(*cp)) { + while (!EOL(*cp) || onemore) { char *nextcp; /* Check for named argument */ @@ -464,7 +466,8 @@ STREAM *expandmacro( eval_arg(refstr, arg); /* Check for expression evaluation */ - cp = skipdelim(nextcp); + /* If there is a trailing comma, there is an empty last argument */ + cp = skipdelim_comma(nextcp, &onemore); } /* Now go back and fill in defaults */ { diff --git a/parse.c b/parse.c index a973878..6191c54 100644 --- a/parse.c +++ b/parse.c @@ -35,6 +35,21 @@ char *skipdelim( return cp; } +/* skipdelim_comma - used to advance between tokens. Whitespace + and one comma are allowed delims. + Set *comma depending on whether a comma was skipped. */ + +char *skipdelim_comma( + char *cp, + int *comma) +{ + cp = skipwhite(cp); + if (*comma = (*cp == ',')) { + cp = skipwhite(cp + 1); + } + return cp; +} + /* Parses a string from the input stream. */ /* If not bracketed by <...> or ^/.../, then */ /* the string is delimited by trailing comma or whitespace. */ diff --git a/parse.h b/parse.h index 55a4add..b1a415b 100644 --- a/parse.h +++ b/parse.h @@ -16,6 +16,9 @@ char *skipwhite( char *cp); char *skipdelim( char *cp); +char *skipdelim_comma( + char *cp, + int *comma); SYMBOL *get_op( char *cp,