version 1.5, 2009/07/12 20:30:27 |
version 1.6, 2009/07/12 21:08:29 |
|
|
* one mandatory value, an optional single value, or no value. |
* one mandatory value, an optional single value, or no value. |
*/ |
*/ |
int |
int |
mdoc_argv(struct mdoc *mdoc, int line, int tok, |
mdoc_argv(struct mdoc *m, int line, int tok, |
struct mdoc_arg **v, int *pos, char *buf) |
struct mdoc_arg **v, int *pos, char *buf) |
{ |
{ |
int i; |
int i; |
|
|
/* XXX - restore saved zeroed byte. */ |
/* XXX - restore saved zeroed byte. */ |
if (sv) |
if (sv) |
buf[*pos - 1] = sv; |
buf[*pos - 1] = sv; |
if ( ! pwarn(mdoc, line, i, WARGVPARM)) |
if ( ! pwarn(m, line, i, WARGVPARM)) |
return(ARGV_ERROR); |
return(ARGV_ERROR); |
return(ARGV_WORD); |
return(ARGV_WORD); |
} |
} |
|
|
while (buf[*pos] && ' ' == buf[*pos]) |
while (buf[*pos] && ' ' == buf[*pos]) |
(*pos)++; |
(*pos)++; |
|
|
if ( ! argv(mdoc, line, &tmp, pos, buf)) |
if ( ! argv(m, line, &tmp, pos, buf)) |
return(ARGV_ERROR); |
return(ARGV_ERROR); |
|
|
if (NULL == (arg = *v)) { |
if (NULL == (arg = *v)) { |
*v = calloc(1, sizeof(struct mdoc_arg)); |
*v = calloc(1, sizeof(struct mdoc_arg)); |
if (NULL == *v) { |
if (NULL == *v) { |
(void)verr(mdoc, EMALLOC); |
(void)mdoc_nerr(m, m->last, EMALLOC); |
return(ARGV_ERROR); |
return(ARGV_ERROR); |
} |
} |
arg = *v; |
arg = *v; |
|
|
sizeof(struct mdoc_argv)); |
sizeof(struct mdoc_argv)); |
|
|
if (NULL == arg->argv) { |
if (NULL == arg->argv) { |
(void)verr(mdoc, EMALLOC); |
(void)mdoc_nerr(m, m->last, EMALLOC); |
return(ARGV_ERROR); |
return(ARGV_ERROR); |
} |
} |
|
|
|
|
|
|
|
|
static int |
static int |
argv_multi(struct mdoc *mdoc, int line, |
argv_multi(struct mdoc *m, int line, |
struct mdoc_argv *v, int *pos, char *buf) |
struct mdoc_argv *v, int *pos, char *buf) |
{ |
{ |
int c; |
int c; |
|
|
for (v->sz = 0; ; v->sz++) { |
for (v->sz = 0; ; v->sz++) { |
if ('-' == buf[*pos]) |
if ('-' == buf[*pos]) |
break; |
break; |
c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p); |
c = args(m, line, pos, buf, ARGS_QUOTED, &p); |
if (ARGS_ERROR == c) |
if (ARGS_ERROR == c) |
return(0); |
return(0); |
else if (ARGS_EOLN == c) |
else if (ARGS_EOLN == c) |
|
|
v->value = realloc(v->value, |
v->value = realloc(v->value, |
(v->sz + MULTI_STEP) * sizeof(char *)); |
(v->sz + MULTI_STEP) * sizeof(char *)); |
if (NULL == v->value) { |
if (NULL == v->value) { |
(void)verr(mdoc, EMALLOC); |
(void)mdoc_nerr(m, m->last, EMALLOC); |
return(ARGV_ERROR); |
return(ARGV_ERROR); |
} |
} |
} |
} |
if (NULL == (v->value[(int)v->sz] = strdup(p))) |
if (NULL == (v->value[(int)v->sz] = strdup(p))) |
return(verr(mdoc, EMALLOC)); |
return(mdoc_nerr(m, m->last, EMALLOC)); |
} |
} |
|
|
return(1); |
return(1); |
|
|
|
|
|
|
static int |
static int |
argv_opt_single(struct mdoc *mdoc, int line, |
argv_opt_single(struct mdoc *m, int line, |
struct mdoc_argv *v, int *pos, char *buf) |
struct mdoc_argv *v, int *pos, char *buf) |
{ |
{ |
int c; |
int c; |
|
|
if ('-' == buf[*pos]) |
if ('-' == buf[*pos]) |
return(1); |
return(1); |
|
|
c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p); |
c = args(m, line, pos, buf, ARGS_QUOTED, &p); |
if (ARGS_ERROR == c) |
if (ARGS_ERROR == c) |
return(0); |
return(0); |
if (ARGS_EOLN == c) |
if (ARGS_EOLN == c) |
|
|
|
|
v->sz = 1; |
v->sz = 1; |
if (NULL == (v->value = calloc(1, sizeof(char *)))) |
if (NULL == (v->value = calloc(1, sizeof(char *)))) |
return(verr(mdoc, EMALLOC)); |
return(mdoc_nerr(m, m->last, EMALLOC)); |
if (NULL == (v->value[0] = strdup(p))) |
if (NULL == (v->value[0] = strdup(p))) |
return(verr(mdoc, EMALLOC)); |
return(mdoc_nerr(m, m->last, EMALLOC)); |
|
|
return(1); |
return(1); |
} |
} |
|
|
* Parse a single, mandatory value from the stream. |
* Parse a single, mandatory value from the stream. |
*/ |
*/ |
static int |
static int |
argv_single(struct mdoc *mdoc, int line, |
argv_single(struct mdoc *m, int line, |
struct mdoc_argv *v, int *pos, char *buf) |
struct mdoc_argv *v, int *pos, char *buf) |
{ |
{ |
int c, ppos; |
int c, ppos; |
|
|
|
|
ppos = *pos; |
ppos = *pos; |
|
|
c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p); |
c = args(m, line, pos, buf, ARGS_QUOTED, &p); |
if (ARGS_ERROR == c) |
if (ARGS_ERROR == c) |
return(0); |
return(0); |
if (ARGS_EOLN == c) |
if (ARGS_EOLN == c) |
return(perr(mdoc, line, ppos, EARGVAL)); |
return(perr(m, line, ppos, EARGVAL)); |
|
|
v->sz = 1; |
v->sz = 1; |
if (NULL == (v->value = calloc(1, sizeof(char *)))) |
if (NULL == (v->value = calloc(1, sizeof(char *)))) |
return(verr(mdoc, EMALLOC)); |
return(mdoc_nerr(m, m->last, EMALLOC)); |
if (NULL == (v->value[0] = strdup(p))) |
if (NULL == (v->value[0] = strdup(p))) |
return(verr(mdoc, EMALLOC)); |
return(mdoc_nerr(m, m->last, EMALLOC)); |
|
|
return(1); |
return(1); |
} |
} |