=================================================================== RCS file: /cvs/mandoc/mdoc_argv.c,v retrieving revision 1.64 retrieving revision 1.67 diff -u -p -r1.64 -r1.67 --- mandoc/mdoc_argv.c 2011/03/17 00:58:14 1.64 +++ mandoc/mdoc_argv.c 2011/03/17 10:41:18 1.67 @@ -1,4 +1,4 @@ -/* $Id: mdoc_argv.c,v 1.64 2011/03/17 00:58:14 kristaps Exp $ */ +/* $Id: mdoc_argv.c,v 1.67 2011/03/17 10:41:18 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -405,20 +405,12 @@ args(struct mdoc *m, int line, int *pos, * is unterminated. */ if (MDOC_PHRASELIT & m->flags) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE); m->flags &= ~MDOC_PHRASELIT; return(ARGS_EOLN); } - /* - * If the first character is a closing delimiter and we're to - * look for delimited strings, then pass down the buffer seeing - * if it follows the pattern of [[::delim::][ ]+]+. Note that - * we ONLY care about closing delimiters. - */ - *v = &buf[*pos]; if (ARGS_DELIM & fl && args_checkpunct(&buf[*pos])) { @@ -427,9 +419,7 @@ args(struct mdoc *m, int line, int *pos, return(ARGS_PUNCT); if (ARGS_NOWARN & fl) return(ARGS_PUNCT); - /* FIXME: remove conditional messages... */ - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); return(ARGS_PUNCT); } @@ -480,8 +470,7 @@ args(struct mdoc *m, int line, int *pos, /* Whitespace check for eoln case... */ if ('\0' == *p && ' ' == *(p - 1) && ! (ARGS_NOWARN & fl)) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); *pos += (int)(p - *v); @@ -525,8 +514,7 @@ args(struct mdoc *m, int line, int *pos, if ('\0' == buf[*pos]) { if (ARGS_NOWARN & fl || MDOC_PPHRASE & m->flags) return(ARGS_QWORD); - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE); return(ARGS_QWORD); } @@ -540,8 +528,7 @@ args(struct mdoc *m, int line, int *pos, (*pos)++; if (0 == buf[*pos] && ! (ARGS_NOWARN & fl)) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); return(ARGS_QWORD); } @@ -564,36 +551,57 @@ args(struct mdoc *m, int line, int *pos, (*pos)++; if ('\0' == buf[*pos] && ! (ARGS_NOWARN & fl)) - if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE)) - return(ARGS_ERROR); + mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE); return(ARGS_WORD); } /* * Check if the string consists only of space-separated closing - * delimiters. + * delimiters. This is a bit of a dance: the first must be a close + * delimiter, but it may be followed by middle delimiters. Arbitrary + * whitespace may separate these tokens. */ static int args_checkpunct(const char *p) { - int i; + int i, j; + char buf[DELIMSZ]; enum mdelim d; i = 0; - if (DELIM_CLOSE != mdoc_iscdelim(p[i])) + /* First token must be a close-delimiter. */ + + for (j = 0; p[i] && ' ' != p[i] && j < DELIMSZ; j++, i++) + buf[j] = p[i]; + + if (DELIMSZ == j) return(0); - while ('\0' != p[i]) { - d = mdoc_iscdelim(p[i]); - if (DELIM_NONE == d || DELIM_OPEN == d) - break; + buf[j] = '\0'; + if (DELIM_CLOSE != mandoc_isdelim(buf)) + return(0); + + while (' ' == p[i]) i++; - if ('\0' == p[i] || ' ' != p[i]) - break; - i++; - while (p[i] && ' ' == p[i]) + + /* Remaining must NOT be open/none. */ + + while (p[i]) { + j = 0; + while (p[i] && ' ' != p[i] && j < DELIMSZ) + buf[j++] = p[i++]; + + if (DELIMSZ == j) + return(0); + + buf[j] = '\0'; + d = mandoc_isdelim(buf); + if (DELIM_NONE == d || DELIM_OPEN == d) + return(0); + + while (' ' == p[i]) i++; }