version 1.12, 2009/01/12 16:39:57 |
version 1.19, 2009/01/20 13:05:28 |
|
|
|
|
#include "private.h" |
#include "private.h" |
|
|
|
/* FIXME: .It called with -column and quoted arguments. */ |
|
/* FIXME: if arguments are quoted, they should not be later parsed for |
|
* macros. */ |
|
|
static int lookup(int, const char *); |
static int lookup(int, const char *); |
static int parse(struct mdoc *, int, int, |
static int parse(struct mdoc *, int, |
struct mdoc_arg *, int *, char *); |
struct mdoc_arg *, int *, char *); |
static int parse_single(struct mdoc *, int, |
static int parse_single(struct mdoc *, int, |
struct mdoc_arg *, int *, char *); |
struct mdoc_arg *, int *, char *); |
Line 46 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
Line 49 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
return(ARGS_EOLN); |
return(ARGS_EOLN); |
|
|
if ('\"' == buf[*pos] && ! (fl & ARGS_QUOTED)) |
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); |
return(ARGS_ERROR); |
|
|
if ('-' == buf[*pos]) |
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); |
return(ARGS_ERROR); |
|
|
if ((fl & ARGS_DELIM) && mdoc_iscdelim(buf[*pos])) { |
if ((fl & ARGS_DELIM) && mdoc_iscdelim(buf[*pos])) { |
Line 76 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
Line 79 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
|
|
/* Parse routine for non-quoted string. */ |
/* Parse routine for non-quoted string. */ |
|
|
if ('\"' != buf[*pos]) { |
assert(*pos > 0); |
|
if ('\"' != buf[*pos] || ! (ARGS_QUOTED & fl)) { |
*v = &buf[*pos]; |
*v = &buf[*pos]; |
|
|
/* FIXME: UGLY tab-sep processing. */ |
/* FIXME: UGLY tab-sep processing. */ |
Line 96 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
Line 100 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
} |
} |
(*pos)++; |
(*pos)++; |
} |
} |
else |
else { |
while (buf[*pos] && ! isspace(buf[*pos])) |
while (buf[*pos]) { |
|
if (isspace(buf[*pos])) |
|
if ('\\' != buf[*pos - 1]) |
|
break; |
(*pos)++; |
(*pos)++; |
|
} |
|
} |
|
|
if (0 == buf[*pos]) |
if (0 == buf[*pos]) |
return(ARGS_WORD); |
return(ARGS_WORD); |
Line 115 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
Line 124 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
if (buf[*pos]) |
if (buf[*pos]) |
return(ARGS_WORD); |
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_ERROR); |
|
|
return(ARGS_WORD); |
return(ARGS_WORD); |
Line 127 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
Line 136 mdoc_args(struct mdoc *mdoc, int line, int *pos, char |
|
* error. After, parse to the next word. |
* error. After, parse to the next word. |
*/ |
*/ |
|
|
assert( ! (ARGS_TABSEP & fl)); |
|
|
|
*v = &buf[++(*pos)]; |
*v = &buf[++(*pos)]; |
|
|
while (buf[*pos] && '\"' != buf[*pos]) |
while (buf[*pos] && '\"' != buf[*pos]) |
(*pos)++; |
(*pos)++; |
|
|
if (0 == buf[*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); |
return(ARGS_ERROR); |
} |
} |
|
|
buf[(*pos)++] = 0; |
buf[(*pos)++] = 0; |
if (0 == buf[*pos]) |
if (0 == buf[*pos]) |
return(ARGS_WORD); |
return(ARGS_QWORD); |
|
|
while (buf[*pos] && isspace(buf[*pos])) |
while (buf[*pos] && isspace(buf[*pos])) |
(*pos)++; |
(*pos)++; |
|
|
if (buf[*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_ERROR); |
|
|
return(ARGS_WORD); |
return(ARGS_QWORD); |
} |
} |
|
|
|
|
Line 173 lookup(int tok, const char *argv) |
|
Line 180 lookup(int tok, const char *argv) |
|
return(MDOC_Ragged); |
return(MDOC_Ragged); |
else if (xstrcmp(argv, "unfilled")) |
else if (xstrcmp(argv, "unfilled")) |
return(MDOC_Unfilled); |
return(MDOC_Unfilled); |
|
else if (xstrcmp(argv, "filled")) |
|
return(MDOC_Filled); |
else if (xstrcmp(argv, "literal")) |
else if (xstrcmp(argv, "literal")) |
return(MDOC_Literal); |
return(MDOC_Literal); |
else if (xstrcmp(argv, "file")) |
else if (xstrcmp(argv, "file")) |
Line 336 postparse(struct mdoc *mdoc, int line, const struct md |
|
Line 345 postparse(struct mdoc *mdoc, int line, const struct md |
|
break; |
break; |
if (xstrcmp(v->value[0], "indent-two")) |
if (xstrcmp(v->value[0], "indent-two")) |
break; |
break; |
return(mdoc_perr(mdoc, line, pos, ERR_SYNTAX_ARGBAD)); |
return(mdoc_perr(mdoc, line, pos, "invalid offset value")); |
default: |
default: |
break; |
break; |
} |
} |
Line 372 parse_multi(struct mdoc *mdoc, int line, |
|
Line 381 parse_multi(struct mdoc *mdoc, int line, |
|
if (0 < v->sz && v->sz < MDOC_LINEARG_MAX) |
if (0 < v->sz && v->sz < MDOC_LINEARG_MAX) |
return(1); |
return(1); |
|
|
c = 0 == v->sz ? ERR_SYNTAX_ARGVAL : ERR_SYNTAX_ARGMANY; |
|
free(v->value); |
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")); |
} |
} |
|
|
|
|
Line 391 parse_single(struct mdoc *mdoc, int line, |
|
Line 401 parse_single(struct mdoc *mdoc, int line, |
|
if (ARGS_ERROR == c) |
if (ARGS_ERROR == c) |
return(0); |
return(0); |
if (ARGS_EOLN == c) |
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->sz = 1; |
v->value = xcalloc(1, sizeof(char *)); |
v->value = xcalloc(1, sizeof(char *)); |
Line 401 parse_single(struct mdoc *mdoc, int line, |
|
Line 411 parse_single(struct mdoc *mdoc, int line, |
|
|
|
|
|
static int |
static int |
parse(struct mdoc *mdoc, int line, int tok, |
parse(struct mdoc *mdoc, int line, |
struct mdoc_arg *v, int *pos, char *buf) |
struct mdoc_arg *v, int *pos, char *buf) |
{ |
{ |
|
|
Line 448 mdoc_argv(struct mdoc *mdoc, int line, int tok, |
|
Line 458 mdoc_argv(struct mdoc *mdoc, int line, int tok, |
|
v->line = line; |
v->line = line; |
v->pos = *pos; |
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)++; |
(*pos)++; |
|
} |
|
|
if (buf[*pos]) |
if (buf[*pos]) |
buf[(*pos)++] = 0; |
buf[(*pos)++] = 0; |
|
|
if (MDOC_ARG_MAX == (v->arg = lookup(tok, argv))) { |
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); |
return(ARGV_WORD); |
} |
} |
|
|
Line 465 mdoc_argv(struct mdoc *mdoc, int line, int tok, |
|
Line 481 mdoc_argv(struct mdoc *mdoc, int line, int tok, |
|
/* FIXME: whitespace if no value. */ |
/* FIXME: whitespace if no value. */ |
|
|
ppos = *pos; |
ppos = *pos; |
if ( ! parse(mdoc, line, tok, v, pos, buf)) |
if ( ! parse(mdoc, line, v, pos, buf)) |
return(ARGV_ERROR); |
return(ARGV_ERROR); |
if ( ! postparse(mdoc, line, v, ppos)) |
if ( ! postparse(mdoc, line, v, ppos)) |
return(ARGV_ERROR); |
return(ARGV_ERROR); |