diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-13 05:23:37 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-12-13 05:23:37 +0000 |
commit | 5d4d2785b08ebc101f0eb519b9a0480a9c6f4b08 (patch) | |
tree | 15f9648cba61edda780139b44de9745a3fa812fa | |
parent | b705aa5d322006a519c498654b59f3b1ba185233 (diff) | |
download | mandoc-5d4d2785b08ebc101f0eb519b9a0480a9c6f4b08.tar.gz |
Cleanup, no functional change:
No need to expose the eqn(7) syntax tree data structures everywhere.
Move them to their own include file, "eqn.h".
While here, delete the unused enum eqn_pilet.
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | Makefile.depend | 8 | ||||
-rw-r--r-- | eqn.c | 16 | ||||
-rw-r--r-- | eqn.h | 72 | ||||
-rw-r--r-- | eqn_html.c | 1 | ||||
-rw-r--r-- | eqn_parse.h | 3 | ||||
-rw-r--r-- | eqn_term.c | 2 | ||||
-rw-r--r-- | mandoc.h | 68 | ||||
-rw-r--r-- | mandoc_headers.3 | 22 | ||||
-rw-r--r-- | roff.c | 3 | ||||
-rw-r--r-- | tree.c | 1 |
11 files changed, 117 insertions, 86 deletions
@@ -155,6 +155,7 @@ DISTFILES = INSTALL \ dbm_map.h \ demandoc.1 \ eqn.7 \ + eqn.h \ eqn_parse.h \ gmdiff \ html.h \ @@ -348,7 +349,8 @@ WWW_MANS = apropos.1.html \ man.cgi.8.html \ mandocd.8.html -WWW_INCS = man.h.html \ +WWW_INCS = eqn.h.html \ + man.h.html \ manconf.h.html \ mandoc.h.html \ mandoc_aux.h.html \ @@ -426,7 +428,7 @@ lib-install: libmandoc.a mkdir -p $(DESTDIR)$(INCLUDEDIR) mkdir -p $(DESTDIR)$(MANDIR)/man3 $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR) - $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h roff.h tbl.h \ + $(INSTALL_LIB) eqn.h man.h mandoc.h mandoc_aux.h mdoc.h roff.h tbl.h \ $(DESTDIR)$(INCLUDEDIR) $(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \ mansearch.3 mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3 @@ -481,6 +483,7 @@ uninstall: rm -f $(DESTDIR)$(MANDIR)/man3/mansearch.3 rm -f $(DESTDIR)$(MANDIR)/man3/mchars_alloc.3 rm -f $(DESTDIR)$(MANDIR)/man3/tbl.3 + rm -f $(DESTDIR)$(INCLUDEDIR)/eqn.h rm -f $(DESTDIR)$(INCLUDEDIR)/man.h rm -f $(DESTDIR)$(INCLUDEDIR)/mandoc.h rm -f $(DESTDIR)$(INCLUDEDIR)/mandoc_aux.h diff --git a/Makefile.depend b/Makefile.depend index 92945589..8bab156a 100644 --- a/Makefile.depend +++ b/Makefile.depend @@ -27,9 +27,9 @@ 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 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 +eqn.o: eqn.c config.h mandoc_aux.h mandoc.h roff.h eqn.h libmandoc.h eqn_parse.h +eqn_html.o: eqn_html.c config.h mandoc.h eqn.h out.h html.h +eqn_term.o: eqn_term.c config.h eqn.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 lib.o: lib.c config.h mandoc.h roff.h mdoc.h libmdoc.h lib.in main.o: main.c config.h mandoc_aux.h mandoc.h mandoc_xr.h roff.h mdoc.h man.h tag.h main.h manconf.h mansearch.h @@ -76,4 +76,4 @@ 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 tbl.h main.h +tree.o: tree.c config.h mandoc.h roff.h mdoc.h man.h tbl.h eqn.h main.h @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2014, 2015, 2017, 2018 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 @@ -30,6 +30,7 @@ #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" +#include "eqn.h" #include "libmandoc.h" #include "eqn_parse.h" @@ -491,6 +492,16 @@ eqn_box_free(struct eqn_box *bp) free(bp); } +struct eqn_box * +eqn_box_new(void) +{ + struct eqn_box *bp; + + bp = mandoc_calloc(1, sizeof(*bp)); + bp->expectargs = UINT_MAX; + return bp; +} + /* * Allocate a box as the last child of the parent node. */ @@ -499,10 +510,9 @@ eqn_box_alloc(struct eqn_node *ep, struct eqn_box *parent) { struct eqn_box *bp; - bp = mandoc_calloc(1, sizeof(struct eqn_box)); + bp = eqn_box_new(); bp->parent = parent; bp->parent->args++; - bp->expectargs = UINT_MAX; bp->font = bp->parent->font; bp->size = ep->gsize; @@ -0,0 +1,72 @@ +/* $Id$ */ +/* + * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> + * + * 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. + * + * Public data types for eqn(7) syntax trees. + */ + +enum eqn_boxt { + EQN_TEXT, /* Text, e.g. number, variable, operator, ... */ + EQN_SUBEXPR, /* Nested eqn(7) subexpression. */ + EQN_LIST, /* List, for example in braces. */ + EQN_PILE, /* Vertical pile. */ + EQN_MATRIX /* List of columns. */ +}; + +enum eqn_fontt { + EQNFONT_NONE = 0, + EQNFONT_ROMAN, + EQNFONT_BOLD, + EQNFONT_FAT, + EQNFONT_ITALIC, + EQNFONT__MAX +}; + +enum eqn_post { + EQNPOS_NONE = 0, + EQNPOS_SUP, + EQNPOS_SUBSUP, + EQNPOS_SUB, + EQNPOS_TO, + EQNPOS_FROM, + EQNPOS_FROMTO, + EQNPOS_OVER, + EQNPOS_SQRT, + EQNPOS__MAX +}; + + /* + * A "box" is a parsed mathematical expression as defined by the eqn.7 + * grammar. + */ +struct eqn_box { + struct eqn_box *parent; + struct eqn_box *prev; + struct eqn_box *next; + struct eqn_box *first; /* First child node. */ + struct eqn_box *last; /* Last child node. */ + char *text; /* Text (or NULL). */ + char *left; /* Left-hand fence. */ + char *right; /* Right-hand fence. */ + char *top; /* Symbol above. */ + char *bottom; /* Symbol below. */ + size_t expectargs; /* Maximal number of arguments. */ + size_t args; /* Actual number of arguments. */ + int size; /* Font size. */ +#define EQN_DEFSIZE INT_MIN + enum eqn_boxt type; /* Type of node. */ + enum eqn_fontt font; /* Font in this box. */ + enum eqn_post pos; /* Position of the next box. */ +}; @@ -26,6 +26,7 @@ #include <string.h> #include "mandoc.h" +#include "eqn.h" #include "out.h" #include "html.h" diff --git a/eqn_parse.h b/eqn_parse.h index 66eca319..be71b8a9 100644 --- a/eqn_parse.h +++ b/eqn_parse.h @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2014, 2017, 2018 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 @@ -42,6 +42,7 @@ struct eqn_node { struct eqn_node *eqn_alloc(struct mparse *); +struct eqn_box *eqn_box_new(void); void eqn_box_free(struct eqn_box *); void eqn_free(struct eqn_node *); void eqn_parse(struct eqn_node *); @@ -25,7 +25,7 @@ #include <stdlib.h> #include <string.h> -#include "mandoc.h" +#include "eqn.h" #include "out.h" #include "term.h" @@ -241,74 +241,6 @@ enum mandocerr { MANDOCERR_MAX }; -enum eqn_boxt { - EQN_TEXT, /* text (number, variable, whatever) */ - EQN_SUBEXPR, /* nested `eqn' subexpression */ - EQN_LIST, /* list (braces, etc.) */ - EQN_PILE, /* vertical pile */ - EQN_MATRIX /* pile of piles */ -}; - -enum eqn_fontt { - EQNFONT_NONE = 0, - EQNFONT_ROMAN, - EQNFONT_BOLD, - EQNFONT_FAT, - EQNFONT_ITALIC, - EQNFONT__MAX -}; - -enum eqn_post { - EQNPOS_NONE = 0, - EQNPOS_SUP, - EQNPOS_SUBSUP, - EQNPOS_SUB, - EQNPOS_TO, - EQNPOS_FROM, - EQNPOS_FROMTO, - EQNPOS_OVER, - EQNPOS_SQRT, - EQNPOS__MAX -}; - -enum eqn_pilet { - EQNPILE_NONE = 0, - EQNPILE_PILE, - EQNPILE_CPILE, - EQNPILE_RPILE, - EQNPILE_LPILE, - EQNPILE_COL, - EQNPILE_CCOL, - EQNPILE_RCOL, - EQNPILE_LCOL, - EQNPILE__MAX -}; - - /* - * A "box" is a parsed mathematical expression as defined by the eqn.7 - * grammar. - */ -struct eqn_box { - int size; /* font size of expression */ -#define EQN_DEFSIZE INT_MIN - enum eqn_boxt type; /* type of node */ - struct eqn_box *first; /* first child node */ - struct eqn_box *last; /* last child node */ - struct eqn_box *next; /* node sibling */ - struct eqn_box *prev; /* node sibling */ - struct eqn_box *parent; /* node sibling */ - char *text; /* text (or NULL) */ - char *left; /* fence left-hand */ - char *right; /* fence right-hand */ - char *top; /* expression over-symbol */ - char *bottom; /* expression under-symbol */ - size_t args; /* arguments in parent */ - size_t expectargs; /* max arguments in parent */ - enum eqn_post pos; /* position of next box */ - enum eqn_fontt font; /* font of box */ - enum eqn_pilet pile; /* equation piling */ -}; - /* * Parse options. */ diff --git a/mandoc_headers.3 b/mandoc_headers.3 index cd264963..b69582d4 100644 --- a/mandoc_headers.3 +++ b/mandoc_headers.3 @@ -97,11 +97,6 @@ Provides .Vt enum mandocerr , .Vt enum mandoclevel , .Vt enum mandoc_os , -.Vt enum eqn_boxt , -.Vt enum eqn_fontt , -.Vt enum eqn_pilet , -.Vt enum eqn_post , -.Vt struct eqn_box , the function prototype typedef .Fn mandocmsg , the function @@ -143,6 +138,22 @@ Provides .Vt struct tbl_dat , and .Vt struct tbl_span . +.It Qq Pa eqn.h +Data structures for the +.Xr eqn 7 +parse tree; can be used everywhere. +.Pp +Requires +.In sys/types.h +for +.Vt size_t . +.Pp +Provides +.Vt enum eqn_boxt , +.Vt enum eqn_fontt , +.Vt enum eqn_post , +and +.Vt struct eqn_box . .It Qq Pa mandoc_xr.h Cross reference validation; intended for use in the main program and in parsers, but not in formatters. @@ -388,6 +399,7 @@ Provides .Vt struct eqn_node and the functions .Fn eqn_alloc , +.Fn eqn_box_new , .Fn eqn_box_free , .Fn eqn_free , .Fn eqn_parse , @@ -3153,8 +3153,7 @@ roff_EQ(ROFF_ARGS) n = roff_node_alloc(r->man, ln, ppos, ROFFT_EQN, TOKEN_NONE); if (ln > r->man->last->line) n->flags |= NODE_LINE; - n->eqn = mandoc_calloc(1, sizeof(*n->eqn)); - n->eqn->expectargs = UINT_MAX; + n->eqn = eqn_box_new(); roff_node_append(r->man, n); r->man->next = ROFF_NEXT_SIBLING; @@ -30,6 +30,7 @@ #include "mdoc.h" #include "man.h" #include "tbl.h" +#include "eqn.h" #include "main.h" static void print_box(const struct eqn_box *, int); |