aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-01-08 17:48:09 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-01-08 17:48:09 +0000
commit924c4755ac64b780903344b188653f513990a771 (patch)
tree8790707d642423006b0f909baf400a6dc333adcb /mdoc_term.c
parentc2d0e548871bfed103ed040312a4333026ee10f1 (diff)
downloadmandoc-924c4755ac64b780903344b188653f513990a771.tar.gz
mandoc-924c4755ac64b780903344b188653f513990a771.tar.zst
mandoc-924c4755ac64b780903344b188653f513990a771.zip
Delete the redundant "nchild" member of struct roff_node, replacing
most uses by one, a few by two pointer checks, and only one by a tiny loop - not only making data smaller, but code shorter as well. This gets rid of an implicit invariant that confused both static analysis tools and human auditors. No functional change.
Diffstat (limited to 'mdoc_term.c')
-rw-r--r--mdoc_term.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/mdoc_term.c b/mdoc_term.c
index b90a2090..e8464362 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,7 +1,7 @@
-/* $Id: mdoc_term.c,v 1.330 2015/10/12 15:29:35 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.331 2016/01/08 17:48:09 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2016 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -357,7 +357,7 @@ print_mdoc_node(DECL_ARGS)
break;
default:
if (termacts[n->tok].pre &&
- (n->end == ENDBODY_NOT || n->nchild))
+ (n->end == ENDBODY_NOT || n->child != NULL))
chld = (*termacts[n->tok].pre)
(p, &npair, meta, n);
break;
@@ -598,7 +598,7 @@ static int
termp_ll_pre(DECL_ARGS)
{
- term_setwidth(p, n->nchild ? n->child->string : NULL);
+ term_setwidth(p, n->child != NULL ? n->child->string : NULL);
return 0;
}
@@ -731,7 +731,7 @@ termp_it_pre(DECL_ARGS)
term_word(p, "\\ \\ ");
break;
case LIST_inset:
- if (n->type == ROFFT_BODY && n->parent->head->nchild)
+ if (n->type == ROFFT_BODY && n->parent->head->child != NULL)
term_word(p, "\\ ");
break;
default:
@@ -1039,7 +1039,7 @@ termp_fl_pre(DECL_ARGS)
term_fontpush(p, TERMFONT_BOLD);
term_word(p, "\\-");
- if ( ! (n->nchild == 0 &&
+ if (!(n->child == NULL &&
(n->next == NULL ||
n->next->type == ROFFT_TEXT ||
n->next->flags & MDOC_LINE)))
@@ -1106,34 +1106,33 @@ termp_rs_pre(DECL_ARGS)
static int
termp_rv_pre(DECL_ARGS)
{
- int nchild;
+ struct roff_node *nch;
term_newln(p);
- nchild = n->nchild;
- if (nchild > 0) {
+ if (n->child != NULL) {
term_word(p, "The");
- for (n = n->child; n; n = n->next) {
+ for (nch = n->child; nch != NULL; nch = nch->next) {
term_fontpush(p, TERMFONT_BOLD);
- term_word(p, n->string);
+ term_word(p, nch->string);
term_fontpop(p);
p->flags |= TERMP_NOSPACE;
term_word(p, "()");
- if (n->next == NULL)
+ if (nch->next == NULL)
continue;
- if (nchild > 2) {
+ if (nch->prev != NULL || nch->next->next != NULL) {
p->flags |= TERMP_NOSPACE;
term_word(p, ",");
}
- if (n->next->next == NULL)
+ if (nch->next->next == NULL)
term_word(p, "and");
}
- if (nchild > 1)
+ if (n->child != NULL && n->child->next != NULL)
term_word(p, "functions return");
else
term_word(p, "function returns");
@@ -1159,27 +1158,29 @@ termp_rv_pre(DECL_ARGS)
static int
termp_ex_pre(DECL_ARGS)
{
- int nchild;
+ struct roff_node *nch;
term_newln(p);
term_word(p, "The");
- nchild = n->nchild;
- for (n = n->child; n; n = n->next) {
+ for (nch = n->child; nch != NULL; nch = nch->next) {
term_fontpush(p, TERMFONT_BOLD);
- term_word(p, n->string);
+ term_word(p, nch->string);
term_fontpop(p);
- if (nchild > 2 && n->next) {
+ if (nch->next == NULL)
+ continue;
+
+ if (nch->prev != NULL || nch->next->next != NULL) {
p->flags |= TERMP_NOSPACE;
term_word(p, ",");
}
- if (n->next && NULL == n->next->next)
+ if (nch->next->next == NULL)
term_word(p, "and");
}
- if (nchild > 1)
+ if (n->child != NULL && n->child->next != NULL)
term_word(p, "utilities exit\\~0");
else
term_word(p, "utility exits\\~0");
@@ -1838,7 +1839,7 @@ termp_quote_pre(DECL_ARGS)
switch (n->tok) {
case MDOC_Ao:
case MDOC_Aq:
- term_word(p, n->nchild == 1 &&
+ term_word(p, n->child != NULL && n->child->next == NULL &&
n->child->tok == MDOC_Mt ? "<" : "\\(la");
break;
case MDOC_Bro:
@@ -1895,7 +1896,7 @@ termp_quote_post(DECL_ARGS)
switch (n->tok) {
case MDOC_Ao:
case MDOC_Aq:
- term_word(p, n->nchild == 1 &&
+ term_word(p, n->child != NULL && n->child->next == NULL &&
n->child->tok == MDOC_Mt ? ">" : "\\(ra");
break;
case MDOC_Bro:
@@ -2159,7 +2160,7 @@ termp_bk_pre(DECL_ARGS)
case ROFFT_HEAD:
return 0;
case ROFFT_BODY:
- if (n->parent->args || 0 == n->prev->nchild)
+ if (n->parent->args != NULL || n->prev->child == NULL)
p->flags |= TERMP_PREKEEP;
break;
default: