]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_validate.c
do not break the line between Bsx/Bx/Fx/Nx/Ox/Dx and its arguments
[mandoc.git] / mdoc_validate.c
index 1d3d81e41bf8b46faee1c92c6e30a39a7e162f36..9bf1efb3d784ac19467e9790bd6d0fd399ecd591 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -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 */
@@ -301,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:
@@ -382,6 +388,25 @@ check_text(struct roff_man *mdoc, int ln, int pos, char *p)
                    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)
 {
@@ -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,
@@ -768,6 +794,9 @@ post_lb(POST_ARGS)
                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");
@@ -866,6 +895,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.
  */
@@ -1040,6 +1079,7 @@ static void
 post_nd(POST_ARGS)
 {
        struct roff_node        *n;
+       size_t                   sz;
 
        n = mdoc->last;
 
@@ -1053,6 +1093,11 @@ post_nd(POST_ARGS)
        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);
 }
@@ -1437,6 +1482,8 @@ post_bl(POST_ARGS)
        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) {
@@ -1537,6 +1584,34 @@ post_bl(POST_ARGS)
 
                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
@@ -2264,11 +2339,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;
@@ -2335,11 +2418,11 @@ post_os(POST_ARGS)
        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
@@ -2356,6 +2439,10 @@ post_os(POST_ARGS)
        }
        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