diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-04-19 14:25:41 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-04-19 14:25:41 +0000 |
commit | b41835362693d09c3eff29cb37f2217b9dca8cc3 (patch) | |
tree | 304f88d63b2cc2aa84f33f3805156cd93c4f7cec /roff.c | |
parent | eed5e7f1fb85805f1b324c5a4501ed30467ae2a0 (diff) | |
download | mandoc-b41835362693d09c3eff29cb37f2217b9dca8cc3.tar.gz |
Unify some node handling functions that use TOKEN_NONE.
* mdoc_word_alloc(), man_word_alloc() -> roff_word_alloc()
* mdoc_word_append(), man_word_append() -> roff_word_append()
* mdoc_addspan(), man_addspan() -> roff_addtbl()
* mdoc_addeqn(), man_addeqn() -> roff_addeqn()
Minus 50 lines of code, no functional change.
Diffstat (limited to 'roff.c')
-rw-r--r-- | roff.c | 63 |
1 files changed, 61 insertions, 2 deletions
@@ -1,6 +1,6 @@ /* $Id$ */ /* - * Copyright (c) 2009-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -32,7 +32,6 @@ #include "libmandoc.h" #include "roff_int.h" #include "libroff.h" -#include "libmdoc.h" /* Maximum number of nested if-else conditionals. */ #define RSTACK_MAX 128 @@ -1067,6 +1066,36 @@ roff_node_append(struct roff_man *man, struct roff_node *n) man->last = n; } +void +roff_word_alloc(struct roff_man *man, int line, int pos, const char *word) +{ + struct roff_node *n; + + n = roff_node_alloc(man, line, pos, ROFFT_TEXT, TOKEN_NONE); + n->string = roff_strdup(man->roff, word); + roff_node_append(man, n); + if (man->macroset == MACROSET_MDOC) + mdoc_valid_post(man); + else + man_valid_post(man); + man->next = ROFF_NEXT_SIBLING; +} + +void +roff_word_append(struct roff_man *man, const char *word) +{ + struct roff_node *n; + char *addstr, *newstr; + + n = man->last; + addstr = roff_strdup(man->roff, word); + mandoc_asprintf(&newstr, "%s %s", n->string, addstr); + free(addstr); + free(n->string); + n->string = newstr; + man->next = ROFF_NEXT_SIBLING; +} + struct roff_node * roff_head_alloc(struct roff_man *man, int line, int pos, int tok) { @@ -1090,6 +1119,36 @@ roff_body_alloc(struct roff_man *man, int line, int pos, int tok) } void +roff_addeqn(struct roff_man *man, const struct eqn *eqn) +{ + struct roff_node *n; + + n = roff_node_alloc(man, eqn->ln, eqn->pos, ROFFT_EQN, TOKEN_NONE); + n->eqn = eqn; + if (eqn->ln > man->last->line) + n->flags |= MDOC_LINE; + roff_node_append(man, n); + man->next = ROFF_NEXT_SIBLING; +} + +void +roff_addtbl(struct roff_man *man, const struct tbl_span *tbl) +{ + struct roff_node *n; + + if (man->macroset == MACROSET_MAN) + man_breakscope(man, TOKEN_NONE); + n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE); + n->span = tbl; + roff_node_append(man, n); + if (man->macroset == MACROSET_MDOC) + mdoc_valid_post(man); + else + man_valid_post(man); + man->next = ROFF_NEXT_SIBLING; +} + +void roff_node_unlink(struct roff_man *man, struct roff_node *n) { |