From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]); by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id aa178402; for ; Sun, 19 Apr 2015 09:26:12 -0500 (EST) Date: Sun, 19 Apr 2015 09:26:12 -0500 (EST) Message-Id: <4487415440686023472.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Unify some node handling functions that use TOKEN_NONE. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- 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. Modified Files: -------------- mdocml: libman.h libmandoc.h libmdoc.h man.c man_macro.c mdoc.c mdoc_macro.c mdoc_validate.c read.c roff.c roff_int.h Revision Data ------------- Index: man_macro.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/man_macro.c,v retrieving revision 1.106 retrieving revision 1.107 diff -Lman_macro.c -Lman_macro.c -u -p -r1.106 -r1.107 --- man_macro.c +++ 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); } /* Index: mdoc.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/mdoc.c,v retrieving revision 1.248 retrieving revision 1.249 diff -Lmdoc.c -Lmdoc.c -u -p -r1.248 -r1.249 --- mdoc.c +++ mdoc.c @@ -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, i } 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 li 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); Index: mdoc_macro.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/mdoc_macro.c,v retrieving revision 1.191 retrieving revision 1.192 diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.191 -r1.192 --- mdoc_macro.c +++ mdoc_macro.c @@ -432,11 +432,11 @@ dword(struct roff_man *mdoc, int line, i ! (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, Index: mdoc_validate.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/mdoc_validate.c,v retrieving revision 1.288 retrieving revision 1.289 diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.288 -r1.289 --- mdoc_validate.c +++ 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; } Index: man.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/man.c,v retrieving revision 1.159 retrieving revision 1.160 diff -Lman.c -Lman.c -u -p -r1.159 -r1.160 --- man.c +++ man.c @@ -50,7 +50,6 @@ const char *const __man_macronames[MAN_M 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, in 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 /* 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 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 Index: roff.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/roff.c,v retrieving revision 1.266 retrieving revision 1.267 diff -Lroff.c -Lroff.c -u -p -r1.266 -r1.267 --- roff.c +++ roff.c @@ -1,6 +1,6 @@ /* $Id$ */ /* - * Copyright (c) 2009-2012, 2014 Kristaps Dzonsons + * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze * * 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, s 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) { @@ -1087,6 +1116,36 @@ roff_body_alloc(struct roff_man *man, in roff_node_append(man, n); man->next = ROFF_NEXT_CHILD; return(n); +} + +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 Index: roff_int.h =================================================================== RCS file: /home/cvs/mdocml/mdocml/roff_int.h,v retrieving revision 1.1 retrieving revision 1.2 diff -Lroff_int.h -Lroff_int.h -u -p -r1.1 -r1.2 --- roff_int.h +++ roff_int.h @@ -1,7 +1,7 @@ -/* $OpenBSD$ */ +/* $Id$ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014, 2015 Ingo Schwarze + * Copyright (c) 2013, 2014, 2015 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 @@ -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 Index: read.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/read.c,v retrieving revision 1.138 retrieving revision 1.139 diff -Lread.c -Lread.c -u -p -r1.138 -r1.139 --- read.c +++ read.c @@ -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; Index: libman.h =================================================================== RCS file: /home/cvs/mdocml/mdocml/libman.h,v retrieving revision 1.74 retrieving revision 1.75 diff -Llibman.h -Llibman.h -u -p -r1.74 -r1.75 --- libman.h +++ libman.h @@ -36,8 +36,6 @@ extern const struct man_macro *const man __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 *); Index: libmdoc.h =================================================================== RCS file: /home/cvs/mdocml/mdocml/libmdoc.h,v retrieving revision 1.103 retrieving revision 1.104 diff -Llibmdoc.h -Llibmdoc.h -u -p -r1.103 -r1.104 --- libmdoc.h +++ libmdoc.h @@ -67,8 +67,6 @@ extern const struct mdoc_macro *const md __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 *); Index: libmandoc.h =================================================================== RCS file: /home/cvs/mdocml/mdocml/libmandoc.h,v retrieving revision 1.59 retrieving revision 1.60 diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.59 -r1.60 --- libmandoc.h +++ 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 *, -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv