From 924c4755ac64b780903344b188653f513990a771 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Fri, 8 Jan 2016 17:48:09 +0000 Subject: 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. --- man_html.c | 6 +++--- man_macro.c | 4 ++-- man_term.c | 4 ++-- man_validate.c | 20 ++++++++++---------- mandoc.3 | 6 +++--- mandocdb.c | 19 ++++++++++--------- mdoc_html.c | 51 ++++++++++++++++++++++++++------------------------- mdoc_man.c | 51 +++++++++++++++++++++++++-------------------------- mdoc_term.c | 51 ++++++++++++++++++++++++++------------------------- mdoc_validate.c | 26 ++++++++++++-------------- roff.c | 5 +---- roff.h | 1 - 12 files changed, 120 insertions(+), 124 deletions(-) diff --git a/man_html.c b/man_html.c index 57a289cc..d71eb382 100644 --- a/man_html.c +++ b/man_html.c @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.119 2015/10/06 18:32:19 schwarze Exp $ */ +/* $Id: man_html.c,v 1.120 2016/01/08 17:48:09 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -654,7 +654,7 @@ man_UR_pre(MAN_ARGS) n = n->child; assert(n->type == ROFFT_HEAD); - if (n->nchild) { + if (n->child != NULL) { assert(n->child->type == ROFFT_TEXT); PAIR_CLASS_INIT(&tag[0], "link-ext"); PAIR_HREF_INIT(&tag[1], n->child->string); @@ -662,7 +662,7 @@ man_UR_pre(MAN_ARGS) } assert(n->next->type == ROFFT_BODY); - if (n->next->nchild) + if (n->next->child != NULL) n = n->next; print_man_nodelist(man, n->child, mh, h); diff --git a/man_macro.c b/man_macro.c index 52073410..d1533570 100644 --- a/man_macro.c +++ b/man_macro.c @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.113 2015/10/22 21:54:23 schwarze Exp $ */ +/* $Id: man_macro.c,v 1.114 2016/01/08 17:48:09 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2012, 2013, 2014, 2015 Ingo Schwarze @@ -157,7 +157,7 @@ rew_scope(struct roff_man *man, int tok) /* Preserve empty paragraphs before RS. */ n = man->last; - if (tok == MAN_RS && n->nchild == 0 && + if (tok == MAN_RS && n->child == NULL && (n->tok == MAN_P || n->tok == MAN_PP || n->tok == MAN_LP)) return; diff --git a/man_term.c b/man_term.c index d9814ff0..f45e24af 100644 --- a/man_term.c +++ b/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.186 2015/10/12 00:08:15 schwarze Exp $ */ +/* $Id: man_term.c,v 1.187 2016/01/08 17:48:09 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -219,7 +219,7 @@ static int pre_ll(DECL_ARGS) { - term_setwidth(p, n->nchild ? n->child->string : NULL); + term_setwidth(p, n->child != NULL ? n->child->string : NULL); return 0; } diff --git a/man_validate.c b/man_validate.c index ad8206b6..16d99635 100644 --- a/man_validate.c +++ b/man_validate.c @@ -1,7 +1,7 @@ /* $OpenBSD$ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012-2015 Ingo Schwarze + * Copyright (c) 2010, 2012-2016 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -180,10 +180,10 @@ static void post_OP(CHKARGS) { - if (n->nchild == 0) + if (n->child == NULL) mandoc_msg(MANDOCERR_OP_EMPTY, man->parse, n->line, n->pos, "OP"); - else if (n->nchild > 2) { + else if (n->child->next != NULL && n->child->next->next != NULL) { n = n->child->next->next; mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, n->line, n->pos, "OP ... %s", n->string); @@ -206,7 +206,7 @@ post_ft(CHKARGS) char *cp; int ok; - if (0 == n->nchild) + if (n->child == NULL) return; ok = 0; @@ -256,22 +256,22 @@ check_par(CHKARGS) switch (n->type) { case ROFFT_BLOCK: - if (0 == n->body->nchild) + if (n->body->child == NULL) roff_node_delete(man, n); break; case ROFFT_BODY: - if (0 == n->nchild) + if (n->child == NULL) mandoc_vmsg(MANDOCERR_PAR_SKIP, man->parse, n->line, n->pos, "%s empty", man_macronames[n->tok]); break; case ROFFT_HEAD: - if (n->nchild) + if (n->child != NULL) mandoc_vmsg(MANDOCERR_ARG_SKIP, man->parse, n->line, n->pos, "%s %s%s", man_macronames[n->tok], n->child->string, - n->nchild > 1 ? " ..." : ""); + n->child->next != NULL ? " ..." : ""); break; default: break; @@ -284,11 +284,11 @@ post_IP(CHKARGS) switch (n->type) { case ROFFT_BLOCK: - if (0 == n->head->nchild && 0 == n->body->nchild) + if (n->head->child == NULL && n->body->child == NULL) roff_node_delete(man, n); break; case ROFFT_BODY: - if (0 == n->parent->head->nchild && 0 == n->nchild) + if (n->parent->head->child == NULL && n->child == NULL) mandoc_vmsg(MANDOCERR_PAR_SKIP, man->parse, n->line, n->pos, "%s empty", man_macronames[n->tok]); diff --git a/mandoc.3 b/mandoc.3 index d87a7f78..61012ede 100644 --- a/mandoc.3 +++ b/mandoc.3 @@ -1,7 +1,7 @@ -.\" $Id: mandoc.3,v 1.35 2016/01/08 02:53:13 schwarze Exp $ +.\" $Id: mandoc.3,v 1.36 2016/01/08 17:48:09 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons -.\" Copyright (c) 2010, 2013, 2014, 2015 Ingo Schwarze +.\" Copyright (c) 2010-2016 Ingo Schwarze .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -557,7 +557,7 @@ and fields), its position in the tree (the .Va parent , .Va child , -.Va nchild , +.Va last , .Va next and .Va prev diff --git a/mandocdb.c b/mandocdb.c index 93cca9ec..08f89c17 100644 --- a/mandocdb.c +++ b/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.214 2016/01/08 15:02:54 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.215 2016/01/08 17:48:09 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2016 Ingo Schwarze @@ -1446,7 +1446,7 @@ parse_man(struct mpage *mpage, const struct roff_meta *meta, char byte; size_t sz; - if (NULL == n) + if (n == NULL) return; /* @@ -1458,13 +1458,12 @@ parse_man(struct mpage *mpage, const struct roff_meta *meta, if (n->type == ROFFT_BODY && n->tok == MAN_SH) { body = n; - assert(body->parent); - if (NULL != (head = body->parent->head) && - 1 == head->nchild && - NULL != (head = (head->child)) && + if ((head = body->parent->head) != NULL && + (head = head->child) != NULL && + head->next == NULL && head->type == ROFFT_TEXT && - 0 == strcmp(head->string, "NAME") && - NULL != body->child) { + strcmp(head->string, "NAME") == 0 && + body->child != NULL) { /* * Suck the entire NAME section into memory. @@ -1697,7 +1696,9 @@ parse_mdoc_Va(struct mpage *mpage, const struct roff_meta *meta, if (n->type != ROFFT_ELEM && n->type != ROFFT_BODY) return 0; - if (n->nchild == 1 && n->child->type == ROFFT_TEXT) + if (n->child != NULL && + n->child->next == NULL && + n->child->type == ROFFT_TEXT) return 1; cp = NULL; diff --git a/mdoc_html.c b/mdoc_html.c index ee986acc..8e21bc79 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,7 +1,7 @@ -/* $Id: mdoc_html.c,v 1.239 2016/01/04 12:45:29 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.240 2016/01/08 17:48:09 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons - * Copyright (c) 2014, 2015 Ingo Schwarze + * Copyright (c) 2014, 2015, 2016 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -602,7 +602,7 @@ mdoc_fl_pre(MDOC_ARGS) print_text(h, "\\-"); - if ( ! (n->nchild == 0 && + if (!(n->child == NULL && (n->next == NULL || n->next->type == ROFFT_TEXT || n->next->flags & MDOC_LINE))) @@ -979,9 +979,9 @@ mdoc_bl_pre(MDOC_ARGS) static int mdoc_ex_pre(MDOC_ARGS) { - struct tag *t; - struct htmlpair tag; - int nchild; + struct htmlpair tag; + struct tag *t; + struct roff_node *nch; if (n->prev) print_otag(h, TAG_BR, 0, NULL); @@ -990,24 +990,26 @@ mdoc_ex_pre(MDOC_ARGS) print_text(h, "The"); - nchild = n->nchild; - for (n = n->child; n; n = n->next) { - assert(n->type == ROFFT_TEXT); + for (nch = n->child; nch != NULL; nch = nch->next) { + assert(nch->type == ROFFT_TEXT); t = print_otag(h, TAG_B, 1, &tag); - print_text(h, n->string); + print_text(h, nch->string); print_tagq(h, t); - if (nchild > 2 && n->next) { + if (nch->next == NULL) + continue; + + if (nch->prev != NULL || nch->next->next != NULL) { h->flags |= HTML_NOSPACE; print_text(h, ","); } - if (n->next && NULL == n->next->next) + if (nch->next->next == NULL) print_text(h, "and"); } - if (nchild > 1) + if (n->child != NULL && n->child->next != NULL) print_text(h, "utilities exit\\~0"); else print_text(h, "utility exits\\~0"); @@ -1695,37 +1697,36 @@ mdoc_rv_pre(MDOC_ARGS) { struct htmlpair tag; struct tag *t; - int nchild; + struct roff_node *nch; if (n->prev) print_otag(h, TAG_BR, 0, NULL); PAIR_CLASS_INIT(&tag, "fname"); - nchild = n->nchild; - if (nchild > 0) { + if (n->child != NULL) { print_text(h, "The"); - for (n = n->child; n; n = n->next) { + for (nch = n->child; nch != NULL; nch = nch->next) { t = print_otag(h, TAG_B, 1, &tag); - print_text(h, n->string); + print_text(h, nch->string); print_tagq(h, t); h->flags |= HTML_NOSPACE; print_text(h, "()"); - if (n->next == NULL) + if (nch->next == NULL) continue; - if (nchild > 2) { + if (nch->prev != NULL || nch->next->next != NULL) { h->flags |= HTML_NOSPACE; print_text(h, ","); } - if (n->next->next == NULL) + if (nch->next->next == NULL) print_text(h, "and"); } - if (nchild > 1) + if (n->child != NULL && n->child->next != NULL) print_text(h, "functions return"); else print_text(h, "function returns"); @@ -2001,7 +2002,7 @@ mdoc_bk_pre(MDOC_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) h->flags |= HTML_PREKEEP; break; default: @@ -2030,7 +2031,7 @@ mdoc_quote_pre(MDOC_ARGS) switch (n->tok) { case MDOC_Ao: case MDOC_Aq: - print_text(h, n->nchild == 1 && + print_text(h, n->child != NULL && n->child->next == NULL && n->child->tok == MDOC_Mt ? "<" : "\\(la"); break; case MDOC_Bro: @@ -2094,7 +2095,7 @@ mdoc_quote_post(MDOC_ARGS) switch (n->tok) { case MDOC_Ao: case MDOC_Aq: - print_text(h, n->nchild == 1 && + print_text(h, n->child != NULL && n->child->next == NULL && n->child->tok == MDOC_Mt ? ">" : "\\(ra"); break; case MDOC_Bro: diff --git a/mdoc_man.c b/mdoc_man.c index 55894eda..ab245313 100644 --- a/mdoc_man.c +++ b/mdoc_man.c @@ -1,6 +1,6 @@ -/* $Id: mdoc_man.c,v 1.95 2015/10/12 00:08:15 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.96 2016/01/08 17:48:09 schwarze Exp $ */ /* - * Copyright (c) 2011-2015 Ingo Schwarze + * Copyright (c) 2011-2016 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -610,7 +610,8 @@ print_node(DECL_ARGS) */ act = manacts + n->tok; cond = act->cond == NULL || (*act->cond)(meta, n); - if (cond && act->pre && (n->end == ENDBODY_NOT || n->nchild)) + if (cond && act->pre != NULL && + (n->end == ENDBODY_NOT || n->child != NULL)) do_sub = (*act->pre)(meta, n); } @@ -681,30 +682,29 @@ post_enc(DECL_ARGS) static int pre_ex(DECL_ARGS) { - int nchild; + struct roff_node *nch; outflags |= MMAN_br | MMAN_nl; print_word("The"); - nchild = n->nchild; - for (n = n->child; n; n = n->next) { + for (nch = n->child; nch != NULL; nch = nch->next) { font_push('B'); - print_word(n->string); + print_word(nch->string); font_pop(); - if (n->next == NULL) + if (nch->next == NULL) continue; - if (nchild > 2) { + if (nch->prev != NULL || nch->next->next != NULL) { outflags &= ~MMAN_spc; print_word(","); } - if (n->next->next == NULL) + if (nch->next->next == NULL) print_word("and"); } - if (nchild > 1) + if (n->child != NULL && n->child->next != NULL) print_word("utilities exit\\~0"); else print_word("utility exits\\~0"); @@ -873,7 +873,7 @@ static int pre_aq(DECL_ARGS) { - print_word(n->nchild == 1 && + print_word(n->child != NULL && n->child->next == NULL && n->child->tok == MDOC_Mt ? "<" : "\\(la"); outflags &= ~MMAN_spc; return 1; @@ -884,7 +884,7 @@ post_aq(DECL_ARGS) { outflags &= ~(MMAN_spc | MMAN_nl); - print_word(n->nchild == 1 && + print_word(n->child != NULL && n->child->next == NULL && n->child->tok == MDOC_Mt ? ">" : "\\(ra"); } @@ -1000,7 +1000,7 @@ pre_bl(DECL_ARGS) return 1; } - if (n->nchild) { + if (n->child != NULL) { print_line(".TS", MMAN_nl); for (icol = 0; icol < n->norm->Bl.ncols; icol++) print_word("l"); @@ -1016,7 +1016,7 @@ post_bl(DECL_ARGS) switch (n->norm->Bl.type) { case LIST_column: - if (n->nchild) + if (n->child != NULL) print_line(".TE", 0); break; case LIST_enum: @@ -1214,7 +1214,7 @@ pre_fl(DECL_ARGS) font_push('B'); print_word("\\-"); - if (n->nchild) + if (n->child != NULL) outflags &= ~MMAN_spc; return 1; } @@ -1224,7 +1224,7 @@ post_fl(DECL_ARGS) { font_pop(); - if ( ! (n->nchild || + if (!(n->child != NULL || n->next == NULL || n->next->type == ROFFT_TEXT || n->next->flags & MDOC_LINE)) @@ -1645,34 +1645,33 @@ pre_rs(DECL_ARGS) static int pre_rv(DECL_ARGS) { - int nchild; + struct roff_node *nch; outflags |= MMAN_br | MMAN_nl; - nchild = n->nchild; - if (nchild > 0) { + if (n->child != NULL) { print_word("The"); - for (n = n->child; n; n = n->next) { + for (nch = n->child; nch != NULL; nch = nch->next) { font_push('B'); - print_word(n->string); + print_word(nch->string); font_pop(); outflags &= ~MMAN_spc; print_word("()"); - if (n->next == NULL) + if (nch->next == NULL) continue; - if (nchild > 2) { + if (nch->prev != NULL || nch->next->next != NULL) { outflags &= ~MMAN_spc; print_word(","); } - if (n->next->next == NULL) + if (nch->next->next == NULL) print_word("and"); } - if (nchild > 1) + if (n->child != NULL && n->child->next != NULL) print_word("functions return"); else print_word("function returns"); 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 - * Copyright (c) 2010, 2012-2015 Ingo Schwarze + * Copyright (c) 2010, 2012-2016 Ingo Schwarze * Copyright (c) 2013 Franco Fichtner * * 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: diff --git a/mdoc_validate.c b/mdoc_validate.c index 9261e2fb..e369349c 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,7 +1,7 @@ -/* $Id: mdoc_validate.c,v 1.300 2015/10/30 19:04:16 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.301 2016/01/08 17:48:09 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010-2015 Ingo Schwarze + * Copyright (c) 2010-2016 Ingo Schwarze * Copyright (c) 2010 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -1278,7 +1278,8 @@ post_bl_head(POST_ARGS) argv = nbl->args->argv + j; i = argv->sz; - argv->sz += nh->nchild; + for (nch = nh->child; nch != NULL; nch = nch->next) + argv->sz++; argv->value = mandoc_reallocarray(argv->value, argv->sz, sizeof(char *)); @@ -1291,7 +1292,6 @@ post_bl_head(POST_ARGS) nnext = nch->next; roff_node_delete(NULL, nch); } - nh->nchild = 0; nh->child = NULL; } @@ -1352,14 +1352,11 @@ post_bl(POST_ARGS) */ assert(nchild->prev == NULL); - if (--nbody->nchild == 0) { - nbody->child = NULL; + nbody->child = nnext; + if (nnext == NULL) nbody->last = NULL; - assert(nnext == NULL); - } else { - nbody->child = nnext; + else nnext->prev = NULL; - } /* * Relink this child. @@ -1370,7 +1367,6 @@ post_bl(POST_ARGS) nchild->next = nblock; nblock->prev = nchild; - nparent->nchild++; if (nprev == NULL) nparent->child = nchild; else @@ -1688,7 +1684,9 @@ post_sh_see_also(POST_ARGS) n = mdoc->last->child; lastname = lastsec = lastpunct = NULL; while (n != NULL) { - if (n->tok != MDOC_Xr || n->nchild < 2) + if (n->tok != MDOC_Xr || + n->child == NULL || + n->child->next == NULL) break; /* Process one .Xr node. */ @@ -1744,7 +1742,7 @@ child_an(const struct roff_node *n) { for (n = n->child; n != NULL; n = n->next) - if ((n->tok == MDOC_An && n->nchild) || child_an(n)) + if ((n->tok == MDOC_An && n->child != NULL) || child_an(n)) return 1; return 0; } @@ -1931,7 +1929,7 @@ post_par(POST_ARGS) post_prevpar(mdoc); if (np->tok == MDOC_sp) { - if (np->nchild > 1) + if (np->child != NULL && np->child->next != NULL) mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, np->child->next->line, np->child->next->pos, "sp ... %s", np->child->next->string); diff --git a/roff.c b/roff.c index 4ee44f15..13b9439e 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.283 2015/10/22 21:54:23 schwarze Exp $ */ +/* $Id: roff.c,v 1.284 2016/01/08 17:48:10 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -1024,7 +1024,6 @@ roff_node_append(struct roff_man *man, struct roff_node *n) default: abort(); } - n->parent->nchild++; man->last = n; switch (n->type) { @@ -1169,7 +1168,6 @@ roff_node_unlink(struct roff_man *man, struct roff_node *n) /* Adjust parent. */ if (n->parent != NULL) { - n->parent->nchild--; if (n->parent->child == n) n->parent->child = n->next; if (n->parent->last == n) @@ -1211,7 +1209,6 @@ roff_node_delete(struct roff_man *man, struct roff_node *n) while (n->child != NULL) roff_node_delete(man, n->child); - assert(n->nchild == 0); roff_node_unlink(man, n); roff_node_free(n); } diff --git a/roff.h b/roff.h index cbee3822..19ec50f4 100644 --- a/roff.h +++ b/roff.h @@ -93,7 +93,6 @@ struct roff_node { char *string; /* TEXT */ const struct tbl_span *span; /* TBL */ const struct eqn *eqn; /* EQN */ - int nchild; /* Number of child nodes. */ int line; /* Input file line number. */ int pos; /* Input file column number. */ int tok; /* Request or macro ID. */ -- cgit v1.2.3-56-ge451