=================================================================== RCS file: /cvs/mandoc/mdoc_argv.c,v retrieving revision 1.17 retrieving revision 1.24 diff -u -p -r1.17 -r1.24 --- mandoc/mdoc_argv.c 2009/07/18 18:49:19 1.17 +++ mandoc/mdoc_argv.c 2009/08/20 09:07:24 1.24 @@ -1,4 +1,4 @@ -/* $Id: mdoc_argv.c,v 1.17 2009/07/18 18:49:19 kristaps Exp $ */ +/* $Id: mdoc_argv.c,v 1.24 2009/08/20 09:07:24 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -32,11 +32,6 @@ * There's no limit to the number or arguments that may be allocated. */ -/* FIXME .Bf Li raises "macro-like parameter". */ - -#define ARGS_DELIM (1 << 1) -#define ARGS_TABSEP (1 << 2) - #define ARGV_NONE (1 << 0) #define ARGV_SINGLE (1 << 1) #define ARGV_MULTI (1 << 2) @@ -327,6 +322,15 @@ mdoc_argv_free(struct mdoc_arg *p) int +mdoc_zargs(struct mdoc *m, int line, int *pos, + char *buf, int flags, char **v) +{ + + return(args(m, line, pos, buf, flags, v)); +} + + +int mdoc_args(struct mdoc *m, int line, int *pos, char *buf, int tok, char **v) { @@ -371,6 +375,21 @@ args(struct mdoc *m, int line, int *pos, int i; char *p, *pp; + /* + * Parse out the terms (like `val' in `.Xx -arg val' or simply + * `.Xx val'), which can have all sorts of properties: + * + * ARGS_DELIM: use special handling if encountering trailing + * delimiters in the form of [[::delim::][ ]+]+. + * + * ARGS_NOWARN: don't post warnings. This is only used when + * re-parsing delimiters, as the warnings have already been + * posted. + * + * ARGS_TABSEP: use special handling for tab/`Ta' separated + * phrases like in `Bl -column'. + */ + assert(*pos); assert(' ' != buf[*pos]); @@ -395,10 +414,14 @@ args(struct mdoc *m, int line, int *pos, i++; } - /* FIXME: warn about trailing whitespace. */ - if (0 == buf[i]) { *v = &buf[*pos]; + if (' ' != buf[i - 1]) + return(ARGS_PUNCT); + if (ARGS_NOWARN & fl) + return(ARGS_PUNCT); + if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) + return(ARGS_ERROR); return(ARGS_PUNCT); } } @@ -413,7 +436,7 @@ args(struct mdoc *m, int line, int *pos, */ if (ARGS_TABSEP & fl) { - /* Scan ahead to unescaped tab. */ + /* Scan ahead to tab (can't be escaped). */ p = strchr(*v, '\t'); /* Scan ahead to unescaped `Ta'. */ @@ -426,59 +449,40 @@ args(struct mdoc *m, int line, int *pos, break; } - /* Choose delimiter tab/Ta. */ - if (p && pp) - p = (p < pp ? p : pp); - else if ( ! p && pp) + /* + * Adjust new-buffer position to be beyond delimiter + * mark (e.g., Ta -> end + 2). + */ + if (p && pp) { + *pos += pp < p ? 2 : 1; + p = pp < p ? pp : p; + } else if (p && ! pp) { + *pos += 1; + } else if (pp && ! p) { p = pp; + *pos += 2; + } else + p = strchr(*v, 0); - /* Strip delimiter's preceding whitespace. */ - /* FIXME: escaped whitespace? */ - if (p && p > *v) { - pp = p - 1; - while (pp > *v && ' ' == *pp) - pp--; - if (pp == *v && ' ' == *pp) - *pp = 0; - else if (' ' == *pp) - *(pp + 1) = 0; - } - - /* ...in- and proceding whitespace. */ - if (p && ('\t' != *p)) { - *p++ = 0; - *p++ = 0; - } else if (p) - *p++ = 0; - - if (p) { - while (' ' == *p) - p++; - if (0 != *p) - *(p - 1) = 0; - *pos += (int)(p - *v); - } - - /* Some warnings, if applicable. */ - if (p && 0 == *p) - if ( ! mdoc_pwarn(m, line, *pos, ECOLEMPTY)) - return(ARGS_ERROR); - if (p && 0 == *p && p > *v && ' ' == *(p - 1)) + /* Whitespace check for eoln case... */ + if (0 == *p && ' ' == *(p - 1) && ! (ARGS_NOWARN & fl)) if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); - /* Non-eoln case returns now. */ - if (p) - return(ARGS_PHRASE); + *pos += (int)(p - *v); - /* Configure the eoln case, too. */ - p = strchr(*v, 0); - assert(p); + /* Strip delimiter's preceding whitespace. */ + pp = p - 1; + while (pp > *v && ' ' == *pp) { + if (pp > *v && '\\' == *(pp - 1)) + break; + pp--; + } + *(pp + 1) = 0; - if (p > *v && ' ' == *(p - 1)) - if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) - return(ARGS_ERROR); - *pos += (int)(p - *v); + /* Strip delimiter's proceeding whitespace. */ + for (pp = &buf[*pos]; ' ' == *pp; pp++, (*pos)++) + /* Skip ahead. */ ; return(ARGS_PHRASE); } @@ -501,8 +505,11 @@ args(struct mdoc *m, int line, int *pos, } if (0 == buf[*pos]) { - (void)mdoc_perr(m, line, *pos, EQUOTTERM); - return(ARGS_ERROR); + if (ARGS_NOWARN & fl) + return(ARGS_QWORD); + if ( ! mdoc_pwarn(m, line, *pos, EQUOTTERM)) + return(ARGS_ERROR); + return(ARGS_QWORD); } buf[(*pos)++] = 0; @@ -513,7 +520,7 @@ args(struct mdoc *m, int line, int *pos, while (' ' == buf[*pos]) (*pos)++; - if (0 == buf[*pos]) + if (0 == buf[*pos] && ! (ARGS_NOWARN & fl)) if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); @@ -537,7 +544,7 @@ args(struct mdoc *m, int line, int *pos, while (' ' == buf[*pos]) (*pos)++; - if (0 == buf[*pos]) + if (0 == buf[*pos] && ! (ARGS_NOWARN & fl)) if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR);