=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.212 retrieving revision 1.217 diff -u -p -r1.212 -r1.217 --- mandoc/mdoc_validate.c 2014/04/20 20:48:53 1.212 +++ mandoc/mdoc_validate.c 2014/07/01 22:37:15 1.217 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.212 2014/04/20 20:48:53 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.217 2014/07/01 22:37:15 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -935,10 +935,12 @@ pre_dt(PRE_ARGS) { if (NULL == mdoc->meta.date || mdoc->meta.os) - mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO); + mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse, + n->line, n->pos, "Dt"); if (mdoc->meta.title) - mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP); + mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse, + n->line, n->pos, "Dt"); return(1); } @@ -948,10 +950,12 @@ pre_os(PRE_ARGS) { if (NULL == mdoc->meta.title || NULL == mdoc->meta.date) - mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO); + mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse, + n->line, n->pos, "Os"); if (mdoc->meta.os) - mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP); + mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse, + n->line, n->pos, "Os"); return(1); } @@ -961,10 +965,12 @@ pre_dd(PRE_ARGS) { if (mdoc->meta.title || mdoc->meta.os) - mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO); + mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse, + n->line, n->pos, "Dd"); if (mdoc->meta.date) - mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP); + mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse, + n->line, n->pos, "Dd"); return(1); } @@ -1183,9 +1189,9 @@ post_defaults(POST_ARGS) static int post_at(POST_ARGS) { - const char *p, *q; - char *buf; - size_t sz; + struct mdoc_node *n; + const char *std_att; + char *att; /* * If we have a child, look it up in the standard keys. If a @@ -1193,27 +1199,18 @@ post_at(POST_ARGS) * prefix "AT&T UNIX " to the existing data. */ - if (NULL == mdoc->last->child) + if (NULL == (n = mdoc->last->child)) return(1); - assert(MDOC_TEXT == mdoc->last->child->type); - p = mdoc_a2att(mdoc->last->child->string); - - if (p) { - free(mdoc->last->child->string); - mdoc->last->child->string = mandoc_strdup(p); - } else { + assert(MDOC_TEXT == n->type); + if (NULL == (std_att = mdoc_a2att(n->string))) { mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADATT); - p = "AT&T UNIX "; - q = mdoc->last->child->string; - sz = strlen(p) + strlen(q) + 1; - buf = mandoc_malloc(sz); - strlcpy(buf, p, sz); - strlcat(buf, q, sz); - free(mdoc->last->child->string); - mdoc->last->child->string = buf; - } + mandoc_asprintf(&att, "AT&T UNIX %s", n->string); + } else + att = mandoc_strdup(std_att); + free(n->string); + n->string = att; return(1); } @@ -1469,8 +1466,8 @@ post_bl_block_tag(POST_ARGS) assert(n->args); i = (int)(n->args->argc)++; - n->args->argv = mandoc_realloc(n->args->argv, - n->args->argc * sizeof(struct mdoc_argv)); + n->args->argv = mandoc_reallocarray(n->args->argv, + n->args->argc, sizeof(struct mdoc_argv)); n->args->argv[i].arg = MDOC_Width; n->args->argv[i].line = n->line; @@ -1530,8 +1527,8 @@ post_bl_head(POST_ARGS) */ np->args->argv[j].sz = (size_t)mdoc->last->nchild; - np->args->argv[j].value = mandoc_malloc( - (size_t)mdoc->last->nchild * sizeof(char *)); + np->args->argv[j].value = mandoc_reallocarray(NULL, + (size_t)mdoc->last->nchild, sizeof(char *)); mdoc->last->norm->Bl.ncols = np->args->argv[j].sz; mdoc->last->norm->Bl.cols = (void *)np->args->argv[j].value; @@ -1654,15 +1651,15 @@ ebool(struct mdoc *mdoc) static int post_root(POST_ARGS) { - int erc; + int ret; struct mdoc_node *n; - erc = 0; + ret = 1; /* Check that we have a finished prologue. */ if ( ! (MDOC_PBODY & mdoc->flags)) { - erc++; + ret = 0; mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG); } @@ -1671,17 +1668,14 @@ post_root(POST_ARGS) /* Check that we begin with a proper `Sh'. */ - if (NULL == n->child) { - erc++; - mdoc_nmsg(mdoc, n, MANDOCERR_NODOCBODY); - } else if (MDOC_BLOCK != n->child->type || - MDOC_Sh != n->child->tok) { - erc++; - /* Can this be lifted? See rxdebug.1 for example. */ - mdoc_nmsg(mdoc, n, MANDOCERR_NODOCBODY); - } + if (NULL == n->child) + mdoc_nmsg(mdoc, n, MANDOCERR_DOC_EMPTY); + else if (MDOC_Sh != n->child->tok) + mandoc_msg(MANDOCERR_SEC_BEFORE, mdoc->parse, + n->child->line, n->child->pos, + mdoc_macronames[n->child->tok]); - return(erc ? 0 : 1); + return(ret); } static int @@ -1902,7 +1896,8 @@ post_sh_body(POST_ARGS) */ if (NULL == (n = mdoc->last->child)) { - mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC); + mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, + mdoc->last->line, mdoc->last->pos, "empty"); return(1); } @@ -1911,14 +1906,16 @@ post_sh_body(POST_ARGS) continue; if (MDOC_TEXT == n->type) continue; - mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC); + mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, + n->line, n->pos, mdoc_macronames[n->tok]); } assert(n); if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok) return(1); - mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC); + mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse, + n->line, n->pos, mdoc_macronames[n->tok]); return(1); } @@ -1926,6 +1923,7 @@ static int post_sh_head(POST_ARGS) { struct mdoc_node *n; + const char *goodsec; char *secname; enum mdoc_sec sec; @@ -1944,7 +1942,8 @@ post_sh_head(POST_ARGS) /* The NAME should be first. */ if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed) - mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NAMESECFIRST); + mandoc_msg(MANDOCERR_NAMESEC_FIRST, mdoc->parse, + mdoc->last->line, mdoc->last->pos, secname); /* The SYNOPSIS gets special attention in other areas. */ @@ -1987,10 +1986,12 @@ post_sh_head(POST_ARGS) */ if (sec == mdoc->lastnamed) - mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECREP); + mandoc_msg(MANDOCERR_SEC_REP, mdoc->parse, + mdoc->last->line, mdoc->last->pos, secname); if (sec < mdoc->lastnamed) - mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECOOO); + mandoc_msg(MANDOCERR_SEC_ORDER, mdoc->parse, + mdoc->last->line, mdoc->last->pos, secname); /* Mark the last named section. */ @@ -2000,10 +2001,12 @@ post_sh_head(POST_ARGS) assert(mdoc->meta.msec); + goodsec = NULL; switch (sec) { case SEC_ERRORS: if (*mdoc->meta.msec == '4') break; + goodsec = "2, 3, 4, 9"; /* FALLTHROUGH */ case SEC_RETURN_VALUES: /* FALLTHROUGH */ @@ -2012,12 +2015,17 @@ post_sh_head(POST_ARGS) break; if (*mdoc->meta.msec == '3') break; + if (NULL == goodsec) + goodsec = "2, 3, 9"; /* FALLTHROUGH */ case SEC_CONTEXT: if (*mdoc->meta.msec == '9') break; - mandoc_msg(MANDOCERR_SECMSEC, mdoc->parse, - mdoc->last->line, mdoc->last->pos, secname); + if (NULL == goodsec) + goodsec = "9"; + mandoc_vmsg(MANDOCERR_SEC_MSEC, mdoc->parse, + mdoc->last->line, mdoc->last->pos, + "%s for %s only", secname, goodsec); break; default: break; @@ -2182,18 +2190,16 @@ post_dt(POST_ARGS) mdoc->meta.title = mdoc->meta.vol = mdoc->meta.arch = NULL; - /* First make all characters uppercase. */ + /* First check that all characters are uppercase. */ if (NULL != (nn = n->child)) for (p = nn->string; *p; p++) { if (toupper((unsigned char)*p) == *p) continue; - - /* - * FIXME: don't be lazy: have this make all - * characters be uppercase and just warn once. - */ - mdoc_nmsg(mdoc, nn, MANDOCERR_UPPERCASE); + mandoc_msg(MANDOCERR_TITLE_CASE, + mdoc->parse, nn->line, + nn->pos + (p - nn->string), + nn->string); break; } @@ -2237,7 +2243,8 @@ post_dt(POST_ARGS) mdoc->meta.vol = mandoc_strdup(cp); mdoc->meta.msec = mandoc_strdup(nn->string); } else { - mdoc_nmsg(mdoc, n, MANDOCERR_BADMSEC); + mandoc_msg(MANDOCERR_MSEC_BAD, mdoc->parse, + nn->line, nn->pos, nn->string); mdoc->meta.vol = mandoc_strdup(nn->string); mdoc->meta.msec = mandoc_strdup(nn->string); } @@ -2259,7 +2266,8 @@ post_dt(POST_ARGS) } else { cp = mdoc_a2arch(nn->string); if (NULL == cp) { - mdoc_nmsg(mdoc, nn, MANDOCERR_BADVOLARCH); + mandoc_msg(MANDOCERR_ARCH_BAD, mdoc->parse, + nn->line, nn->pos, nn->string); free(mdoc->meta.vol); mdoc->meta.vol = mandoc_strdup(nn->string); } else