aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-12-13 05:23:37 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-12-13 05:23:37 +0000
commit32c0933851c645dfc5d1af1bda32e80c9f237254 (patch)
treefab2cd59317b0b0eabad302f92f03d5eadc60c25
parent41c83570cd0b176c663b583e5990f9869f214754 (diff)
downloadmandoc-32c0933851c645dfc5d1af1bda32e80c9f237254.tar.gz
mandoc-32c0933851c645dfc5d1af1bda32e80c9f237254.tar.zst
mandoc-32c0933851c645dfc5d1af1bda32e80c9f237254.zip
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--Makefile9
-rw-r--r--Makefile.depend8
-rw-r--r--eqn.c18
-rw-r--r--eqn.h72
-rw-r--r--eqn_html.c3
-rw-r--r--eqn_parse.h5
-rw-r--r--eqn_term.c4
-rw-r--r--mandoc.h70
-rw-r--r--mandoc_headers.322
-rw-r--r--roff.c5
-rw-r--r--tree.c3
11 files changed, 125 insertions, 94 deletions
diff --git a/Makefile b/Makefile
index b76f6510..8bfc1acc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.523 2018/12/13 03:40:13 schwarze Exp $
+# $Id: Makefile,v 1.524 2018/12/13 05:23:37 schwarze Exp $
#
# Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
# Copyright (c) 2011, 2013-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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
diff --git a/eqn.c b/eqn.c
index 5f4e8ae6..2383c798 100644
--- a/eqn.c
+++ b/eqn.c
@@ -1,7 +1,7 @@
-/* $Id: eqn.c,v 1.80 2018/12/13 03:40:13 schwarze Exp $ */
+/* $Id: eqn.c,v 1.81 2018/12/13 05:23:38 schwarze Exp $ */
/*
* 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;
diff --git a/eqn.h b/eqn.h
new file mode 100644
index 00000000..c7c7aa15
--- /dev/null
+++ b/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. */
+};
diff --git a/eqn_html.c b/eqn_html.c
index 51f14423..1fe41ecb 100644
--- a/eqn_html.c
+++ b/eqn_html.c
@@ -1,4 +1,4 @@
-/* $Id: eqn_html.c,v 1.17 2017/07/14 13:32:35 schwarze Exp $ */
+/* $Id: eqn_html.c,v 1.18 2018/12/13 05:23:38 schwarze Exp $ */
/*
* Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 873720b2..c0090119 100644
--- a/eqn_parse.h
+++ b/eqn_parse.h
@@ -1,7 +1,7 @@
-/* $Id: eqn_parse.h,v 1.1 2018/12/13 03:40:13 schwarze Exp $ */
+/* $Id: eqn_parse.h,v 1.2 2018/12/13 05:23:38 schwarze Exp $ */
/*
* 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 *);
diff --git a/eqn_term.c b/eqn_term.c
index b1a438d9..3e27233b 100644
--- a/eqn_term.c
+++ b/eqn_term.c
@@ -1,4 +1,4 @@
-/* $Id: eqn_term.c,v 1.18 2018/10/02 12:18:33 schwarze Exp $ */
+/* $Id: eqn_term.c,v 1.19 2018/12/13 05:23:38 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -25,7 +25,7 @@
#include <stdlib.h>
#include <string.h>
-#include "mandoc.h"
+#include "eqn.h"
#include "out.h"
#include "term.h"
diff --git a/mandoc.h b/mandoc.h
index 5e3a42a9..20a1ad0b 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.256 2018/12/12 21:54:35 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.257 2018/12/13 05:23:38 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 199f6dfc..0adbf5a2 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 ,
diff --git a/roff.c b/roff.c
index 283f3997..667f5615 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.347 2018/12/13 03:40:13 schwarze Exp $ */
+/* $Id: roff.c,v 1.348 2018/12/13 05:23:38 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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;
diff --git a/tree.c b/tree.c
index 63f594f5..67358243 100644
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.81 2018/12/12 21:54:35 schwarze Exp $ */
+/* $Id: tree.c,v 1.82 2018/12/13 05:23:38 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);