diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-06-18 10:53:58 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-06-18 10:53:58 +0000 |
commit | 28dbd78db68ddebbe43fda7d4abefd2d6257d286 (patch) | |
tree | b62ef5f6c371aced00114a58b7dac6bc1feb4498 | |
parent | ebc04fb0a062bcf881ac1fbe0706af873a8fcfc8 (diff) | |
download | mandoc-28dbd78db68ddebbe43fda7d4abefd2d6257d286.tar.gz |
Moved all formatted libman warn/error into man.c/libman.h.
Converted all formatted warn/errors into regular syntax.
-rw-r--r-- | libman.h | 20 | ||||
-rw-r--r-- | man.c | 37 | ||||
-rw-r--r-- | man_action.c | 15 | ||||
-rw-r--r-- | man_macro.c | 12 | ||||
-rw-r--r-- | man_validate.c | 30 |
5 files changed, 70 insertions, 44 deletions
@@ -38,8 +38,28 @@ struct man { struct man_meta meta; }; +enum merr { + WNPRINT, + WNMEM, + WMSEC, + WDATE, + WLNSCOPE, + WTSPACE, + WTQUOTE +}; + __BEGIN_DECLS +#define man_perr(m, l, p, t) \ + man_err((m), l, p, 1, (t)) +#define man_pwarn(m, l, p, t) \ + man_err((m), l, p, 0, (t)) +#define man_nerr(m, n, t) \ + man_err((m), (n)->line, (n)->pos, 1, (t)) +#define man_nwarn(m, n, t) \ + man_err((m), (n)->line, (n)->pos, 0, (t)) + +int man_err(struct man *, int, int, int, enum merr); int man_word_alloc(struct man *, int, int, const char *); int man_elem_alloc(struct man *, int, int, int); void man_node_free(struct man_node *); @@ -434,3 +434,40 @@ man_vwarn(struct man *man, int ln, int pos, const char *fmt, ...) } +int +man_err(struct man *m, int line, int pos, + int iserr, enum merr type) +{ + const char *p; + + p = NULL; + switch (type) { + case (WNPRINT): + p = "invalid character"; + break; + case (WNMEM): + p = "memory exhausted"; + break; + case (WMSEC): + p = "invalid manual section"; + break; + case (WDATE): + p = "invalid date format"; + break; + case (WLNSCOPE): + p = "scope of prior line violated"; + break; + case (WTSPACE): + p = "trailing whitespace at end of line"; + break; + case (WTQUOTE): + p = "unterminated quotation"; + break; + } + assert(p); + + if (iserr) + return(man_verr(m, line, pos, p)); + + return(man_vwarn(m, line, pos, p)); +} diff --git a/man_action.c b/man_action.c index 3d8d784a..1bb775f3 100644 --- a/man_action.c +++ b/man_action.c @@ -108,8 +108,7 @@ post_TH(struct man *m) assert(n); if (NULL == (m->meta.title = strdup(n->string))) - return(man_verr(m, n->line, n->pos, - "memory exhausted")); + return(man_nerr(m, n, WNMEM)); /* TITLE ->MSEC<- DATE SOURCE VOL */ @@ -120,7 +119,7 @@ post_TH(struct man *m) lval = strtol(n->string, &ep, 10); if (n->string[0] != '\0' && *ep == '\0') m->meta.msec = (int)lval; - else if ( ! man_vwarn(m, n->line, n->pos, "invalid section")) + else if ( ! man_nwarn(m, n, WMSEC)) return(0); /* TITLE MSEC ->DATE<- SOURCE VOL */ @@ -128,7 +127,7 @@ post_TH(struct man *m) if (NULL == (n = n->next)) m->meta.date = time(NULL); else if (0 == (m->meta.date = man_atotime(n->string))) { - if ( ! man_vwarn(m, n->line, n->pos, "invalid date")) + if ( ! man_nwarn(m, n, WDATE)) return(0); m->meta.date = time(NULL); } @@ -137,15 +136,13 @@ post_TH(struct man *m) if (n && (n = n->next)) if (NULL == (m->meta.source = strdup(n->string))) - return(man_verr(m, n->line, n->pos, - "memory exhausted")); + return(man_nerr(m, n, WNMEM)); /* TITLE MSEC DATE SOURCE ->VOL<- */ if (n && (n = n->next)) if (NULL == (m->meta.vol = strdup(n->string))) - return(man_verr(m, n->line, n->pos, - "memory exhausted")); + return(man_nerr(m, n, WNMEM)); /* * The end document shouldn't have the prologue macros as part @@ -178,7 +175,7 @@ man_atotime(const char *p) struct tm tm; char *pp; - (void)memset(&tm, 0, sizeof(struct tm)); + bzero(&tm, sizeof(struct tm)); if ((pp = strptime(p, "%b %d %Y", &tm)) && 0 == *pp) return(mktime(&tm)); diff --git a/man_macro.c b/man_macro.c index 80949fae..df723e5e 100644 --- a/man_macro.c +++ b/man_macro.c @@ -82,16 +82,14 @@ man_macro(struct man *man, int tok, int line, if (n == man->last && (FL_NLINE & man_flags[tok])) { if (MAN_NLINE & man->flags) - return(man_verr(man, line, ppos, - "next-line scope already open")); + return(man_perr(man, line, ppos, WLNSCOPE)); man->flags |= MAN_NLINE; return(1); } if (FL_TLINE & man_flags[tok]) { if (MAN_NLINE & man->flags) - return(man_verr(man, line, ppos, - "next-line scope already open")); + return(man_perr(man, line, ppos, WLNSCOPE)); man->flags |= MAN_NLINE; return(1); } @@ -186,7 +184,7 @@ man_args(struct man *m, int line, if (buf[*pos]) return(1); - if ( ! man_vwarn(m, line, *pos, "trailing spaces")) + if ( ! man_pwarn(m, line, *pos, WTSPACE)) return(-1); return(1); @@ -204,7 +202,7 @@ man_args(struct man *m, int line, (*pos)++; if (0 == buf[*pos]) { - if ( ! man_vwarn(m, line, *pos, "unterminated quote")) + if ( ! man_pwarn(m, line, *pos, WTQUOTE)) return(-1); return(1); } @@ -219,7 +217,7 @@ man_args(struct man *m, int line, if (buf[*pos]) return(1); - if ( ! man_vwarn(m, line, *pos, "trailing spaces")) + if ( ! man_pwarn(m, line, *pos, WTSPACE)) return(-1); return(1); } diff --git a/man_validate.c b/man_validate.c index 24081eb8..c47a3a07 100644 --- a/man_validate.c +++ b/man_validate.c @@ -25,10 +25,6 @@ #define POSTARGS struct man *m, const struct man_node *n -enum merr { - WPRINT -}; - typedef int (*v_post)(POSTARGS); struct man_valid { @@ -42,7 +38,6 @@ static int check_le1(POSTARGS); static int check_le2(POSTARGS); static int check_le5(POSTARGS); static int check_text(POSTARGS); -static int perr(struct man *, int, int, int, enum merr); static v_post posts_le1[] = { check_le1, NULL }; static v_post posts_le2[] = { check_le2, NULL }; @@ -106,27 +101,6 @@ man_valid_post(struct man *m) static int -perr(struct man *m, int line, int pos, - int iserr, enum merr type) -{ - const char *p; - - p = NULL; - switch (type) { - case (WPRINT): - p = "invalid character"; - break; - } - assert(p); - - if (iserr) - return(man_verr(m, line, pos, p)); - - return(man_vwarn(m, line, pos, p)); -} - - -static int check_text(POSTARGS) { const char *p; @@ -139,8 +113,8 @@ check_text(POSTARGS) continue; if (MAN_IGN_CHARS & m->pflags) - return(perr(m, n->line, pos, 0, WPRINT)); - return(perr(m, n->line, pos, 1, WPRINT)); + return(man_pwarn(m, n->line, pos, WNPRINT)); + return(man_perr(m, n->line, pos, WNPRINT)); } return(1); |