summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/mandoc/eqn.c17
-rw-r--r--usr.bin/mandoc/eqn_parse.h49
-rw-r--r--usr.bin/mandoc/libroff.h48
-rw-r--r--usr.bin/mandoc/roff.c10
4 files changed, 67 insertions, 57 deletions
diff --git a/usr.bin/mandoc/eqn.c b/usr.bin/mandoc/eqn.c
index ef6ef0d80ef..cf7b3b8121b 100644
--- a/usr.bin/mandoc/eqn.c
+++ b/usr.bin/mandoc/eqn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eqn.c,v 1.42 2018/12/12 21:54:30 schwarze Exp $ */
+/* $OpenBSD: eqn.c,v 1.43 2018/12/13 03:40:09 schwarze Exp $ */
/*
* Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -28,9 +28,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) \
@@ -283,6 +282,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 *);
@@ -467,6 +473,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);
@@ -1091,6 +1099,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/usr.bin/mandoc/eqn_parse.h b/usr.bin/mandoc/eqn_parse.h
new file mode 100644
index 00000000000..b829ca25be9
--- /dev/null
+++ b/usr.bin/mandoc/eqn_parse.h
@@ -0,0 +1,49 @@
+/* $OpenBSD: eqn_parse.h,v 1.1 2018/12/13 03:40:09 schwarze Exp $ */
+/*
+ * 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/usr.bin/mandoc/libroff.h b/usr.bin/mandoc/libroff.h
deleted file mode 100644
index a505ef1d077..00000000000
--- a/usr.bin/mandoc/libroff.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $OpenBSD: libroff.h,v 1.21 2018/12/13 02:05:57 schwarze Exp $ */
-/*
- * 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/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 1b0bf0b9687..a1767789ecc 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.218 2018/12/13 02:05:57 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.219 2018/12/13 03:40:09 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -32,8 +32,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
@@ -721,8 +721,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)
@@ -1077,8 +1076,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);
}