From fc520e3cedbcdd86eb2b80e94cce78f98af717cf Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 6 Feb 2017 03:44:58 +0000 Subject: The .Nm macro does not only use the default name when it has no argument, but also when the first argument is a child macro. Arcane issue found in the FreeBSD cxgbetool(8) manual that Baptiste Daroussin sent me long ago for a different reason. While solving this, switch to the new technique of doing text production in the validator, reducing code duplication in the formatters, which also makes -Ttree output clearer. --- mdoc_html.c | 4 +--- mdoc_man.c | 8 +++----- mdoc_term.c | 6 ++---- mdoc_validate.c | 12 +++++++++++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/mdoc_html.c b/mdoc_html.c index bd434000..88bab333 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.269 2017/02/05 21:00:43 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.270 2017/02/06 03:44:58 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze @@ -582,8 +582,6 @@ mdoc_nm_pre(MDOC_ARGS) /* FALLTHROUGH */ case ROFFT_ELEM: print_otag(h, TAG_B, "c", "Nm"); - if (n->child == NULL && meta->name != NULL) - print_text(h, meta->name); return 1; case ROFFT_BODY: print_otag(h, TAG_TD, ""); diff --git a/mdoc_man.c b/mdoc_man.c index 2c19e15f..1785a034 100644 --- a/mdoc_man.c +++ b/mdoc_man.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.101 2017/01/11 17:39:53 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.102 2017/02/06 03:44:58 schwarze Exp $ */ /* * Copyright (c) 2011-2017 Ingo Schwarze * @@ -1518,7 +1518,7 @@ pre_nm(DECL_ARGS) } if (n->type != ROFFT_ELEM && n->type != ROFFT_HEAD) return 1; - name = n->child ? n->child->string : meta->name; + name = n->child == NULL ? NULL : n->child->string; if (NULL == name) return 0; if (n->type == ROFFT_HEAD) { @@ -1529,8 +1529,6 @@ pre_nm(DECL_ARGS) outflags |= MMAN_nl; } font_push('B'); - if (NULL == n->child) - print_word(meta->name); return 1; } @@ -1544,7 +1542,7 @@ post_nm(DECL_ARGS) break; case ROFFT_HEAD: case ROFFT_ELEM: - if (n->child != NULL || meta->name != NULL) + if (n->child != NULL && n->child->string != NULL) font_pop(); break; default: diff --git a/mdoc_term.c b/mdoc_term.c index ecac6a66..dc17de54 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.342 2017/02/04 11:58:09 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.343 2017/02/06 03:44:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -996,7 +996,7 @@ termp_nm_pre(DECL_ARGS) return 1; } - if (NULL == n->child && NULL == meta->name) + if (n->child == NULL) return 0; if (n->type == ROFFT_HEAD) @@ -1020,8 +1020,6 @@ termp_nm_pre(DECL_ARGS) } term_fontpush(p, TERMFONT_BOLD); - if (NULL == n->child) - term_word(p, meta->name); return 1; } diff --git a/mdoc_validate.c b/mdoc_validate.c index 043145ae..e58e7a47 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.317 2017/01/11 17:39:53 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.318 2017/02/06 03:44:58 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -1013,6 +1013,16 @@ post_nm(POST_ARGS) (mdoc->lastsec == SEC_NAME && n->child == NULL)) mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse, n->line, n->pos, "Nm"); + + if ((n->type != ROFFT_ELEM && n->type != ROFFT_HEAD) || + (n->child != NULL && n->child->type == ROFFT_TEXT) || + mdoc->meta.name == NULL) + return; + + mdoc->next = ROFF_NEXT_CHILD; + roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name); + mdoc->last->flags |= NODE_NOSRC; + mdoc->last = n; } static void -- cgit v1.2.3-56-ge451