diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2017-05-31 15:31:00 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2017-05-31 15:31:00 +0000 |
commit | 97d9e8867b464b881cf5d4f88296991990492d49 (patch) | |
tree | 8cdae68a9a911fdb7764094619a2a3425e5c06c1 | |
parent | c7f610a9114ad98bda15eb653ca89a1db958ddd7 (diff) | |
download | mandoc-97d9e8867b464b881cf5d4f88296991990492d49.tar.gz |
STYLE message about missing use of Ox/Nx/Fx/Dx; OK jmc@ wiz@
-rw-r--r-- | mandoc.1 | 10 | ||||
-rw-r--r-- | mandoc.h | 1 | ||||
-rw-r--r-- | mdoc_validate.c | 32 | ||||
-rw-r--r-- | read.c | 1 |
4 files changed, 44 insertions, 0 deletions
@@ -753,6 +753,16 @@ or .Ic \&Ud macro was found. Simply delete it: it serves no useful purpose. +.It Sy "consider using OS macro" +.Pq mdoc +A string was found in plain text or in a +.Ic \&Bx +macro that could be represented using +.Ic \&Ox , +.Ic \&Nx , +.Ic \&Fx , +or +.Ic \&Dx . .El .Ss Warnings related to the document prologue .Bl -ohang @@ -47,6 +47,7 @@ enum mandocerr { MANDOCERR_STYLE, /* ===== start of style suggestions ===== */ MANDOCERR_MACRO_USELESS, /* useless macro: macro */ + MANDOCERR_BX, /* consider using OS macro: macro */ MANDOCERR_WARNING, /* ===== start of warnings ===== */ diff --git a/mdoc_validate.c b/mdoc_validate.c index a4b01c97..1a9dce2b 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -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 *); @@ -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: @@ -384,6 +389,25 @@ check_text(struct roff_man *mdoc, int ln, int pos, char *p) } 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; @@ -2276,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; @@ -89,6 +89,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "generic style suggestion", "useless macro", + "consider using OS macro", "generic warning", |