]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_validate.c
Revert part of the previous diff to fix a regression (another endless loop)
[mandoc.git] / mdoc_validate.c
index 8a8176b9cf2200bb510aae30c4375cdd90393644..e1cd3ae1edcbff150170a061868c3013146f511b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.383 2020/04/06 10:16:17 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.389 2021/07/18 11:41:23 schwarze Exp $ */
 /*
  * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
 #include "mandoc.h"
 #include "mandoc_xr.h"
 #include "roff.h"
-#include "tag.h"
 #include "mdoc.h"
 #include "libmandoc.h"
 #include "roff_int.h"
 #include "libmdoc.h"
+#include "tag.h"
 
 /* FIXME: .Bl -diag can't have non-text children in HEAD. */
 
@@ -92,6 +92,7 @@ static        void     post_es(POST_ARGS);
 static void     post_eoln(POST_ARGS);
 static void     post_ex(POST_ARGS);
 static void     post_fa(POST_ARGS);
+static void     post_fl(POST_ARGS);
 static void     post_fn(POST_ARGS);
 static void     post_fname(POST_ARGS);
 static void     post_fo(POST_ARGS);
@@ -150,7 +151,7 @@ static      const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = {
        post_ex,        /* Ex */
        post_fa,        /* Fa */
        NULL,           /* Fd */
-       post_tag,       /* Fl */
+       post_fl,        /* Fl */
        post_fn,        /* Fn */
        post_delim_nb,  /* Ft */
        post_tag,       /* Ic */
@@ -163,7 +164,7 @@ static      const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = {
        post_defaults,  /* Pa */
        post_rv,        /* Rv */
        post_st,        /* St */
-       post_delim_nb,  /* Va */
+       post_tag,       /* Va */
        post_delim_nb,  /* Vt */
        post_xr,        /* Xr */
        NULL,           /* %A */
@@ -1627,6 +1628,29 @@ post_es(POST_ARGS)
        mdoc->last_es = mdoc->last;
 }
 
+static void
+post_fl(POST_ARGS)
+{
+       struct roff_node        *n;
+       char                    *cp;
+
+       /*
+        * Transform ".Fl Fl long" to ".Fl \-long",
+        * resulting for example in better HTML output.
+        */
+
+       n = mdoc->last;
+       if (n->prev != NULL && n->prev->tok == MDOC_Fl &&
+           n->prev->child == NULL && n->child != NULL &&
+           (n->flags & NODE_LINE) == 0) {
+               mandoc_asprintf(&cp, "\\-%s", n->child->string);
+               free(n->child->string);
+               n->child->string = cp;
+               roff_node_delete(mdoc, n->prev);
+       }
+       post_tag(mdoc);
+}
+
 static void
 post_xx(POST_ARGS)
 {
@@ -2212,8 +2236,8 @@ post_hyph(POST_ARGS)
                        if (*cp == '-' &&
                            isalpha((unsigned char)cp[-1]) &&
                            isalpha((unsigned char)cp[1])) {
-                               if (n->string == NULL && n->flags & NODE_ID)
-                                       n->string = mandoc_strdup(nch->string);
+                               if (n->tag == NULL && n->flags & NODE_ID)
+                                       n->tag = mandoc_strdup(nch->string);
                                *cp = ASCII_HYPH;
                        }
        }
@@ -2593,7 +2617,7 @@ post_section(POST_ARGS)
                        if ((nch = n->child) != NULL &&
                            nch->type == ROFFT_TEXT &&
                            strcmp(nch->string, tag) == 0)
-                               tag_put(NULL, TAG_WEAK, n);
+                               tag_put(NULL, TAG_STRONG, n);
                        else
                                tag_put(tag, TAG_FALLBACK, n);
                        free(tag);
@@ -2765,8 +2789,14 @@ post_dt(POST_ARGS)
                mandoc_msg(MANDOCERR_MSEC_BAD,
                    nn->line, nn->pos, "Dt ... %s", nn->string);
                mdoc->meta.vol = mandoc_strdup(nn->string);
-       } else
+       } else {
                mdoc->meta.vol = mandoc_strdup(cp);
+               if (mdoc->filesec != '\0' &&
+                   mdoc->filesec != *nn->string &&
+                   *nn->string >= '1' && *nn->string <= '9')
+                       mandoc_msg(MANDOCERR_MSEC_FILE, nn->line, nn->pos,
+                           "*.%c vs Dt ... %c", mdoc->filesec, *nn->string);
+       }
 
        /* Optional third argument: architecture. */