-/* $Id: mdoc_validate.c,v 1.327 2017/05/14 14:00:58 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.332 2017/06/08 00:23:30 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
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 *);
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);
post_sm, /* Sm */
post_hyph, /* Sx */
NULL, /* Sy */
- NULL, /* Tn */
+ post_useless, /* Tn */
post_xx, /* Ux */
NULL, /* Xc */
NULL, /* Xo */
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:
ln, pos + (int)(p - cp), NULL);
}
+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;
+ post_useless(mdoc);
n = mdoc->last;
if (n->child != NULL)
mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse, n->line,
return;
}
+ mandoc_vmsg(MANDOCERR_LB_BAD, mdoc->parse, n->child->line,
+ n->child->pos, "Lb %s", n->child->string);
+
roff_word_alloc(mdoc, n->line, n->pos, "library");
mdoc->last->flags = NODE_NOSRC;
roff_word_alloc(mdoc, n->line, n->pos, "\\(Lq");
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.
*/
post_nd(POST_ARGS)
{
struct roff_node *n;
+ size_t sz;
n = mdoc->last;
if (n->child == NULL)
mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse,
n->line, n->pos, "Nd");
+ else if (n->last->type == ROFFT_TEXT &&
+ (sz = strlen(n->last->string)) != 0 &&
+ n->last->string[sz - 1] == '.')
+ mandoc_msg(MANDOCERR_ND_DOT, mdoc->parse,
+ n->last->line, n->last->pos + sz - 1, NULL);
post_hyph(mdoc);
}
struct roff_node *nparent, *nprev; /* of the Bl block */
struct roff_node *nblock, *nbody; /* of the Bl */
struct roff_node *nchild, *nnext; /* of the Bl body */
+ const char *prev_Er;
+ int order;
nbody = mdoc->last;
switch (nbody->type) {
nchild = nnext;
}
+
+ if (mdoc->meta.os_e != MDOC_OS_NETBSD)
+ return;
+
+ prev_Er = NULL;
+ for (nchild = nbody->child; nchild != NULL; nchild = nchild->next) {
+ if (nchild->tok != MDOC_It)
+ continue;
+ if ((nnext = nchild->head->child) == NULL)
+ continue;
+ if (nnext->type == ROFFT_BLOCK)
+ nnext = nnext->body->child;
+ if (nnext == NULL || nnext->tok != MDOC_Er)
+ continue;
+ nnext = nnext->child;
+ if (prev_Er != NULL) {
+ order = strcmp(prev_Er, nnext->string);
+ if (order > 0)
+ mandoc_vmsg(MANDOCERR_ER_ORDER,
+ mdoc->parse, nnext->line, nnext->pos,
+ "Er %s %s", prev_Er, nnext->string);
+ else if (order == 0)
+ mandoc_vmsg(MANDOCERR_ER_REP,
+ mdoc->parse, nnext->line, nnext->pos,
+ "Er %s", prev_Er);
+ }
+ prev_Er = nnext->string;
+ }
}
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;
mdoc->meta.os = NULL;
deroff(&mdoc->meta.os, n);
if (mdoc->meta.os)
- return;
+ goto out;
if (mdoc->defos) {
mdoc->meta.os = mandoc_strdup(mdoc->defos);
- return;
+ goto out;
}
#ifdef OSNAME
}
mdoc->meta.os = mandoc_strdup(defbuf);
#endif /*!OSNAME*/
+
+out: mdoc->meta.os_e = strstr(mdoc->meta.os, "OpenBSD") != NULL ?
+ MDOC_OS_OPENBSD : strstr(mdoc->meta.os, "NetBSD") != NULL ?
+ MDOC_OS_NETBSD : MDOC_OS_OTHER;
}
enum roff_sec