=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.369 retrieving revision 1.371 diff -u -p -r1.369 -r1.371 --- mandoc/roff.c 2020/01/19 18:02:00 1.369 +++ mandoc/roff.c 2020/02/27 21:43:44 1.371 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.369 2020/01/19 18:02:00 schwarze Exp $ */ +/* $Id: roff.c,v 1.371 2020/02/27 21:43:44 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017-2020 Ingo Schwarze @@ -1114,13 +1114,66 @@ roff_node_delete(struct roff_man *man, struct roff_nod roff_node_free(n); } +int +roff_node_transparent(struct roff_node *n) +{ + if (n == NULL) + return 0; + if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT) + return 1; + switch (n->tok) { + case ROFF_ft: + case ROFF_ll: + case ROFF_mc: + case ROFF_po: + case ROFF_ta: + case MDOC_Db: + case MDOC_Es: + case MDOC_Sm: + case MDOC_Tg: + case MAN_DT: + case MAN_UC: + case MAN_PD: + case MAN_AT: + return 1; + default: + return 0; + } +} + +struct roff_node * +roff_node_child(struct roff_node *n) +{ + for (n = n->child; roff_node_transparent(n); n = n->next) + continue; + return n; +} + +struct roff_node * +roff_node_prev(struct roff_node *n) +{ + do { + n = n->prev; + } while (roff_node_transparent(n)); + return n; +} + +struct roff_node * +roff_node_next(struct roff_node *n) +{ + do { + n = n->next; + } while (roff_node_transparent(n)); + return n; +} + void deroff(char **dest, const struct roff_node *n) { char *cp; size_t sz; - if (n->type != ROFFT_TEXT) { + if (n->string == NULL) { for (n = n->child; n != NULL; n = n->next) deroff(dest, n); return;