* mandoc: Cleanup, no functional change: No need to expose the eqn(7)
@ 2018-12-13 5:24 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-12-13 5:24 UTC (permalink / raw)
To: source
Log Message:
-----------
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.
Modified Files:
--------------
mandoc:
Makefile
Makefile.depend
eqn.c
eqn_html.c
eqn_parse.h
eqn_term.c
mandoc.h
mandoc_headers.3
roff.c
tree.c
Added Files:
-----------
mandoc:
eqn.h
Revision Data
-------------
--- /dev/null
+++ eqn.h
@@ -0,0 +1,72 @@
+/* $Id: eqn.h,v 1.1 2018/12/13 05:23:38 schwarze Exp $ */
+/*
+ * 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. */
+};
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.347
retrieving revision 1.348
diff -Lroff.c -Lroff.c -u -p -r1.347 -r1.348
--- roff.c
+++ roff.c
@@ -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;
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/Makefile,v
retrieving revision 1.523
retrieving revision 1.524
diff -LMakefile -LMakefile -u -p -r1.523 -r1.524
--- Makefile
+++ Makefile
@@ -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
Index: mandoc_headers.3
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_headers.3,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lmandoc_headers.3 -Lmandoc_headers.3 -u -p -r1.22 -r1.23
--- mandoc_headers.3
+++ 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 ,
Index: eqn_term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/eqn_term.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -Leqn_term.c -Leqn_term.c -u -p -r1.18 -r1.19
--- eqn_term.c
+++ eqn_term.c
@@ -25,7 +25,7 @@
#include <stdlib.h>
#include <string.h>
-#include "mandoc.h"
+#include "eqn.h"
#include "out.h"
#include "term.h"
Index: eqn.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/eqn.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -Leqn.c -Leqn.c -u -p -r1.80 -r1.81
--- eqn.c
+++ eqn.c
@@ -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, struc
{
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;
Index: tree.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tree.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -Ltree.c -Ltree.c -u -p -r1.81 -r1.82
--- tree.c
+++ tree.c
@@ -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);
Index: eqn_html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/eqn_html.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -Leqn_html.c -Leqn_html.c -u -p -r1.17 -r1.18
--- eqn_html.c
+++ eqn_html.c
@@ -26,6 +26,7 @@
#include <string.h>
#include "mandoc.h"
+#include "eqn.h"
#include "out.h"
#include "html.h"
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.h,v
retrieving revision 1.256
retrieving revision 1.257
diff -Lmandoc.h -Lmandoc.h -u -p -r1.256 -r1.257
--- mandoc.h
+++ mandoc.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.
*/
Index: Makefile.depend
===================================================================
RCS file: /home/cvs/mandoc/mandoc/Makefile.depend,v
retrieving revision 1.35
retrieving revision 1.36
diff -LMakefile.depend -LMakefile.depend -u -p -r1.35 -r1.36
--- Makefile.depend
+++ Makefile.depend
@@ -27,9 +27,9 @@ dba_write.o: dba_write.c config.h dba_wr
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_
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
Index: eqn_parse.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/eqn_parse.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -Leqn_parse.h -Leqn_parse.h -u -p -r1.1 -r1.2
--- eqn_parse.h
+++ 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 *);
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-12-13 5:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13 5:24 mandoc: Cleanup, no functional change: No need to expose the eqn(7) schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).