=================================================================== RCS file: /cvs/mandoc/Attic/argv.c,v retrieving revision 1.14 retrieving revision 1.21 diff -u -p -r1.14 -r1.21 --- mandoc/Attic/argv.c 2009/01/16 11:50:54 1.14 +++ mandoc/Attic/argv.c 2009/01/20 13:49:36 1.21 @@ -1,4 +1,4 @@ -/* $Id: argv.c,v 1.14 2009/01/16 11:50:54 kristaps Exp $ */ +/* $Id: argv.c,v 1.21 2009/01/20 13:49:36 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 *); @@ -62,10 +70,10 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char if ( ! mdoc_iscdelim(buf[i])) break; i++; - if (0 == buf[i] || ! isspace(buf[i])) + if (0 == buf[i] || ! isspace((int)buf[i])) break; i++; - while (buf[i] && isspace(buf[i])) + while (buf[i] && isspace((int)buf[i])) i++; } if (0 == buf[i]) { @@ -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((int)buf[*pos])) + if ('\\' != buf[*pos - 1]) + break; (*pos)++; + } + } if (0 == buf[*pos]) return(ARGS_WORD); @@ -109,7 +123,7 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char return(ARGS_WORD); if ( ! (ARGS_TABSEP & fl)) - while (buf[*pos] && isspace(buf[*pos])) + while (buf[*pos] && isspace((int)buf[*pos])) (*pos)++; if (buf[*pos]) @@ -139,18 +153,18 @@ mdoc_args(struct mdoc *mdoc, int line, int *pos, char buf[(*pos)++] = 0; if (0 == buf[*pos]) - return(ARGS_WORD); + return(ARGS_QWORD); - while (buf[*pos] && isspace(buf[*pos])) + while (buf[*pos] && isspace((int)buf[*pos])) (*pos)++; if (buf[*pos]) - return(ARGS_WORD); + return(ARGS_QWORD); if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_COMPAT, "whitespace at end-of-line")) return(ARGS_ERROR); - return(ARGS_WORD); + return(ARGS_QWORD); } @@ -402,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) { @@ -438,7 +452,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, if (0 == buf[*pos]) return(ARGV_EOLN); - assert( ! isspace(buf[*pos])); + assert( ! isspace((int)buf[*pos])); if ('-' != buf[*pos]) return(ARGV_WORD); @@ -449,8 +463,13 @@ 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((int)buf[*pos])) + if ('\\' != buf[*pos - 1]) + break; (*pos)++; + } if (buf[*pos]) buf[(*pos)++] = 0; @@ -461,13 +480,13 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, return(ARGV_WORD); } - while (buf[*pos] && isspace(buf[*pos])) + while (buf[*pos] && isspace((int)buf[*pos])) (*pos)++; /* 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);