diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-14 06:33:14 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-14 06:33:14 +0000 |
commit | e7602bc16044a04fe97beac48909840f1b12ba4e (patch) | |
tree | b489159f1ce065b9075402209449aab86376cc72 | |
parent | e3863b1460cd9598ecb57705c9b22c2f2c552953 (diff) | |
download | mandoc-e7602bc16044a04fe97beac48909840f1b12ba4e.tar.gz |
Cleanup, no functional change:
Now that message handling is properly encapsulated,
remove struct mparse pointers from four structs (roff, roff_man,
tbl_node, eqn_node) and from the argument lists of five functions
(roff_alloc, roff_man_alloc, mandoc_getarg, tbl_alloc, eqn_alloc).
Except for being passed to the main program as an opaque object,
it now only occurs in read.c, as it should, and not across 15 files
like in the past.
-rw-r--r-- | eqn.c | 3 | ||||
-rw-r--r-- | eqn_parse.h | 4 | ||||
-rw-r--r-- | libmandoc.h | 8 | ||||
-rw-r--r-- | man_macro.c | 2 | ||||
-rw-r--r-- | mandoc.c | 2 | ||||
-rw-r--r-- | mandoc_headers.3 | 28 | ||||
-rw-r--r-- | mdoc_argv.c | 2 | ||||
-rw-r--r-- | read.c | 4 | ||||
-rw-r--r-- | roff.c | 14 | ||||
-rw-r--r-- | roff.h | 1 | ||||
-rw-r--r-- | tbl.3 | 7 | ||||
-rw-r--r-- | tbl.c | 3 | ||||
-rw-r--r-- | tbl_int.h | 1 | ||||
-rw-r--r-- | tbl_parse.h | 3 |
14 files changed, 19 insertions, 63 deletions
@@ -303,12 +303,11 @@ static void eqn_undef(struct eqn_node *); struct eqn_node * -eqn_alloc(struct mparse *parse) +eqn_alloc(void) { struct eqn_node *ep; ep = mandoc_calloc(1, sizeof(*ep)); - ep->parse = parse; ep->gsize = EQN_DEFSIZE; return ep; } diff --git a/eqn_parse.h b/eqn_parse.h index be71b8a9..bb21a0e1 100644 --- a/eqn_parse.h +++ b/eqn_parse.h @@ -19,13 +19,11 @@ * For use in the roff(7) and eqn(7) parsers only. */ -struct mparse; struct roff_node; struct eqn_box; struct eqn_def; struct eqn_node { - struct mparse *parse; /* Main parser, for error reporting. */ struct roff_node *node; /* Syntax tree of this equation. */ struct eqn_def *defs; /* Array of definitions. */ char *data; /* Source code of this equation. */ @@ -41,7 +39,7 @@ struct eqn_node { }; -struct eqn_node *eqn_alloc(struct mparse *); +struct eqn_node *eqn_alloc(void); struct eqn_box *eqn_box_new(void); void eqn_box_free(struct eqn_box *); void eqn_free(struct eqn_node *); diff --git a/libmandoc.h b/libmandoc.h index cd2a1ba2..c2422590 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -45,11 +45,10 @@ struct buf { }; -struct mparse; struct roff; struct roff_man; -char *mandoc_getarg(struct mparse *, char **, int, int *); +char *mandoc_getarg(char **, int, int *); char *mandoc_normdate(struct roff_man *, char *, int, int); int mandoc_eos(const char *, size_t); int mandoc_strntoi(const char *, size_t, int); @@ -66,11 +65,10 @@ int preconv_encode(const struct buf *, size_t *, struct buf *, size_t *, int *); void roff_free(struct roff *); -struct roff *roff_alloc(struct mparse *, int); +struct roff *roff_alloc(int); void roff_reset(struct roff *); void roff_man_free(struct roff_man *); -struct roff_man *roff_man_alloc(struct roff *, struct mparse *, - const char *, int); +struct roff_man *roff_man_alloc(struct roff *, const char *, int); void roff_man_reset(struct roff_man *); int roff_parseln(struct roff *, int, struct buf *, int *); void roff_userret(struct roff *); diff --git a/man_macro.c b/man_macro.c index 3055197d..3fb04dac 100644 --- a/man_macro.c +++ b/man_macro.c @@ -456,6 +456,6 @@ man_args(struct roff_man *man, int line, int *pos, char *buf, char **v) if ('\0' == *start) return 0; - *v = mandoc_getarg(man->parse, v, line, pos); + *v = mandoc_getarg(v, line, pos); return 1; } @@ -401,7 +401,7 @@ mandoc_escape(const char **end, const char **start, int *sz) * or to the NUL byte terminating the argument line. */ char * -mandoc_getarg(struct mparse *parse, char **cpp, int ln, int *pos) +mandoc_getarg(char **cpp, int ln, int *pos) { char *start, *cp; int quoted, pairs, white; diff --git a/mandoc_headers.3 b/mandoc_headers.3 index 81fc21bb..18612685 100644 --- a/mandoc_headers.3 +++ b/mandoc_headers.3 @@ -192,7 +192,7 @@ and for .Vt enum mandoc_os . .Pp -Uses to opaque type +Uses the opaque type .Vt struct mparse from .Pa read.c @@ -260,11 +260,6 @@ Provides the functions described in .Xr mandoc 3 . .Pp -Uses the opaque type -.Vt struct mparse -from -.Pa read.c -for function prototypes. Uses the type .Vt struct roff_man from @@ -296,11 +291,7 @@ Provides utility functions needed by multiple parsers, and the top-level functions to call the parsers. .Pp -Uses the opaque types -.Vt struct mparse -from -.Pa read.c -and +Uses the opaque type .Vt struct roff from .Pa roff.c @@ -424,11 +415,6 @@ and the functions and .Fn eqn_reset . .Pp -Uses the opaque type -.Vt struct mparse -from -.Pa read.c -for function prototypes. Uses the type .Vt struct eqn_box from @@ -458,10 +444,6 @@ parsers only. Provides the functions documented in .Xr tbl 3 . .Pp -Uses the opaque type -.Vt struct mparse -from -.Pa read.c . Uses the types .Vt struct tbl_span from @@ -497,12 +479,6 @@ and the functions and .Fn tbl_reset . .Pp -Uses a pointer to the opaque type -.Vt struct mparse -from -.Pa read.c -as an opaque struct member. -.Pp When this header is included, the same file should not include interfaces of different parsers. .El diff --git a/mdoc_argv.c b/mdoc_argv.c index 6cd5efa2..752fb327 100644 --- a/mdoc_argv.c +++ b/mdoc_argv.c @@ -572,7 +572,7 @@ args(struct roff_man *mdoc, int line, int *pos, } p = &buf[*pos]; - *v = mandoc_getarg(mdoc->parse, &p, line, pos); + *v = mandoc_getarg(&p, line, pos); /* * After parsing the last word in this phrase, @@ -647,8 +647,8 @@ mparse_alloc(int options, enum mandoc_os os_e, const char *os_s) curp->options = options; curp->os_s = os_s; - curp->roff = roff_alloc(curp, options); - curp->man = roff_man_alloc(curp->roff, curp, curp->os_s, + curp->roff = roff_alloc(options); + curp->man = roff_man_alloc(curp->roff, curp->os_s, curp->options & MPARSE_QUICK ? 1 : 0); if (curp->options & MPARSE_MDOC) { curp->man->macroset = MACROSET_MDOC; @@ -98,7 +98,6 @@ struct mctx { }; struct roff { - struct mparse *parse; /* parse point */ struct roff_man *man; /* mdoc or man parser */ struct roffnode *last; /* leaf of stack */ struct mctx *mstack; /* stack of macro contexts */ @@ -780,12 +779,11 @@ roff_free(struct roff *r) } struct roff * -roff_alloc(struct mparse *parse, int options) +roff_alloc(int options) { struct roff *r; r = mandoc_calloc(1, sizeof(struct roff)); - r->parse = parse; r->reqtab = roffhash_alloc(0, ROFF_RENAMED); r->options = options; r->format = options & (MPARSE_MDOC | MPARSE_MAN); @@ -844,13 +842,11 @@ roff_man_free(struct roff_man *man) } struct roff_man * -roff_man_alloc(struct roff *roff, struct mparse *parse, - const char *os_s, int quick) +roff_man_alloc(struct roff *roff, const char *os_s, int quick) { struct roff_man *man; man = mandoc_calloc(1, sizeof(*man)); - man->parse = parse; man->roff = roff; man->os_s = os_s; man->quick = quick; @@ -3148,7 +3144,7 @@ roff_EQ(ROFF_ARGS) assert(r->eqn == NULL); if (r->last_eqn == NULL) - r->last_eqn = eqn_alloc(r->parse); + r->last_eqn = eqn_alloc(); else eqn_reset(r->last_eqn); r->eqn = r->last_eqn; @@ -3182,7 +3178,7 @@ roff_TS(ROFF_ARGS) mandoc_msg(MANDOCERR_BLK_BROKEN, ln, ppos, "TS breaks TS"); tbl_end(r->tbl, 0); } - r->tbl = tbl_alloc(ppos, ln, r->parse, r->last_tbl); + r->tbl = tbl_alloc(ppos, ln, r->last_tbl); if (r->last_tbl == NULL) r->first_tbl = r->tbl; r->last_tbl = r->tbl; @@ -3659,7 +3655,7 @@ roff_userdef(ROFF_ARGS) ctx->argv = mandoc_reallocarray(ctx->argv, ctx->argsz, sizeof(*ctx->argv)); } - arg = mandoc_getarg(r->parse, &src, ln, &pos); + arg = mandoc_getarg(&src, ln, &pos); sz = 1; /* For the terminating NUL. */ for (ap = arg; *ap != '\0'; ap++) sz += *ap == '"' ? 4 : 1; @@ -548,7 +548,6 @@ struct roff_meta { struct roff_man { struct roff_meta meta; /* Document meta-data. */ - struct mparse *parse; /* Parse pointer. */ struct roff *roff; /* Roff parser state data. */ struct ohash *mdocmac; /* Mdoc macro lookup table. */ struct ohash *manmac; /* Man macro lookup table. */ @@ -33,7 +33,6 @@ .Fo tbl_alloc .Fa "int pos" .Fa "int line" -.Fa "struct mparse *parse" .Fc .Ft void .Fo tbl_read @@ -104,12 +103,6 @@ but if there is a span, the function .Fn tbl_layout guarantees that these pointers are not .Dv NULL . -The function -.Fn tbl_alloc -guarantees that the -.Fa parse -member is not -.Dv NULL . .It Vt struct tbl_opts This structure describes the options of one table. It is used as a substructure of @@ -88,7 +88,7 @@ tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos) } struct tbl_node * -tbl_alloc(int pos, int line, struct mparse *parse, struct tbl_node *last_tbl) +tbl_alloc(int pos, int line, struct tbl_node *last_tbl) { struct tbl_node *tbl; @@ -97,7 +97,6 @@ tbl_alloc(int pos, int line, struct mparse *parse, struct tbl_node *last_tbl) last_tbl->next = tbl; tbl->line = line; tbl->pos = pos; - tbl->parse = parse; tbl->part = TBL_PART_OPTS; tbl->opts.tab = '\t'; tbl->opts.decimal = '.'; @@ -28,7 +28,6 @@ enum tbl_part { struct tbl_node { struct tbl_opts opts; /* Options for the whole table. */ - struct mparse *parse; /* For error reporting. */ struct tbl_node *next; /* Next table. */ struct tbl_row *first_row; /* First layout row. */ struct tbl_row *last_row; /* Last layout row. */ diff --git a/tbl_parse.h b/tbl_parse.h index b4e885fb..787ad833 100644 --- a/tbl_parse.h +++ b/tbl_parse.h @@ -19,11 +19,10 @@ * For use in the roff(7) and tbl(7) parsers only. */ -struct mparse; struct tbl_node; struct tbl_span; -struct tbl_node *tbl_alloc(int, int, struct mparse *, struct tbl_node *); +struct tbl_node *tbl_alloc(int, int, struct tbl_node *); int tbl_end(struct tbl_node *, int); void tbl_free(struct tbl_node *); void tbl_read(struct tbl_node *, int, const char *, int); |