=================================================================== RCS file: /cvs/mandoc/man_validate.c,v retrieving revision 1.104 retrieving revision 1.113 diff -u -p -r1.104 -r1.113 --- mandoc/man_validate.c 2014/08/01 21:24:17 1.104 +++ mandoc/man_validate.c 2015/02/06 11:54:36 1.113 @@ -1,7 +1,7 @@ -/* $Id: man_validate.c,v 1.104 2014/08/01 21:24:17 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.113 2015/02/06 11:54:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze + * Copyright (c) 2010, 2012-2015 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,9 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include @@ -38,27 +36,23 @@ #define CHKARGS struct man *man, struct man_node *n -typedef int (*v_check)(CHKARGS); +typedef void (*v_check)(CHKARGS); -static int check_eq0(CHKARGS); -static int check_eq2(CHKARGS); -static int check_le1(CHKARGS); -static int check_ge2(CHKARGS); -static int check_le5(CHKARGS); -static int check_par(CHKARGS); -static int check_part(CHKARGS); -static int check_root(CHKARGS); -static int check_text(CHKARGS); +static void check_par(CHKARGS); +static void check_part(CHKARGS); +static void check_root(CHKARGS); +static void check_text(CHKARGS); -static int post_AT(CHKARGS); -static int post_IP(CHKARGS); -static int post_vs(CHKARGS); -static int post_fi(CHKARGS); -static int post_ft(CHKARGS); -static int post_nf(CHKARGS); -static int post_TH(CHKARGS); -static int post_UC(CHKARGS); -static int post_UR(CHKARGS); +static void post_AT(CHKARGS); +static void post_IP(CHKARGS); +static void post_vs(CHKARGS); +static void post_fi(CHKARGS); +static void post_ft(CHKARGS); +static void post_nf(CHKARGS); +static void post_OP(CHKARGS); +static void post_TH(CHKARGS); +static void post_UC(CHKARGS); +static void post_UR(CHKARGS); static v_check man_valids[MAN_MAX] = { post_vs, /* br */ @@ -82,7 +76,6 @@ static v_check man_valids[MAN_MAX] = { NULL, /* I */ NULL, /* IR */ NULL, /* RI */ - check_eq0, /* na */ post_vs, /* sp */ post_nf, /* nf */ post_fi, /* fi */ @@ -90,11 +83,11 @@ static v_check man_valids[MAN_MAX] = { check_part, /* RS */ NULL, /* DT */ post_UC, /* UC */ - check_le1, /* PD */ + NULL, /* PD */ post_AT, /* AT */ NULL, /* in */ post_ft, /* ft */ - check_eq2, /* OP */ + post_OP, /* OP */ post_nf, /* EX */ post_fi, /* EE */ post_UR, /* UR */ @@ -103,7 +96,7 @@ static v_check man_valids[MAN_MAX] = { }; -int +void man_valid_post(struct man *man) { struct man_node *n; @@ -111,25 +104,29 @@ man_valid_post(struct man *man) n = man->last; if (n->flags & MAN_VALID) - return(1); + return; n->flags |= MAN_VALID; switch (n->type) { case MAN_TEXT: - return(check_text(man, n)); + check_text(man, n); + break; case MAN_ROOT: - return(check_root(man, n)); + check_root(man, n); + break; case MAN_EQN: /* FALLTHROUGH */ case MAN_TBL: - return(1); + break; default: cp = man_valids + n->tok; - return(*cp ? (*cp)(man, n) : 1); + if (*cp) + (*cp)(man, n); + break; } } -static int +static void check_root(CHKARGS) { @@ -142,7 +139,7 @@ check_root(CHKARGS) man->meta.hasbody = 1; if (NULL == man->meta.title) { - mandoc_msg(MANDOCERR_TH_MISSING, man->parse, + mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse, n->line, n->pos, NULL); /* @@ -150,67 +147,59 @@ check_root(CHKARGS) * implication, date and section also aren't set). */ - man->meta.title = mandoc_strdup("unknown"); - man->meta.msec = mandoc_strdup("1"); + man->meta.title = mandoc_strdup(""); + man->meta.msec = mandoc_strdup(""); man->meta.date = man->quick ? mandoc_strdup("") : mandoc_normdate(man->parse, NULL, n->line, n->pos); } - - return(1); } -static int +static void check_text(CHKARGS) { char *cp, *p; if (MAN_LITERAL & man->flags) - return(1); + return; cp = n->string; for (p = cp; NULL != (p = strchr(p, '\t')); p++) mandoc_msg(MANDOCERR_FI_TAB, man->parse, n->line, n->pos + (p - cp), NULL); - return(1); } -#define INEQ_DEFINE(x, ineq, name) \ -static int \ -check_##name(CHKARGS) \ -{ \ - if (n->nchild ineq (x)) \ - return(1); \ - mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \ - "line arguments %s %d (have %d)", \ - #ineq, (x), n->nchild); \ - return(1); \ +static void +post_OP(CHKARGS) +{ + + if (n->nchild == 0) + mandoc_msg(MANDOCERR_OP_EMPTY, man->parse, + n->line, n->pos, "OP"); + else if (n->nchild > 2) { + n = n->child->next->next; + mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, + n->line, n->pos, "OP ... %s", n->string); + } } -INEQ_DEFINE(0, ==, eq0) -INEQ_DEFINE(2, ==, eq2) -INEQ_DEFINE(1, <=, le1) -INEQ_DEFINE(2, >=, ge2) -INEQ_DEFINE(5, <=, le5) - -static int +static void post_UR(CHKARGS) { - if (MAN_HEAD == n->type && 1 != n->nchild) - mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, - n->pos, "line arguments eq 1 (have %d)", n->nchild); - - return(check_part(man, n)); + if (n->type == MAN_HEAD && n->child == NULL) + mandoc_vmsg(MANDOCERR_UR_NOHEAD, man->parse, + n->line, n->pos, "UR"); + check_part(man, n); } -static int +static void post_ft(CHKARGS) { char *cp; int ok; if (0 == n->nchild) - return(1); + return; ok = 0; cp = n->child->string; @@ -248,26 +237,18 @@ post_ft(CHKARGS) n->line, n->pos, "ft %s", cp); *cp = '\0'; } - - if (1 < n->nchild) - mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, - n->pos, "want one child (have %d)", n->nchild); - - return(1); } -static int +static void check_part(CHKARGS) { - if (MAN_BODY == n->type && 0 == n->nchild) - mandoc_msg(MANDOCERR_ARGCWARN, man->parse, n->line, - n->pos, "want children (have none)"); - - return(1); + if (n->type == MAN_BODY && n->child == NULL) + mandoc_msg(MANDOCERR_BLK_EMPTY, man->parse, + n->line, n->pos, man_macronames[n->tok]); } -static int +static void check_par(CHKARGS) { @@ -293,11 +274,9 @@ check_par(CHKARGS) default: break; } - - return(1); } -static int +static void post_IP(CHKARGS) { @@ -315,18 +294,14 @@ post_IP(CHKARGS) default: break; } - return(1); } -static int +static void post_TH(CHKARGS) { struct man_node *nb; const char *p; - check_ge2(man, n); - check_le5(man, n); - free(man->meta.title); free(man->meta.vol); free(man->meta.source); @@ -354,8 +329,11 @@ post_TH(CHKARGS) } } man->meta.title = mandoc_strdup(n->string); - } else + } else { man->meta.title = mandoc_strdup(""); + mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse, + nb->line, nb->pos, "TH"); + } /* TITLE ->MSEC<- DATE SOURCE VOL */ @@ -363,8 +341,11 @@ post_TH(CHKARGS) n = n->next; if (n && n->string) man->meta.msec = mandoc_strdup(n->string); - else + else { man->meta.msec = mandoc_strdup(""); + mandoc_vmsg(MANDOCERR_MSEC_MISSING, man->parse, + nb->line, nb->pos, "TH %s", man->meta.title); + } /* TITLE MSEC ->DATE<- SOURCE VOL */ @@ -386,6 +367,8 @@ post_TH(CHKARGS) if (n && (n = n->next)) man->meta.source = mandoc_strdup(n->string); + else if (man->defos != NULL) + man->meta.source = mandoc_strdup(man->defos); /* TITLE MSEC DATE SOURCE ->VOL<- */ /* If missing, use the default VOL name for MSEC. */ @@ -396,43 +379,40 @@ post_TH(CHKARGS) (NULL != (p = mandoc_a2msec(man->meta.msec)))) man->meta.vol = mandoc_strdup(p); + if (n != NULL && (n = n->next) != NULL) + mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, + n->line, n->pos, "TH ... %s", n->string); + /* * Remove the `TH' node after we've processed it for our * meta-data. */ man_node_delete(man, man->last); - return(1); } -static int +static void post_nf(CHKARGS) { - check_eq0(man, n); - - if (MAN_LITERAL & man->flags) + if (man->flags & MAN_LITERAL) mandoc_msg(MANDOCERR_NF_SKIP, man->parse, n->line, n->pos, "nf"); man->flags |= MAN_LITERAL; - return(1); } -static int +static void post_fi(CHKARGS) { - check_eq0(man, n); - if ( ! (MAN_LITERAL & man->flags)) mandoc_msg(MANDOCERR_FI_SKIP, man->parse, n->line, n->pos, "fi"); man->flags &= ~MAN_LITERAL; - return(1); } -static int +static void post_UC(CHKARGS) { static const char * const bsd_versions[] = { @@ -467,10 +447,9 @@ post_UC(CHKARGS) free(man->meta.source); man->meta.source = mandoc_strdup(p); - return(1); } -static int +static void post_AT(CHKARGS) { static const char * const unix_versions[] = { @@ -505,20 +484,14 @@ post_AT(CHKARGS) free(man->meta.source); man->meta.source = mandoc_strdup(p); - return(1); } -static int +static void post_vs(CHKARGS) { - if (n->tok == MAN_br) - check_eq0(man, n); - else - check_le1(man, n); - if (NULL != n->prev) - return(1); + return; switch (n->parent->tok) { case MAN_SH: @@ -538,6 +511,4 @@ post_vs(CHKARGS) default: break; } - - return(1); }