diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | Makefile.depend | 20 | ||||
-rw-r--r-- | eqn.c | 15 | ||||
-rw-r--r-- | eqn_parse.h | 49 | ||||
-rw-r--r-- | libroff.h | 48 | ||||
-rw-r--r-- | mandoc_headers.3 | 73 | ||||
-rw-r--r-- | roff.c | 8 |
7 files changed, 117 insertions, 98 deletions
@@ -155,13 +155,13 @@ DISTFILES = INSTALL \ dbm_map.h \ demandoc.1 \ eqn.7 \ + eqn_parse.h \ gmdiff \ html.h \ lib.in \ libman.h \ libmandoc.h \ libmdoc.h \ - libroff.h \ main.h \ makewhatis.8 \ man.1 \ diff --git a/Makefile.depend b/Makefile.depend index da366a1c..92945589 100644 --- a/Makefile.depend +++ b/Makefile.depend @@ -27,7 +27,7 @@ dba_write.o: dba_write.c config.h dba_write.h dbm.o: dbm.c config.h mansearch.h dbm_map.h dbm.h dbm_map.o: dbm_map.c config.h mansearch.h dbm_map.h dbm.h demandoc.o: demandoc.c config.h mandoc.h roff.h man.h mdoc.h -eqn.o: eqn.c config.h mandoc_aux.h mandoc.h roff.h libmandoc.h libroff.h +eqn.o: eqn.c config.h mandoc_aux.h mandoc.h roff.h libmandoc.h eqn_parse.h eqn_html.o: eqn_html.c config.h mandoc.h out.h html.h eqn_term.o: eqn_term.c config.h mandoc.h out.h term.h html.o: html.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h mandoc.h roff.h out.h html.h manconf.h main.h @@ -56,24 +56,24 @@ mdoc_state.o: mdoc_state.c mandoc.h roff.h mdoc.h libmandoc.h libmdoc.h mdoc_term.o: mdoc_term.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h out.h term.h tag.h main.h mdoc_validate.o: mdoc_validate.c config.h mandoc_aux.h mandoc.h mandoc_xr.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h msec.o: msec.c config.h mandoc.h libmandoc.h msec.in -out.o: out.c config.h mandoc_aux.h mandoc.h out.h +out.o: out.c config.h mandoc_aux.h mandoc.h tbl.h out.h preconv.o: preconv.c config.h mandoc.h libmandoc.h read.o: read.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h man.h libmandoc.h -roff.o: roff.c config.h mandoc.h mandoc_aux.h mandoc_ohash.h compat_ohash.h roff.h libmandoc.h roff_int.h libroff.h predefs.in +roff.o: roff.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h mandoc.h roff.h libmandoc.h roff_int.h tbl_parse.h eqn_parse.h predefs.in roff_html.o: roff_html.c mandoc.h roff.h out.h html.h roff_term.o: roff_term.c mandoc.h roff.h out.h term.h roff_validate.o: roff_validate.c mandoc.h roff.h libmandoc.h roff_int.h soelim.o: soelim.c config.h compat_stringlist.h st.o: st.c config.h mandoc.h roff.h mdoc.h libmdoc.h st.in tag.o: tag.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h tag.h -tbl.o: tbl.c config.h mandoc.h mandoc_aux.h libmandoc.h libroff.h -tbl_data.o: tbl_data.c config.h mandoc.h mandoc_aux.h libmandoc.h libroff.h -tbl_html.o: tbl_html.c config.h mandoc.h out.h html.h -tbl_layout.o: tbl_layout.c config.h mandoc.h mandoc_aux.h libmandoc.h libroff.h -tbl_opts.o: tbl_opts.c config.h mandoc.h libmandoc.h libroff.h -tbl_term.o: tbl_term.c config.h mandoc.h out.h term.h +tbl.o: tbl.c config.h mandoc_aux.h mandoc.h tbl.h libmandoc.h tbl_parse.h tbl_int.h +tbl_data.o: tbl_data.c config.h mandoc_aux.h mandoc.h tbl.h libmandoc.h tbl_int.h +tbl_html.o: tbl_html.c config.h tbl.h out.h html.h +tbl_layout.o: tbl_layout.c config.h mandoc_aux.h mandoc.h tbl.h libmandoc.h tbl_int.h +tbl_opts.o: tbl_opts.c config.h mandoc.h tbl.h libmandoc.h tbl_int.h +tbl_term.o: tbl_term.c config.h mandoc.h tbl.h out.h term.h term.o: term.c config.h mandoc.h mandoc_aux.h out.h term.h main.h term_ascii.o: term_ascii.c config.h mandoc.h mandoc_aux.h out.h term.h manconf.h main.h term_ps.o: term_ps.c config.h mandoc_aux.h out.h term.h manconf.h main.h term_tab.o: term_tab.c mandoc_aux.h out.h term.h -tree.o: tree.c config.h mandoc.h roff.h mdoc.h man.h main.h +tree.o: tree.c config.h mandoc.h roff.h mdoc.h man.h tbl.h main.h @@ -30,9 +30,8 @@ #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" -#include "tbl.h" #include "libmandoc.h" -#include "libroff.h" +#include "eqn_parse.h" #define EQN_NEST_MAX 128 /* maximum nesting of defines */ #define STRNEQ(p1, sz1, p2, sz2) \ @@ -285,6 +284,13 @@ enum parse_mode { MODE_TOK }; +struct eqn_def { + char *key; + size_t keysz; + char *val; + size_t valsz; +}; + static struct eqn_box *eqn_box_alloc(struct eqn_node *, struct eqn_box *); static struct eqn_box *eqn_box_makebinary(struct eqn_node *, struct eqn_box *); @@ -469,6 +475,8 @@ eqn_next(struct eqn_node *ep, enum parse_mode mode) void eqn_box_free(struct eqn_box *bp) { + if (bp == NULL) + return; if (bp->first) eqn_box_free(bp->first); @@ -1093,6 +1101,9 @@ eqn_free(struct eqn_node *p) { int i; + if (p == NULL) + return; + for (i = 0; i < (int)p->defsz; i++) { free(p->defs[i].key); free(p->defs[i].val); diff --git a/eqn_parse.h b/eqn_parse.h new file mode 100644 index 00000000..66eca319 --- /dev/null +++ b/eqn_parse.h @@ -0,0 +1,49 @@ +/* $Id$ */ +/* + * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2014, 2017 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 + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * External interface of the eqn(7) parser. + * 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. */ + char *start; /* First byte of the current token. */ + char *end; /* First byte of the next token. */ + size_t defsz; /* Number of definitions. */ + size_t sz; /* Length of the source code. */ + size_t toksz; /* Length of the current token. */ + int gsize; /* Default point size. */ + int delim; /* In-line delimiters enabled. */ + char odelim; /* In-line opening delimiter. */ + char cdelim; /* In-line closing delimiter. */ +}; + + +struct eqn_node *eqn_alloc(struct mparse *); +void eqn_box_free(struct eqn_box *); +void eqn_free(struct eqn_node *); +void eqn_parse(struct eqn_node *); +void eqn_read(struct eqn_node *, const char *); +void eqn_reset(struct eqn_node *); diff --git a/libroff.h b/libroff.h deleted file mode 100644 index 828a5cdd..00000000 --- a/libroff.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $Id$ */ -/* - * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014, 2017 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 - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -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 */ - char *start; /* first byte of the current token */ - char *end; /* first byte of the next token */ - size_t defsz; /* number of definitions */ - size_t sz; /* length of the source code */ - size_t toksz; /* length of the current token */ - int gsize; /* default point size */ - int delim; /* in-line delimiters enabled */ - char odelim; /* in-line opening delimiter */ - char cdelim; /* in-line closing delimiter */ -}; - -struct eqn_def { - char *key; - size_t keysz; - char *val; - size_t valsz; -}; - - -struct eqn_node *eqn_alloc(struct mparse *); -void eqn_box_free(struct eqn_box *); -void eqn_free(struct eqn_node *); -void eqn_parse(struct eqn_node *); -void eqn_read(struct eqn_node *, const char *); -void eqn_reset(struct eqn_node *); diff --git a/mandoc_headers.3 b/mandoc_headers.3 index 7948d15d..cd264963 100644 --- a/mandoc_headers.3 +++ b/mandoc_headers.3 @@ -231,9 +231,7 @@ from as an opaque type for function prototypes. .Pp When this header is included, the same file should not include -.Pa libman.h -or -.Pa libroff.h . +internals of different parsers. .It Qq Pa man.h Provides the functions .Fn man_* @@ -252,9 +250,7 @@ from as an opaque type for function prototypes. .Pp When this header is included, the same file should not include -.Pa libmdoc.h -or -.Pa libroff.h . +internals of different parsers. .El .Ss Parser internals Most of the following headers require inclusion of a parser interface header @@ -351,10 +347,7 @@ from as opaque types for function prototypes. .Pp When this header is included, the same file should not include -.Pa man.h , -.Pa libman.h , -or -.Pa libroff.h . +interfaces of different parsers. .It Qq Pa libman.h Requires .Qq Pa roff.h @@ -376,38 +369,54 @@ from as opaque types for function prototypes. .Pp When this header is included, the same file should not include -.Pa mdoc.h , -.Pa libmdoc.h , -or -.Pa libroff.h . -.It Qq Pa libroff.h +interfaces of different parsers. +.It Qq Pa eqn_parse.h +External interface of the +.Xr eqn 7 +parser, for use in the +.Xr roff 7 +and +.Xr eqn 7 +parsers only. +.Pp Requires .In sys/types.h for -.Vt size_t -and -.Qq Pa mandoc.h -for -.Vt struct eqn_box . +.Vt size_t . .Pp Provides -.Vt struct eqn_def , -.Vt struct eqn_node , -and many functions internal to the -.Xr eqn 7 -parser. +.Vt struct eqn_node +and the functions +.Fn eqn_alloc , +.Fn eqn_box_free , +.Fn eqn_free , +.Fn eqn_parse , +.Fn eqn_read , +and +.Fn eqn_reset . .Pp Uses the opaque type .Vt struct mparse from -.Pa read.c . +.Pa read.c +for function prototypes. +Uses the type +.Vt struct eqn_box +from +.Pa mandoc.h +as an opaque type for function prototypes. +Uses the types +.Vt struct roff_node +from +.Pa roff.h +and +.Vt struct eqn_def +from +.Pa eqn.c +as opaque struct members. .Pp When this header is included, the same file should not include -.Pa man.h , -.Pa mdoc.h , -.Pa libman.h , -or -.Pa libmdoc.h . +internals of different parsers. .It Qq Pa tbl_parse.h External interface of the .Xr tbl 7 @@ -435,7 +444,7 @@ from as opaque types for function prototypes. .Pp When this header is included, the same file should not include -internals of a different parser. +internals of different parsers. .It Qq Pa tbl_int.h Internal interfaces of the .Xr tbl 7 @@ -34,8 +34,8 @@ #include "roff.h" #include "libmandoc.h" #include "roff_int.h" -#include "libroff.h" #include "tbl_parse.h" +#include "eqn_parse.h" /* Maximum number of string expansions per line, to break infinite loops. */ #define EXPAND_LIMIT 1000 @@ -723,8 +723,7 @@ roff_free1(struct roff *r) tbl_free(r->first_tbl); r->first_tbl = r->last_tbl = r->tbl = NULL; - if (r->last_eqn != NULL) - eqn_free(r->last_eqn); + eqn_free(r->last_eqn); r->last_eqn = r->eqn = NULL; while (r->mstackpos >= 0) @@ -1079,8 +1078,7 @@ roff_node_free(struct roff_node *n) mdoc_argv_free(n->args); if (n->type == ROFFT_BLOCK || n->type == ROFFT_ELEM) free(n->norm); - if (n->eqn != NULL) - eqn_box_free(n->eqn); + eqn_box_free(n->eqn); free(n->string); free(n); } |