=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.325 retrieving revision 1.329 diff -u -p -r1.325 -r1.329 --- mandoc/mdoc_validate.c 2017/05/05 13:17:55 1.325 +++ mandoc/mdoc_validate.c 2017/05/31 15:31:00 1.329 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.325 2017/05/05 13:17:55 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.329 2017/05/31 15:31:00 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -53,6 +53,7 @@ typedef void (*v_post)(POST_ARGS); static int build_list(struct roff_man *, int); static void check_text(struct roff_man *, int, int, char *); +static void check_bsd(struct roff_man *, int, int, char *); static void check_argv(struct roff_man *, struct roff_node *, struct mdoc_argv *); static void check_args(struct roff_man *, struct roff_node *); @@ -105,6 +106,7 @@ static void post_sh_authors(POST_ARGS); static void post_sm(POST_ARGS); static void post_st(POST_ARGS); static void post_std(POST_ARGS); +static void post_useless(POST_ARGS); static void post_xr(POST_ARGS); static void post_xx(POST_ARGS); @@ -201,7 +203,7 @@ static const v_post __mdoc_valids[MDOC_MAX - MDOC_Dd] post_sm, /* Sm */ post_hyph, /* Sx */ NULL, /* Sy */ - NULL, /* Tn */ + post_useless, /* Tn */ post_xx, /* Ux */ NULL, /* Xc */ NULL, /* Xo */ @@ -227,7 +229,6 @@ static const v_post __mdoc_valids[MDOC_MAX - MDOC_Dd] post_en, /* En */ post_xx, /* Dx */ NULL, /* %Q */ - post_par, /* sp */ NULL, /* %U */ NULL, /* Ta */ }; @@ -302,6 +303,10 @@ mdoc_node_validate(struct roff_man *mdoc) if (n->sec != SEC_SYNOPSIS || (n->parent->tok != MDOC_Cd && n->parent->tok != MDOC_Fd)) check_text(mdoc, n->line, n->pos, n->string); + if (n->parent->tok == MDOC_Sh || + n->parent->tok == MDOC_Ss || + n->parent->tok == MDOC_It) + check_bsd(mdoc, n->line, n->pos, n->string); break; case ROFFT_EQN: case ROFFT_TBL: @@ -328,6 +333,7 @@ mdoc_node_validate(struct roff_man *mdoc) if (n->tok < ROFF_MAX) { switch(n->tok) { case ROFF_br: + case ROFF_sp: post_par(mdoc); break; default: @@ -383,6 +389,25 @@ check_text(struct roff_man *mdoc, int ln, int pos, cha } static void +check_bsd(struct roff_man *mdoc, int ln, int pos, char *p) +{ + const char *cp; + + if ((cp = strstr(p, "OpenBSD")) != NULL) + mandoc_msg(MANDOCERR_BX, mdoc->parse, + ln, pos + (cp - p), "Ox"); + if ((cp = strstr(p, "NetBSD")) != NULL) + mandoc_msg(MANDOCERR_BX, mdoc->parse, + ln, pos + (cp - p), "Nx"); + if ((cp = strstr(p, "FreeBSD")) != NULL) + mandoc_msg(MANDOCERR_BX, mdoc->parse, + ln, pos + (cp - p), "Fx"); + if ((cp = strstr(p, "DragonFly")) != NULL) + mandoc_msg(MANDOCERR_BX, mdoc->parse, + ln, pos + (cp - p), "Dx"); +} + +static void post_bl_norm(POST_ARGS) { struct roff_node *n; @@ -671,6 +696,7 @@ post_eoln(POST_ARGS) { struct roff_node *n; + post_useless(mdoc); n = mdoc->last; if (n->child != NULL) mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse, n->line, @@ -866,6 +892,16 @@ post_obsolete(POST_ARGS) n->line, n->pos, roff_name[n->tok]); } +static void +post_useless(POST_ARGS) +{ + struct roff_node *n; + + n = mdoc->last; + mandoc_msg(MANDOCERR_MACRO_USELESS, mdoc->parse, + n->line, n->pos, roff_name[n->tok]); +} + /* * Block macros. */ @@ -1879,7 +1915,7 @@ post_sh_see_also(POST_ARGS) if (isalpha((const unsigned char)*name)) return; lastpunct = n->string; - if (n->next == NULL) + if (n->next == NULL || n->next->tok == MDOC_Rs) mandoc_vmsg(MANDOCERR_XR_PUNCT, mdoc->parse, n->line, n->pos, "%s after %s(%s)", lastpunct, lastname, lastsec); @@ -2096,10 +2132,10 @@ post_par(POST_ARGS) struct roff_node *np; np = mdoc->last; - if (np->tok != ROFF_br && np->tok != MDOC_sp) + if (np->tok != ROFF_br && np->tok != ROFF_sp) post_prevpar(mdoc); - if (np->tok == MDOC_sp) { + if (np->tok == ROFF_sp) { if (np->child != NULL && np->child->next != NULL) mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, np->child->next->line, np->child->next->pos, @@ -2115,7 +2151,7 @@ post_par(POST_ARGS) return; } else if (np->tok != MDOC_Pp && np->tok != MDOC_Lp && (mdoc->last->tok != ROFF_br || - (np->tok != MDOC_sp && np->tok != ROFF_br))) + (np->tok != ROFF_sp && np->tok != ROFF_br))) return; mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse, @@ -2264,11 +2300,19 @@ static void post_bx(POST_ARGS) { struct roff_node *n, *nch; + const char *macro; n = mdoc->last; nch = n->child; if (nch != NULL) { + macro = !strcmp(nch->string, "Open") ? "Ox" : + !strcmp(nch->string, "Net") ? "Nx" : + !strcmp(nch->string, "Free") ? "Fx" : + !strcmp(nch->string, "DragonFly") ? "Dx" : NULL; + if (macro != NULL) + mandoc_msg(MANDOCERR_BX, mdoc->parse, + n->line, n->pos, macro); mdoc->last = nch; nch = nch->next; mdoc->next = ROFF_NEXT_SIBLING;