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 | |
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.
-rw-r--r-- | libman.h | 2 | ||||
-rw-r--r-- | libmandoc.h | 4 | ||||
-rw-r--r-- | libmdoc.h | 5 | ||||
-rw-r--r-- | man.c | 60 | ||||
-rw-r--r-- | man_macro.c | 8 | ||||
-rw-r--r-- | mdoc.c | 54 | ||||
-rw-r--r-- | mdoc_macro.c | 4 | ||||
-rw-r--r-- | mdoc_validate.c | 10 | ||||
-rw-r--r-- | read.c | 17 | ||||
-rw-r--r-- | roff.c | 63 | ||||
-rw-r--r-- | roff_int.h | 21 |
11 files changed, 100 insertions, 148 deletions
@@ -36,8 +36,6 @@ extern const struct man_macro *const man_macros; __BEGIN_DECLS -void man_word_alloc(struct roff_man *, int, int, const char *); -void man_word_append(struct roff_man *, const char *); void man_block_alloc(struct roff_man *, int, int, int); void man_elem_alloc(struct roff_man *, int, int, int); int man_hash_find(const char *); diff --git a/libmandoc.h b/libmandoc.h index 94f8482b..42bcb059 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -58,14 +58,10 @@ const char *mandoc_a2msec(const char*); void mdoc_hash_init(void); int mdoc_parseln(struct roff_man *, int, char *, int); void mdoc_endparse(struct roff_man *); -void mdoc_addspan(struct roff_man *, const struct tbl_span *); -void mdoc_addeqn(struct roff_man *, const struct eqn *); void man_hash_init(void); int man_parseln(struct roff_man *, int, char *, int); void man_endparse(struct roff_man *); -void man_addspan(struct roff_man *, const struct tbl_span *); -void man_addeqn(struct roff_man *, const struct eqn *); int preconv_cue(const struct buf *, size_t); int preconv_encode(struct buf *, size_t *, @@ -67,8 +67,6 @@ extern const struct mdoc_macro *const mdoc_macros; __BEGIN_DECLS void mdoc_macro(MACRO_PROT_ARGS); -void mdoc_word_alloc(struct roff_man *, int, int, const char *); -void mdoc_word_append(struct roff_man *, const char *); void mdoc_elem_alloc(struct roff_man *, int, int, int, struct mdoc_arg *); struct roff_node *mdoc_block_alloc(struct roff_man *, int, int, @@ -82,11 +80,8 @@ const char *mdoc_a2att(const char *); const char *mdoc_a2lib(const char *); const char *mdoc_a2st(const char *); const char *mdoc_a2arch(const char *); -void mdoc_valid_pre(struct roff_man *, struct roff_node *); -void mdoc_valid_post(struct roff_man *); void mdoc_argv(struct roff_man *, int, int, struct mdoc_arg **, int *, char *); -void mdoc_argv_free(struct mdoc_arg *); enum margserr mdoc_args(struct roff_man *, int, int *, char *, int, char **); void mdoc_macroend(struct roff_man *); @@ -50,7 +50,6 @@ const char *const __man_macronames[MAN_MAX] = { const char * const *man_macronames = __man_macronames; -static void man_breakscope(struct roff_man *, int); static void man_descope(struct roff_man *, int, int); static int man_ptext(struct roff_man *, int, char *, int); static int man_pmacro(struct roff_man *, int, char *, int); @@ -95,61 +94,6 @@ man_block_alloc(struct roff_man *man, int line, int pos, int tok) man->next = ROFF_NEXT_CHILD; } -void -man_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); - man_valid_post(man); - man->next = ROFF_NEXT_SIBLING; -} - -void -man_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; -} - -void -man_addeqn(struct roff_man *man, const struct eqn *ep) -{ - struct roff_node *n; - - n = roff_node_alloc(man, ep->ln, ep->pos, ROFFT_EQN, TOKEN_NONE); - n->eqn = ep; - if (ep->ln > man->last->line) - n->flags |= MAN_LINE; - roff_node_append(man, n); - man->next = ROFF_NEXT_SIBLING; - man_descope(man, ep->ln, ep->pos); -} - -void -man_addspan(struct roff_man *man, const struct tbl_span *sp) -{ - struct roff_node *n; - - man_breakscope(man, TOKEN_NONE); - n = roff_node_alloc(man, sp->line, 0, ROFFT_TBL, TOKEN_NONE); - n->span = sp; - roff_node_append(man, n); - man_valid_post(man); - man->next = ROFF_NEXT_SIBLING; - man_descope(man, sp->line, 0); -} - static void man_descope(struct roff_man *man, int line, int offs) { @@ -178,7 +122,7 @@ man_ptext(struct roff_man *man, int line, char *buf, int offs) /* Literal free-form text whitespace is preserved. */ if (man->flags & MAN_LITERAL) { - man_word_alloc(man, line, offs, buf + offs); + roff_word_alloc(man, line, offs, buf + offs); man_descope(man, line, offs); return(1); } @@ -222,7 +166,7 @@ man_ptext(struct roff_man *man, int line, char *buf, int offs) buf[i] = '\0'; } - man_word_alloc(man, line, offs, buf + offs); + roff_word_alloc(man, line, offs, buf + offs); /* * End-of-sentence check. If the last character is an unescaped diff --git a/man_macro.c b/man_macro.c index 77c5ed11..ab5e3ffc 100644 --- a/man_macro.c +++ b/man_macro.c @@ -264,7 +264,7 @@ blk_exp(MACRO_PROT_ARGS) la = *pos; if (man_args(man, line, pos, buf, &p)) - man_word_alloc(man, line, la, p); + roff_word_alloc(man, line, la, p); if (buf[*pos] != '\0') mandoc_vmsg(MANDOCERR_ARG_EXCESS, @@ -301,7 +301,7 @@ blk_imp(MACRO_PROT_ARGS) la = *pos; if ( ! man_args(man, line, pos, buf, &p)) break; - man_word_alloc(man, line, la, p); + roff_word_alloc(man, line, la, p); } /* @@ -352,9 +352,9 @@ in_line_eoln(MACRO_PROT_ARGS) break; if (man_macros[tok].flags & MAN_JOIN && man->last->type == ROFFT_TEXT) - man_word_append(man, p); + roff_word_append(man, p); else - man_word_alloc(man, line, la, p); + roff_word_alloc(man, line, la, p); } /* @@ -96,31 +96,6 @@ mdoc_endparse(struct roff_man *mdoc) mdoc_macroend(mdoc); } -void -mdoc_addeqn(struct roff_man *mdoc, const struct eqn *ep) -{ - struct roff_node *n; - - n = roff_node_alloc(mdoc, ep->ln, ep->pos, ROFFT_EQN, TOKEN_NONE); - n->eqn = ep; - if (ep->ln > mdoc->last->line) - n->flags |= MDOC_LINE; - roff_node_append(mdoc, n); - mdoc->next = ROFF_NEXT_SIBLING; -} - -void -mdoc_addspan(struct roff_man *mdoc, const struct tbl_span *sp) -{ - struct roff_node *n; - - n = roff_node_alloc(mdoc, sp->line, 0, ROFFT_TBL, TOKEN_NONE); - n->span = sp; - roff_node_append(mdoc, n); - mdoc_valid_post(mdoc); - mdoc->next = ROFF_NEXT_SIBLING; -} - /* * Main parse routine. Parses a single line -- really just hands off to * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). @@ -255,33 +230,6 @@ mdoc_elem_alloc(struct roff_man *mdoc, int line, int pos, } void -mdoc_word_alloc(struct roff_man *mdoc, int line, int pos, const char *p) -{ - struct roff_node *n; - - n = roff_node_alloc(mdoc, line, pos, ROFFT_TEXT, TOKEN_NONE); - n->string = roff_strdup(mdoc->roff, p); - roff_node_append(mdoc, n); - mdoc_valid_post(mdoc); - mdoc->next = ROFF_NEXT_SIBLING; -} - -void -mdoc_word_append(struct roff_man *mdoc, const char *p) -{ - struct roff_node *n; - char *addstr, *newstr; - - n = mdoc->last; - addstr = roff_strdup(mdoc->roff, p); - mandoc_asprintf(&newstr, "%s %s", n->string, addstr); - free(addstr); - free(n->string); - n->string = newstr; - mdoc->next = ROFF_NEXT_SIBLING; -} - -void mdoc_node_relink(struct roff_man *mdoc, struct roff_node *p) { @@ -387,7 +335,7 @@ mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs) return(1); } - mdoc_word_alloc(mdoc, line, offs, buf+offs); + roff_word_alloc(mdoc, line, offs, buf+offs); if (mdoc->flags & MDOC_LITERAL) return(1); diff --git a/mdoc_macro.c b/mdoc_macro.c index fcfd517c..cb06dcdc 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -432,11 +432,11 @@ dword(struct roff_man *mdoc, int line, int col, const char *p, ! (mdoc->flags & (MDOC_SYNOPSIS | MDOC_KEEP | MDOC_SMOFF)) && d == DELIM_NONE && mdoc->last->type == ROFFT_TEXT && mdoc_isdelim(mdoc->last->string) == DELIM_NONE) { - mdoc_word_append(mdoc, p); + roff_word_append(mdoc, p); return; } - mdoc_word_alloc(mdoc, line, col, p); + roff_word_alloc(mdoc, line, col, p); /* * If the word consists of a bare delimiter, diff --git a/mdoc_validate.c b/mdoc_validate.c index 18c606e1..dd477eef 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1051,13 +1051,13 @@ post_defaults(POST_ARGS) switch (nn->tok) { case MDOC_Ar: - mdoc_word_alloc(mdoc, nn->line, nn->pos, "file"); - mdoc_word_alloc(mdoc, nn->line, nn->pos, "..."); + roff_word_alloc(mdoc, nn->line, nn->pos, "file"); + roff_word_alloc(mdoc, nn->line, nn->pos, "..."); break; case MDOC_Pa: /* FALLTHROUGH */ case MDOC_Mt: - mdoc_word_alloc(mdoc, nn->line, nn->pos, "~"); + roff_word_alloc(mdoc, nn->line, nn->pos, "~"); break; default: abort(); @@ -1076,7 +1076,7 @@ post_at(POST_ARGS) n = mdoc->last; if (n->child == NULL) { mdoc->next = ROFF_NEXT_CHILD; - mdoc_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX"); + roff_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX"); mdoc->last = n; return; } @@ -2315,7 +2315,7 @@ post_ex(POST_ARGS) } mdoc->next = ROFF_NEXT_CHILD; - mdoc_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name); + roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name); mdoc->last = n; } @@ -43,6 +43,7 @@ #include "mdoc.h" #include "man.h" #include "libmandoc.h" +#include "roff_int.h" #define REPARSE_LIMIT 1000 @@ -583,18 +584,12 @@ rerun: * Do the same for ROFF_EQN. */ - if (rr == ROFF_TBL) { + if (rr == ROFF_TBL) while ((span = roff_span(curp->roff)) != NULL) - if (curp->man->macroset == MACROSET_MDOC) - mdoc_addspan(curp->man, span); - else - man_addspan(curp->man, span); - } else if (rr == ROFF_EQN) { - if (curp->man->macroset == MACROSET_MDOC) - mdoc_addeqn(curp->man, roff_eqn(curp->roff)); - else - man_addeqn(curp->man, roff_eqn(curp->roff)); - } else if ((curp->man->macroset == MACROSET_MDOC ? + roff_addtbl(curp->man, span); + else if (rr == ROFF_EQN) + roff_addeqn(curp->man, roff_eqn(curp->roff)); + else if ((curp->man->macroset == MACROSET_MDOC ? mdoc_parseln(curp->man, curp->line, ln.buf, of) : man_parseln(curp->man, curp->line, ln.buf, of)) == 2) break; @@ -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) { @@ -1,7 +1,7 @@ -/* $OpenBSD$ */ +/* $Id$ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,10 +21,27 @@ __BEGIN_DECLS struct roff_node *roff_node_alloc(struct roff_man *, int, int, enum roff_type, int); void roff_node_append(struct roff_man *, struct roff_node *); +void roff_word_alloc(struct roff_man *, int, int, const char *); +void roff_word_append(struct roff_man *, const char *); struct roff_node *roff_head_alloc(struct roff_man *, int, int, int); struct roff_node *roff_body_alloc(struct roff_man *, int, int, int); +void roff_addeqn(struct roff_man *, const struct eqn *); +void roff_addtbl(struct roff_man *, const struct tbl_span *); void roff_node_unlink(struct roff_man *, struct roff_node *); void roff_node_free(struct roff_node *); void roff_node_delete(struct roff_man *, struct roff_node *); +/* + * Functions called from roff.c need to be declared here, + * not in libmdoc.h or libman.h, even if they are specific + * to either the mdoc(7) or the man(7) parser. + */ + +void man_breakscope(struct roff_man *, int); +void man_valid_post(struct roff_man *); + +void mdoc_valid_pre(struct roff_man *, struct roff_node *); +void mdoc_valid_post(struct roff_man *); +void mdoc_argv_free(struct mdoc_arg *); + __END_DECLS |