=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.373 retrieving revision 1.377 diff -u -p -r1.373 -r1.377 --- mandoc/mdoc_validate.c 2019/03/13 18:29:18 1.373 +++ mandoc/mdoc_validate.c 2020/01/19 18:02:00 1.377 @@ -1,7 +1,7 @@ -/* $Id: mdoc_validate.c,v 1.373 2019/03/13 18:29:18 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.377 2020/01/19 18:02:00 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2019 Ingo Schwarze + * Copyright (c) 2010-2020 Ingo Schwarze * Copyright (c) 2010 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -113,6 +113,7 @@ static void post_sm(POST_ARGS); static void post_st(POST_ARGS); static void post_std(POST_ARGS); static void post_sx(POST_ARGS); +static void post_tg(POST_ARGS); static void post_useless(POST_ARGS); static void post_xr(POST_ARGS); static void post_xx(POST_ARGS); @@ -238,6 +239,7 @@ static const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = NULL, /* %Q */ NULL, /* %U */ NULL, /* Ta */ + post_tg, /* Tg */ }; #define RSORD_MAX 14 /* Number of `Rs' blocks. */ @@ -1090,6 +1092,41 @@ post_st(POST_ARGS) } static void +post_tg(POST_ARGS) +{ + struct roff_node *n, *nch; + size_t len; + + n = mdoc->last; + nch = n->child; + if (nch == NULL && n->next != NULL && + n->next->child->type == ROFFT_TEXT) { + mdoc->next = ROFF_NEXT_CHILD; + roff_word_alloc(mdoc, n->line, n->pos, n->next->child->string); + nch = mdoc->last; + nch->flags |= NODE_NOSRC; + mdoc->last = n; + } + if (nch == NULL || *nch->string == '\0') { + mandoc_msg(MANDOCERR_MACRO_EMPTY, n->line, n->pos, "Tg"); + roff_node_delete(mdoc, n); + return; + } + len = strcspn(nch->string, " \t"); + if (nch->string[len] != '\0') + mandoc_msg(MANDOCERR_TG_SPC, nch->line, nch->pos + len + 1, + "Tg %s", nch->string); + if (nch->next != NULL) { + mandoc_msg(MANDOCERR_ARG_EXCESS, nch->next->line, + nch->next->pos, "Tg ... %s", nch->next->string); + while (nch->next != NULL) + roff_node_delete(mdoc, nch->next); + } + if (nch->string[len] != '\0') + roff_node_delete(mdoc, n); +} + +static void post_obsolete(POST_ARGS) { struct roff_node *n; @@ -1186,11 +1223,17 @@ post_fname(POST_ARGS) size_t pos; n = mdoc->last->child; - pos = strcspn(n->string, "()"); - cp = n->string + pos; - if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*'))) - mandoc_msg(MANDOCERR_FN_PAREN, n->line, n->pos + pos, - "%s", n->string); + cp = n->string; + if (*cp == '(') { + if (cp[strlen(cp + 1)] == ')') + return; + pos = 0; + } else { + pos = strcspn(cp, "()"); + if (cp[pos] == '\0') + return; + } + mandoc_msg(MANDOCERR_FN_PAREN, n->line, n->pos + pos, "%s", cp); } static void @@ -1748,7 +1791,7 @@ post_bl(POST_ARGS) while (nchild != NULL) { nnext = nchild->next; if (nchild->tok == MDOC_It || - (nchild->tok == MDOC_Sm && + ((nchild->tok == MDOC_Sm || nchild->tok == MDOC_Tg) && nnext != NULL && nnext->tok == MDOC_It)) { nchild = nnext; continue; @@ -1903,8 +1946,7 @@ post_root(POST_ARGS) /* Add missing prologue data. */ if (mdoc->meta.date == NULL) - mdoc->meta.date = mdoc->quick ? mandoc_strdup("") : - mandoc_normdate(mdoc, NULL, 0, 0); + mdoc->meta.date = mandoc_normdate(NULL, NULL); if (mdoc->meta.title == NULL) { mandoc_msg(MANDOCERR_DT_NOTITLE, 0, 0, "EOF"); @@ -2502,7 +2544,6 @@ static void post_dd(POST_ARGS) { struct roff_node *n; - char *datestr; n = mdoc->last; n->flags |= NODE_NOPRT; @@ -2519,21 +2560,10 @@ post_dd(POST_ARGS) mandoc_msg(MANDOCERR_PROLOG_ORDER, n->line, n->pos, "Dd after Os"); - if (n->child == NULL || n->child->string[0] == '\0') { - mdoc->meta.date = mdoc->quick ? mandoc_strdup("") : - mandoc_normdate(mdoc, NULL, n->line, n->pos); - return; - } - - datestr = NULL; - deroff(&datestr, n); - if (mdoc->quick) - mdoc->meta.date = datestr; - else { - mdoc->meta.date = mandoc_normdate(mdoc, - datestr, n->line, n->pos); - free(datestr); - } + if (mdoc->quick && n != NULL) + mdoc->meta.date = mandoc_strdup(""); + else + mdoc->meta.date = mandoc_normdate(n->child, n); } static void