=================================================================== RCS file: /cvs/mandoc/Attic/argv.c,v retrieving revision 1.13 retrieving revision 1.20 diff -u -p -r1.13 -r1.20 --- mandoc/Attic/argv.c 2009/01/15 15:46:45 1.13 +++ mandoc/Attic/argv.c 2009/01/20 13:44:05 1.20 @@ -1,4 +1,4 @@ -/* $Id: argv.c,v 1.13 2009/01/15 15:46:45 kristaps Exp $ */ +/* $Id: argv.c,v 1.20 2009/01/20 13:44:05 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -25,9 +25,17 @@ #include "private.h" +/* + * Parse arguments and parameters of macros. Arguments follow the + * syntax of `-arg [val [valN...]]', while parameters are free-form text + * following arguments (if any). This file must correctly handle the + * strange punctuation rules dictated by groff. + */ +/* FIXME: .It called with -column and quoted arguments. */ + static int lookup(int, const char *); -static int parse(struct mdoc *, int, int, +static int parse(struct mdoc *, int, struct mdoc_arg *, int *, char *); static int parse_single(struct mdoc *, int, struct mdoc_arg *, int *, char *); @@ -46,11 +54,11 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char return(ARGS_EOLN); if ('\"' == buf[*pos] && ! (fl & ARGS_QUOTED)) - if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_SYNTAX_QUOTED)) + if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_SYNTAX, "unexpected quoted parameter")) return(ARGS_ERROR); if ('-' == buf[*pos]) - if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_SYNTAX_ARGLIKE)) + if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_SYNTAX, "argument-like parameter")) return(ARGS_ERROR); if ((fl & ARGS_DELIM) && mdoc_iscdelim(buf[*pos])) { @@ -76,7 +84,8 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char /* Parse routine for non-quoted string. */ - if ('\"' != buf[*pos]) { + assert(*pos > 0); + if ('\"' != buf[*pos] || ! (ARGS_QUOTED & fl)) { *v = &buf[*pos]; /* FIXME: UGLY tab-sep processing. */ @@ -96,9 +105,14 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char } (*pos)++; } - else - while (buf[*pos] && ! isspace(buf[*pos])) + else { + while (buf[*pos]) { + if (isspace(buf[*pos])) + if ('\\' != buf[*pos - 1]) + break; (*pos)++; + } + } if (0 == buf[*pos]) return(ARGS_WORD); @@ -115,7 +129,7 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char if (buf[*pos]) return(ARGS_WORD); - if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_SYNTAX_WS_EOLN)) + if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_COMPAT, "whitespace at end-of-line")) return(ARGS_ERROR); return(ARGS_WORD); @@ -127,32 +141,30 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char * error. After, parse to the next word. */ - assert( ! (ARGS_TABSEP & fl)); - *v = &buf[++(*pos)]; while (buf[*pos] && '\"' != buf[*pos]) (*pos)++; if (0 == buf[*pos]) { - (void)mdoc_perr(mdoc, line, *pos, ERR_SYNTAX_UNQUOTE); + (void)mdoc_perr(mdoc, line, *pos, "unterminated quoted parameter"); return(ARGS_ERROR); } buf[(*pos)++] = 0; if (0 == buf[*pos]) - return(ARGS_WORD); + return(ARGS_QWORD); while (buf[*pos] && isspace(buf[*pos])) (*pos)++; if (buf[*pos]) - return(ARGS_WORD); + return(ARGS_QWORD); - if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_SYNTAX_WS_EOLN)) + if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_COMPAT, "whitespace at end-of-line")) return(ARGS_ERROR); - return(ARGS_WORD); + return(ARGS_QWORD); } @@ -338,7 +350,7 @@ postparse(struct mdoc *mdoc, int line, const struct md break; if (xstrcmp(v->value[0], "indent-two")) break; - return(mdoc_perr(mdoc, line, pos, ERR_SYNTAX_ARGBAD)); + return(mdoc_perr(mdoc, line, pos, "invalid offset value")); default: break; } @@ -374,9 +386,10 @@ parse_multi(struct mdoc *mdoc, int line, if (0 < v->sz && v->sz < MDOC_LINEARG_MAX) return(1); - c = 0 == v->sz ? ERR_SYNTAX_ARGVAL : ERR_SYNTAX_ARGMANY; free(v->value); - return(mdoc_perr(mdoc, line, ppos, c)); + return(mdoc_perr(mdoc, line, ppos, 0 == v->sz ? + "argument requires a value" : + "too many values to argument")); } @@ -393,7 +406,7 @@ parse_single(struct mdoc *mdoc, int line, if (ARGS_ERROR == c) return(0); if (ARGS_EOLN == c) - return(mdoc_perr(mdoc, line, ppos, ERR_SYNTAX_ARGVAL)); + return(mdoc_perr(mdoc, line, ppos, "argument requires a value")); v->sz = 1; v->value = xcalloc(1, sizeof(char *)); @@ -403,7 +416,7 @@ parse_single(struct mdoc *mdoc, int line, static int -parse(struct mdoc *mdoc, int line, int tok, +parse(struct mdoc *mdoc, int line, struct mdoc_arg *v, int *pos, char *buf) { @@ -450,14 +463,20 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, v->line = line; v->pos = *pos; - while (buf[*pos] && ! isspace(buf[*pos])) + assert(*pos > 0); + while (buf[*pos]) { + if (isspace(buf[*pos])) + if ('\\' != buf[*pos - 1]) + break; (*pos)++; + } if (buf[*pos]) buf[(*pos)++] = 0; if (MDOC_ARG_MAX == (v->arg = lookup(tok, argv))) { - (void)mdoc_pwarn(mdoc, line, i, WARN_SYNTAX_ARGLIKE); + if ( ! mdoc_pwarn(mdoc, line, i, WARN_SYNTAX, "argument-like parameter")) + return(ARGV_ERROR); return(ARGV_WORD); } @@ -467,7 +486,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, /* FIXME: whitespace if no value. */ ppos = *pos; - if ( ! parse(mdoc, line, tok, v, pos, buf)) + if ( ! parse(mdoc, line, v, pos, buf)) return(ARGV_ERROR); if ( ! postparse(mdoc, line, v, ppos)) return(ARGV_ERROR);