=================================================================== RCS file: /cvs/mandoc/man_validate.c,v retrieving revision 1.57 retrieving revision 1.60 diff -u -p -r1.57 -r1.60 --- mandoc/man_validate.c 2011/01/01 12:59:17 1.57 +++ mandoc/man_validate.c 2011/01/17 00:21:29 1.60 @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.57 2011/01/01 12:59:17 kristaps Exp $ */ +/* $Id: man_validate.c,v 1.60 2011/01/17 00:21:29 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -53,7 +53,6 @@ static int check_part(CHKARGS); static int check_root(CHKARGS); static int check_sec(CHKARGS); static int check_text(CHKARGS); -static int check_title(CHKARGS); static int post_AT(CHKARGS); static int post_fi(CHKARGS); @@ -70,7 +69,7 @@ static v_check posts_nf[] = { check_eq0, post_nf, NU static v_check posts_par[] = { check_par, NULL }; static v_check posts_part[] = { check_part, NULL }; static v_check posts_sec[] = { check_sec, NULL }; -static v_check posts_th[] = { check_ge2, check_le5, check_title, post_TH, NULL }; +static v_check posts_th[] = { check_ge2, check_le5, post_TH, NULL }; static v_check posts_uc[] = { post_UC, NULL }; static v_check pres_bline[] = { check_bline, NULL }; @@ -80,12 +79,12 @@ static const struct man_valid man_valids[MAN_MAX] = { { pres_bline, posts_th }, /* TH */ { pres_bline, posts_sec }, /* SH */ { pres_bline, posts_sec }, /* SS */ - { pres_bline, posts_par }, /* TP */ + { pres_bline, NULL }, /* TP */ { pres_bline, posts_par }, /* LP */ { pres_bline, posts_par }, /* PP */ { pres_bline, posts_par }, /* P */ - { pres_bline, posts_par }, /* IP */ - { pres_bline, posts_par }, /* HP */ + { pres_bline, NULL }, /* IP */ + { pres_bline, NULL }, /* HP */ { NULL, NULL }, /* SM */ { NULL, NULL }, /* SB */ { NULL, NULL }, /* BI */ @@ -200,29 +199,6 @@ check_root(CHKARGS) static int -check_title(CHKARGS) -{ - const char *p; - - assert(n->child); - /* FIXME: is this sufficient? */ - if ('\0' == *n->child->string) { - man_nmsg(m, n, MANDOCERR_SYNTARGCOUNT); - return(0); - } - - for (p = n->child->string; '\0' != *p; p++) - /* Only warn about this once... */ - if (isalpha((u_char)*p) && ! isupper((u_char)*p)) { - man_nmsg(m, n, MANDOCERR_UPPERCASE); - break; - } - - return(1); -} - - -static int check_text(CHKARGS) { char *p; @@ -266,10 +242,10 @@ check_##name(CHKARGS) \ { \ if (n->nchild ineq (x)) \ return(1); \ - man_vmsg(m, MANDOCERR_SYNTARGCOUNT, n->line, n->pos, \ + man_vmsg(m, MANDOCERR_ARGCOUNT, n->line, n->pos, \ "line arguments %s %d (have %d)", \ #ineq, (x), n->nchild); \ - return(0); \ + return(1); \ } INEQ_DEFINE(0, ==, eq0) @@ -359,33 +335,22 @@ static int check_par(CHKARGS) { - if (MAN_BODY == n->type) - switch (n->tok) { - case (MAN_IP): - /* FALLTHROUGH */ - case (MAN_HP): - /* FALLTHROUGH */ - case (MAN_TP): - /* Body-less lists are ok. */ - break; - default: - if (0 == n->nchild) - man_nmsg(m, n, MANDOCERR_NOBODY); - break; - } - if (MAN_HEAD == n->type) - switch (n->tok) { - case (MAN_PP): - /* FALLTHROUGH */ - case (MAN_P): - /* FALLTHROUGH */ - case (MAN_LP): - if (n->nchild) - man_nmsg(m, n, MANDOCERR_ARGSLOST); - break; - default: - break; - } + switch (n->type) { + case (MAN_BLOCK): + if (0 == n->body->nchild) + man_node_delete(m, n); + break; + case (MAN_BODY): + if (0 == n->nchild) + man_nmsg(m, n, MANDOCERR_IGNPAR); + break; + case (MAN_HEAD): + if (n->nchild) + man_nmsg(m, n, MANDOCERR_ARGSLOST); + break; + default: + break; + } return(1); } @@ -407,6 +372,7 @@ check_bline(CHKARGS) static int post_TH(CHKARGS) { + const char *p; if (m->meta.title) free(m->meta.title); @@ -426,14 +392,26 @@ post_TH(CHKARGS) /* ->TITLE<- MSEC DATE SOURCE VOL */ n = n->child; - assert(n); - m->meta.title = mandoc_strdup(n->string); + if (n && n->string) { + for (p = n->string; '\0' != *p; p++) { + /* Only warn about this once... */ + if (isalpha((u_char)*p) && ! isupper((u_char)*p)) { + man_nmsg(m, n, MANDOCERR_UPPERCASE); + break; + } + } + m->meta.title = mandoc_strdup(n->string); + } else + m->meta.title = mandoc_strdup(""); /* TITLE ->MSEC<- DATE SOURCE VOL */ - n = n->next; - assert(n); - m->meta.msec = mandoc_strdup(n->string); + if (n) + n = n->next; + if (n && n->string) + m->meta.msec = mandoc_strdup(n->string); + else + m->meta.msec = mandoc_strdup(""); /* TITLE MSEC ->DATE<- SOURCE VOL */ @@ -444,7 +422,8 @@ post_TH(CHKARGS) * string, then use the current date. */ - n = n->next; + if (n) + n = n->next; if (n && n->string && *n->string) { m->meta.date = mandoc_a2time (MTIME_ISO_8601, n->string); @@ -489,7 +468,7 @@ post_fi(CHKARGS) { if ( ! (MAN_LITERAL & m->flags)) - man_nmsg(m, n, MANDOCERR_NOSCOPE); + man_nmsg(m, n, MANDOCERR_WNOSCOPE); m->flags &= ~MAN_LITERAL; return(1);