=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.385 retrieving revision 1.393 diff -u -p -r1.385 -r1.393 --- mandoc/mdoc_validate.c 2020/04/18 20:40:10 1.385 +++ mandoc/mdoc_validate.c 2025/06/05 12:38:26 1.393 @@ -1,6 +1,6 @@ -/* $Id: mdoc_validate.c,v 1.385 2020/04/18 20:40:10 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.393 2025/06/05 12:38:26 schwarze Exp $ */ /* - * Copyright (c) 2010-2020 Ingo Schwarze + * Copyright (c) 2010-2022, 2025 Ingo Schwarze * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010 Joerg Sonnenberger * @@ -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 */ @@ -990,18 +991,39 @@ post_ex(POST_ARGS) static void post_lb(POST_ARGS) { - struct roff_node *n; - const char *p; + struct roff_node *n, *nch; + const char *ccp; + char *cp; post_delim_nb(mdoc); n = mdoc->last; - assert(n->child->type == ROFFT_TEXT); + nch = n->child; + assert(nch->type == ROFFT_TEXT); mdoc->next = ROFF_NEXT_CHILD; - if ((p = mdoc_a2lib(n->child->string)) != NULL) { + if (n->sec == SEC_SYNOPSIS) { + roff_word_alloc(mdoc, n->line, n->pos, "/*"); + mdoc->last->flags = NODE_NOSRC; + while (nch != NULL) { + roff_word_alloc(mdoc, n->line, n->pos, "-l"); + mdoc->last->flags = NODE_DELIMO | NODE_NOSRC; + mdoc->last = nch; + assert(nch->type == ROFFT_TEXT); + cp = nch->string; + if (strncmp(cp, "lib", 3) == 0) + memmove(cp, cp + 3, strlen(cp) - 3 + 1); + nch = nch->next; + } + roff_word_alloc(mdoc, n->line, n->pos, "*/"); + mdoc->last->flags = NODE_NOSRC; + mdoc->last = n; + return; + } + + if ((ccp = mdoc_a2lib(n->child->string)) != NULL) { n->child->flags |= NODE_NOPRT; - roff_word_alloc(mdoc, n->line, n->pos, p); + roff_word_alloc(mdoc, n->line, n->pos, ccp); mdoc->last->flags = NODE_NOSRC; mdoc->last = n; return; @@ -1112,7 +1134,8 @@ post_tg(POST_ARGS) /* Find the next node. */ n = mdoc->last; for (nn = n; nn != NULL; nn = nn->parent) { - if (nn->next != NULL) { + if (nn->type != ROFFT_HEAD && nn->type != ROFFT_BODY && + nn->type != ROFFT_TAIL && nn->next != NULL) { nn = nn->next; break; } @@ -1628,6 +1651,29 @@ post_es(POST_ARGS) } 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) { struct roff_node *n; @@ -2593,7 +2639,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 +2811,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. */ @@ -2842,7 +2894,6 @@ post_os(POST_ARGS) { #ifndef OSNAME struct utsname utsname; - static char *defbuf; #endif struct roff_node *n; @@ -2879,15 +2930,15 @@ post_os(POST_ARGS) #ifdef OSNAME mdoc->meta.os = mandoc_strdup(OSNAME); #else /*!OSNAME */ - if (defbuf == NULL) { + if (mdoc->os_r == NULL) { if (uname(&utsname) == -1) { mandoc_msg(MANDOCERR_OS_UNAME, n->line, n->pos, "Os"); - defbuf = mandoc_strdup("UNKNOWN"); + mdoc->os_r = mandoc_strdup("UNKNOWN"); } else - mandoc_asprintf(&defbuf, "%s %s", + mandoc_asprintf(&mdoc->os_r, "%s %s", utsname.sysname, utsname.release); } - mdoc->meta.os = mandoc_strdup(defbuf); + mdoc->meta.os = mandoc_strdup(mdoc->os_r); #endif /*!OSNAME*/ out: @@ -3027,6 +3078,6 @@ macro2len(enum roff_tok macro) return 10; default: break; - }; + } return 0; }