diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-07-06 13:04:52 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-07-06 13:04:52 +0000 |
commit | 7a72fe65c7d5fe05324b8d227b387f2aa3cea747 (patch) | |
tree | a9b1a7faf197c0162351bbd69ec28a426e4cc67c /mdoc_argv.c | |
parent | 836a616d2c9decff2a835b27818ffa4749af5900 (diff) | |
download | mandoc-7a72fe65c7d5fe05324b8d227b387f2aa3cea747.tar.gz |
Consolidated all err/warnings into mdoc.c via libmdoc.h.
Diffstat (limited to 'mdoc_argv.c')
-rw-r--r-- | mdoc_argv.c | 114 |
1 files changed, 30 insertions, 84 deletions
diff --git a/mdoc_argv.c b/mdoc_argv.c index 407edcb6..cd397f5d 100644 --- a/mdoc_argv.c +++ b/mdoc_argv.c @@ -47,16 +47,6 @@ #define MULTI_STEP 5 -enum merr { - ETAILWS, - ECOLEMPTY, - EARGVPARM, - EQUOTPARM, - EQUOTTERM, - EMALLOC, - EARGVAL -}; - static int argv_a2arg(int, const char *); static int args(struct mdoc *, int, int *, char *, int, char **); @@ -68,10 +58,6 @@ static int argv_opt_single(struct mdoc *, int, struct mdoc_argv *, int *, char *); static int argv_multi(struct mdoc *, int, struct mdoc_argv *, int *, char *); -static int perr(struct mdoc *, int, int, enum merr, int); - -#define pwarn(m, l, p, t) perr((m), (l), (p), (t), 0) -#define verr(m, t) perr((m), (m)->last->line, (m)->last->pos, (t), 1) /* Per-argument flags. */ @@ -232,7 +218,7 @@ static int mdoc_argflags[MDOC_MAX] = { * one mandatory value, an optional single value, or no value. */ 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) { int i; @@ -281,7 +267,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, /* XXX - restore saved zeroed byte. */ if (sv) buf[*pos - 1] = sv; - if ( ! pwarn(mdoc, line, i, EARGVPARM)) + if ( ! mdoc_pwarn(m, line, i, EARGVPARM)) return(ARGV_ERROR); return(ARGV_WORD); } @@ -289,13 +275,13 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, while (buf[*pos] && ' ' == buf[*pos]) (*pos)++; - if ( ! argv(mdoc, line, &tmp, pos, buf)) + if ( ! argv(m, line, &tmp, pos, buf)) return(ARGV_ERROR); if (NULL == (arg = *v)) { *v = calloc(1, sizeof(struct mdoc_arg)); if (NULL == *v) { - (void)verr(mdoc, EMALLOC); + (void)mdoc_nerr(m, m->last, EMALLOC); return(ARGV_ERROR); } arg = *v; @@ -306,7 +292,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok, sizeof(struct mdoc_argv)); if (NULL == arg->argv) { - (void)verr(mdoc, EMALLOC); + (void)mdoc_nerr(m, m->last, EMALLOC); return(ARGV_ERROR); } @@ -348,48 +334,8 @@ mdoc_argv_free(struct mdoc_arg *p) } - -static int -perr(struct mdoc *mdoc, int line, int pos, enum merr code, int iserr) -{ - char *p; - - p = NULL; - - switch (code) { - case (EMALLOC): - p = "memory exhausted"; - break; - case (EQUOTTERM): - p = "unterminated quoted parameter"; - break; - case (EARGVAL): - p = "argument requires a value"; - break; - case (EQUOTPARM): - p = "unexpected quoted parameter"; - break; - case (EARGVPARM): - p = "argument-like parameter"; - break; - case (ECOLEMPTY): - p = "last list column is empty"; - break; - case (ETAILWS): - p = "trailing whitespace"; - break; - } - - assert(p); - if (iserr) - return(mdoc_perr(mdoc, line, pos, p)); - - return(mdoc_pwarn(mdoc, line, pos, p)); -} - - int -mdoc_args(struct mdoc *mdoc, int line, +mdoc_args(struct mdoc *m, int line, int *pos, char *buf, int tok, char **v) { int fl, c, i; @@ -405,7 +351,7 @@ mdoc_args(struct mdoc *mdoc, int line, switch (tok) { case (MDOC_It): - for (n = mdoc->last; n; n = n->parent) + for (n = m->last; n; n = n->parent) if (MDOC_BLOCK == n->type && MDOC_Bl == n->tok) break; @@ -440,12 +386,12 @@ mdoc_args(struct mdoc *mdoc, int line, break; } - return(args(mdoc, line, pos, buf, fl, v)); + return(args(m, line, pos, buf, fl, v)); } static int -args(struct mdoc *mdoc, int line, +args(struct mdoc *m, int line, int *pos, char *buf, int fl, char **v) { int i; @@ -457,11 +403,11 @@ args(struct mdoc *mdoc, int line, return(ARGS_EOLN); if ('\"' == buf[*pos] && ! (fl & ARGS_QUOTED)) - if ( ! pwarn(mdoc, line, *pos, EQUOTPARM)) + if ( ! mdoc_pwarn(m, line, *pos, EQUOTPARM)) return(ARGS_ERROR); if ( ! (fl & ARGS_ARGVLIKE) && '-' == buf[*pos]) - if ( ! pwarn(mdoc, line, *pos, EARGVPARM)) + if ( ! mdoc_pwarn(m, line, *pos, EARGVPARM)) return(ARGS_ERROR); /* @@ -553,10 +499,10 @@ args(struct mdoc *mdoc, int line, } if (p && 0 == *p) - if ( ! pwarn(mdoc, line, *pos, ECOLEMPTY)) + if ( ! mdoc_pwarn(m, line, *pos, ECOLEMPTY)) return(0); if (p && 0 == *p && p > *v && ' ' == *(p - 1)) - if ( ! pwarn(mdoc, line, *pos, ETAILWS)) + if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(0); if (p) @@ -568,7 +514,7 @@ args(struct mdoc *mdoc, int line, assert(p); if (p > *v && ' ' == *(p - 1)) - if ( ! pwarn(mdoc, line, *pos, ETAILWS)) + if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(0); *pos += (int)(p - *v); @@ -600,7 +546,7 @@ args(struct mdoc *mdoc, int line, if (buf[*pos]) return(ARGS_WORD); - if ( ! pwarn(mdoc, line, *pos, ETAILWS)) + if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); return(ARGS_WORD); @@ -618,7 +564,7 @@ args(struct mdoc *mdoc, int line, (*pos)++; if (0 == buf[*pos]) { - (void)perr(mdoc, line, *pos, EQUOTTERM, 1); + (void)mdoc_perr(m, line, *pos, EQUOTTERM); return(ARGS_ERROR); } @@ -632,7 +578,7 @@ args(struct mdoc *mdoc, int line, if (buf[*pos]) return(ARGS_QWORD); - if ( ! pwarn(mdoc, line, *pos, ETAILWS)) + if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); return(ARGS_QWORD); @@ -738,7 +684,7 @@ argv_a2arg(int tok, const char *argv) static int -argv_multi(struct mdoc *mdoc, int line, +argv_multi(struct mdoc *m, int line, struct mdoc_argv *v, int *pos, char *buf) { int c; @@ -747,7 +693,7 @@ argv_multi(struct mdoc *mdoc, int line, for (v->sz = 0; ; v->sz++) { if ('-' == buf[*pos]) break; - c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p); + c = args(m, line, pos, buf, ARGS_QUOTED, &p); if (ARGS_ERROR == c) return(0); else if (ARGS_EOLN == c) @@ -757,12 +703,12 @@ argv_multi(struct mdoc *mdoc, int line, v->value = realloc(v->value, (v->sz + MULTI_STEP) * sizeof(char *)); if (NULL == v->value) { - (void)verr(mdoc, EMALLOC); + (void)mdoc_nerr(m, m->last, EMALLOC); return(ARGV_ERROR); } } if (NULL == (v->value[(int)v->sz] = strdup(p))) - return(verr(mdoc, EMALLOC)); + return(mdoc_nerr(m, m->last, EMALLOC)); } return(1); @@ -770,7 +716,7 @@ argv_multi(struct mdoc *mdoc, int line, 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) { int c; @@ -779,7 +725,7 @@ argv_opt_single(struct mdoc *mdoc, int line, if ('-' == buf[*pos]) return(1); - c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p); + c = args(m, line, pos, buf, ARGS_QUOTED, &p); if (ARGS_ERROR == c) return(0); if (ARGS_EOLN == c) @@ -787,9 +733,9 @@ argv_opt_single(struct mdoc *mdoc, int line, v->sz = 1; 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))) - return(verr(mdoc, EMALLOC)); + return(mdoc_nerr(m, m->last, EMALLOC)); return(1); } @@ -799,7 +745,7 @@ argv_opt_single(struct mdoc *mdoc, int line, * Parse a single, mandatory value from the stream. */ static int -argv_single(struct mdoc *mdoc, int line, +argv_single(struct mdoc *m, int line, struct mdoc_argv *v, int *pos, char *buf) { int c, ppos; @@ -807,17 +753,17 @@ argv_single(struct mdoc *mdoc, int line, ppos = *pos; - c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p); + c = args(m, line, pos, buf, ARGS_QUOTED, &p); if (ARGS_ERROR == c) return(0); if (ARGS_EOLN == c) - return(perr(mdoc, line, ppos, EARGVAL, 1)); + return(mdoc_perr(m, line, ppos, EARGVAL)); v->sz = 1; 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))) - return(verr(mdoc, EMALLOC)); + return(mdoc_nerr(m, m->last, EMALLOC)); return(1); } |