summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2018-12-13 02:05:57 +0000
committerschwarze <schwarze@openbsd.org>2018-12-13 02:05:57 +0000
commitfb382a019a53c397434fb3f70980852770813a0c (patch)
tree0dcc008cfce13eccc79b35d2358d8fc9ee4fe79c
parentadd commented-out "val-log-level: 2" next to the uncommentable line to (diff)
downloadwireguard-openbsd-fb382a019a53c397434fb3f70980852770813a0c.tar.xz
wireguard-openbsd-fb382a019a53c397434fb3f70980852770813a0c.zip
Cleanup, no functional change:
Move tbl(7)-specific parser internals out of libroff.h. Move some tbl(7)-internal processing from roff.c to tbl.c.
-rw-r--r--usr.bin/mandoc/libroff.h38
-rw-r--r--usr.bin/mandoc/roff.c36
-rw-r--r--usr.bin/mandoc/roff.h4
-rw-r--r--usr.bin/mandoc/tbl.c64
-rw-r--r--usr.bin/mandoc/tbl_data.c4
-rw-r--r--usr.bin/mandoc/tbl_int.h48
-rw-r--r--usr.bin/mandoc/tbl_layout.c4
-rw-r--r--usr.bin/mandoc/tbl_opts.c4
-rw-r--r--usr.bin/mandoc/tbl_parse.h31
9 files changed, 140 insertions, 93 deletions
diff --git a/usr.bin/mandoc/libroff.h b/usr.bin/mandoc/libroff.h
index 2f78abd960e..a505ef1d077 100644
--- a/usr.bin/mandoc/libroff.h
+++ b/usr.bin/mandoc/libroff.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: libroff.h,v 1.20 2017/07/08 17:52:42 schwarze Exp $ */
+/* $OpenBSD: libroff.h,v 1.21 2018/12/13 02:05:57 schwarze Exp $ */
/*
- * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * 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
@@ -16,27 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-enum tbl_part {
- TBL_PART_OPTS, /* in options (first line) */
- TBL_PART_LAYOUT, /* describing layout */
- TBL_PART_DATA, /* creating data rows */
- TBL_PART_CDATA /* continue previous row */
-};
-
-struct tbl_node {
- struct mparse *parse; /* parse point */
- int pos; /* invocation column */
- int line; /* invocation line */
- enum tbl_part part;
- struct tbl_opts opts;
- struct tbl_row *first_row;
- struct tbl_row *last_row;
- struct tbl_span *first_span;
- struct tbl_span *current_span;
- struct tbl_span *last_span;
- struct tbl_node *next;
-};
-
struct eqn_node {
struct mparse *parse; /* main parser, for error reporting */
struct roff_node *node; /* syntax tree of this equation */
@@ -61,17 +40,6 @@ struct eqn_def {
};
-struct tbl_node *tbl_alloc(int, int, struct mparse *);
-void tbl_restart(int, int, struct tbl_node *);
-void tbl_free(struct tbl_node *);
-void tbl_reset(struct tbl_node *);
-void tbl_read(struct tbl_node *, int, const char *, int);
-void tbl_option(struct tbl_node *, int, const char *, int *);
-void tbl_layout(struct tbl_node *, int, const char *, int);
-void tbl_data(struct tbl_node *, int, const char *, int);
-void tbl_cdata(struct tbl_node *, int, const char *, int);
-const struct tbl_span *tbl_span(struct tbl_node *);
-int tbl_end(struct tbl_node *);
struct eqn_node *eqn_alloc(struct mparse *);
void eqn_box_free(struct eqn_box *);
void eqn_free(struct eqn_node *);
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index a3ef67721e1..1b0bf0b9687 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.217 2018/12/12 21:54:30 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.218 2018/12/13 02:05:57 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -30,10 +30,10 @@
#include "mandoc_ohash.h"
#include "mandoc.h"
#include "roff.h"
-#include "tbl.h"
#include "libmandoc.h"
#include "roff_int.h"
#include "libroff.h"
+#include "tbl_parse.h"
/* Maximum number of string expansions per line, to break infinite loops. */
#define EXPAND_LIMIT 1000
@@ -166,7 +166,7 @@ static int roffnode_cleanscope(struct roff *);
static int roffnode_pop(struct roff *);
static void roffnode_push(struct roff *, enum roff_tok,
const char *, int, int);
-static void roff_addtbl(struct roff_man *, struct tbl_node *);
+static void roff_addtbl(struct roff_man *, int, struct tbl_node *);
static int roff_als(ROFF_ARGS);
static int roff_block(ROFF_ARGS);
static int roff_block_text(ROFF_ARGS);
@@ -716,13 +716,9 @@ roffnode_push(struct roff *r, enum roff_tok tok, const char *name,
static void
roff_free1(struct roff *r)
{
- struct tbl_node *tbl;
int i;
- while (NULL != (tbl = r->first_tbl)) {
- r->first_tbl = tbl->next;
- tbl_free(tbl);
- }
+ tbl_free(r->first_tbl);
r->first_tbl = r->last_tbl = r->tbl = NULL;
if (r->last_eqn != NULL)
@@ -1012,15 +1008,15 @@ roff_body_alloc(struct roff_man *man, int line, int pos, int tok)
}
static void
-roff_addtbl(struct roff_man *man, struct tbl_node *tbl)
+roff_addtbl(struct roff_man *man, int line, struct tbl_node *tbl)
{
struct roff_node *n;
- const struct tbl_span *span;
+ struct tbl_span *span;
if (man->macroset == MACROSET_MAN)
man_breakscope(man, ROFF_TS);
while ((span = tbl_span(tbl)) != NULL) {
- n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE);
+ n = roff_node_alloc(man, line, 0, ROFFT_TBL, TOKEN_NONE);
n->span = span;
roff_node_append(man, n);
n->flags |= NODE_VALID | NODE_ENDED;
@@ -1658,7 +1654,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
}
if (r->tbl != NULL && (ctl == 0 || buf->buf[pos] == '\0')) {
tbl_read(r->tbl, ln, buf->buf, ppos);
- roff_addtbl(r->man, r->tbl);
+ roff_addtbl(r->man, ln, r->tbl);
return e;
}
if ( ! ctl)
@@ -1702,7 +1698,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
while (buf->buf[pos] == ' ')
pos++;
tbl_read(r->tbl, ln, buf->buf, pos);
- roff_addtbl(r->man, r->tbl);
+ roff_addtbl(r->man, ln, r->tbl);
return ROFF_IGN;
}
@@ -1765,9 +1761,7 @@ roff_endparse(struct roff *r)
}
if (r->tbl != NULL) {
- mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
- r->tbl->line, r->tbl->pos, "TS");
- tbl_end(r->tbl);
+ tbl_end(r->tbl, 1);
r->tbl = NULL;
}
}
@@ -3058,7 +3052,7 @@ roff_TE(ROFF_ARGS)
ln, ppos, "TE");
return ROFF_IGN;
}
- if (tbl_end(r->tbl) == 0) {
+ if (tbl_end(r->tbl, 0) == 0) {
r->tbl = NULL;
free(buf->buf);
buf->buf = mandoc_strdup(".sp");
@@ -3199,12 +3193,10 @@ roff_TS(ROFF_ARGS)
if (r->tbl != NULL) {
mandoc_msg(MANDOCERR_BLK_BROKEN, r->parse,
ln, ppos, "TS breaks TS");
- tbl_end(r->tbl);
+ tbl_end(r->tbl, 0);
}
- r->tbl = tbl_alloc(ppos, ln, r->parse);
- if (r->last_tbl)
- r->last_tbl->next = r->tbl;
- else
+ r->tbl = tbl_alloc(ppos, ln, r->parse, r->last_tbl);
+ if (r->last_tbl == NULL)
r->first_tbl = r->tbl;
r->last_tbl = r->tbl;
return ROFF_IGN;
diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h
index 3fa35361f79..361d6e1b917 100644
--- a/usr.bin/mandoc/roff.h
+++ b/usr.bin/mandoc/roff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.h,v 1.43 2018/08/18 02:03:41 schwarze Exp $ */
+/* $OpenBSD: roff.h,v 1.44 2018/12/13 02:05:57 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -502,7 +502,7 @@ struct roff_node {
struct mdoc_arg *args; /* BLOCK/ELEM */
union mdoc_data *norm; /* Normalized arguments. */
char *string; /* TEXT */
- const struct tbl_span *span; /* TBL */
+ struct tbl_span *span; /* TBL */
struct eqn_box *eqn; /* EQN */
int line; /* Input file line number. */
int pos; /* Input file column number. */
diff --git a/usr.bin/mandoc/tbl.c b/usr.bin/mandoc/tbl.c
index 9aebcc624cf..1606b026599 100644
--- a/usr.bin/mandoc/tbl.c
+++ b/usr.bin/mandoc/tbl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tbl.c,v 1.24 2018/12/12 21:54:30 schwarze Exp $ */
+/* $OpenBSD: tbl.c,v 1.25 2018/12/13 02:05:57 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -27,7 +27,8 @@
#include "mandoc.h"
#include "tbl.h"
#include "libmandoc.h"
-#include "libroff.h"
+#include "tbl_parse.h"
+#include "tbl_int.h"
void
@@ -85,11 +86,13 @@ tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
}
struct tbl_node *
-tbl_alloc(int pos, int line, struct mparse *parse)
+tbl_alloc(int pos, int line, struct mparse *parse, struct tbl_node *last_tbl)
{
struct tbl_node *tbl;
tbl = mandoc_calloc(1, sizeof(*tbl));
+ if (last_tbl != NULL)
+ last_tbl->next = tbl;
tbl->line = line;
tbl->pos = pos;
tbl->parse = parse;
@@ -102,34 +105,37 @@ tbl_alloc(int pos, int line, struct mparse *parse)
void
tbl_free(struct tbl_node *tbl)
{
+ struct tbl_node *old_tbl;
struct tbl_row *rp;
struct tbl_cell *cp;
struct tbl_span *sp;
struct tbl_dat *dp;
- while ((rp = tbl->first_row) != NULL) {
- tbl->first_row = rp->next;
- while (rp->first != NULL) {
- cp = rp->first;
- rp->first = cp->next;
- free(cp->wstr);
- free(cp);
+ while (tbl != NULL) {
+ while ((rp = tbl->first_row) != NULL) {
+ tbl->first_row = rp->next;
+ while (rp->first != NULL) {
+ cp = rp->first;
+ rp->first = cp->next;
+ free(cp->wstr);
+ free(cp);
+ }
+ free(rp);
}
- free(rp);
- }
-
- while ((sp = tbl->first_span) != NULL) {
- tbl->first_span = sp->next;
- while (sp->first != NULL) {
- dp = sp->first;
- sp->first = dp->next;
- free(dp->string);
- free(dp);
+ while ((sp = tbl->first_span) != NULL) {
+ tbl->first_span = sp->next;
+ while (sp->first != NULL) {
+ dp = sp->first;
+ sp->first = dp->next;
+ free(dp->string);
+ free(dp);
+ }
+ free(sp);
}
- free(sp);
+ old_tbl = tbl;
+ tbl = tbl->next;
+ free(old_tbl);
}
-
- free(tbl);
}
void
@@ -144,25 +150,27 @@ tbl_restart(int line, int pos, struct tbl_node *tbl)
tbl->pos = pos;
}
-const struct tbl_span *
+struct tbl_span *
tbl_span(struct tbl_node *tbl)
{
struct tbl_span *span;
- assert(tbl);
span = tbl->current_span ? tbl->current_span->next
: tbl->first_span;
- if (span)
+ if (span != NULL)
tbl->current_span = span;
return span;
}
int
-tbl_end(struct tbl_node *tbl)
+tbl_end(struct tbl_node *tbl, int still_open)
{
struct tbl_span *sp;
- if (tbl->part == TBL_PART_CDATA)
+ if (still_open)
+ mandoc_msg(MANDOCERR_BLK_NOEND, tbl->parse,
+ tbl->line, tbl->pos, "TS");
+ else if (tbl->part == TBL_PART_CDATA)
mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse,
tbl->line, tbl->pos, "TE");
diff --git a/usr.bin/mandoc/tbl_data.c b/usr.bin/mandoc/tbl_data.c
index 4f91de629bc..efd42b70e67 100644
--- a/usr.bin/mandoc/tbl_data.c
+++ b/usr.bin/mandoc/tbl_data.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tbl_data.c,v 1.35 2018/12/12 21:54:30 schwarze Exp $ */
+/* $OpenBSD: tbl_data.c,v 1.36 2018/12/13 02:05:57 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -27,7 +27,7 @@
#include "mandoc.h"
#include "tbl.h"
#include "libmandoc.h"
-#include "libroff.h"
+#include "tbl_int.h"
static void getdata(struct tbl_node *, struct tbl_span *,
int, const char *, int *);
diff --git a/usr.bin/mandoc/tbl_int.h b/usr.bin/mandoc/tbl_int.h
new file mode 100644
index 00000000000..f4e3b8a5d7b
--- /dev/null
+++ b/usr.bin/mandoc/tbl_int.h
@@ -0,0 +1,48 @@
+/* $OpenBSD: tbl_int.h,v 1.1 2018/12/13 02:05:57 schwarze Exp $ */
+/*
+ * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011,2013,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
+ * 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.
+ *
+ * Internal interfaces of the tbl(7) parser.
+ * For use inside the tbl(7) parser only.
+ */
+
+enum tbl_part {
+ TBL_PART_OPTS, /* In the first line, ends with semicolon. */
+ TBL_PART_LAYOUT, /* In the layout section, ends with full stop. */
+ TBL_PART_DATA, /* In the data section, ends with TE. */
+ TBL_PART_CDATA /* In a T{ block, ends with T} */
+};
+
+struct tbl_node {
+ struct tbl_opts opts; /* Options for the whole table. */
+ struct mparse *parse; /* For error reporting. */
+ struct tbl_node *next; /* Next table. */
+ struct tbl_row *first_row; /* First layout row. */
+ struct tbl_row *last_row; /* Last layout row. */
+ struct tbl_span *first_span; /* First data row. */
+ struct tbl_span *current_span; /* Data row being parsed. */
+ struct tbl_span *last_span; /* Last data row. */
+ int line; /* Line number in input file. */
+ int pos; /* Column number in input file. */
+ enum tbl_part part; /* Table section being parsed. */
+};
+
+
+void tbl_option(struct tbl_node *, int, const char *, int *);
+void tbl_layout(struct tbl_node *, int, const char *, int);
+void tbl_data(struct tbl_node *, int, const char *, int);
+void tbl_cdata(struct tbl_node *, int, const char *, int);
+void tbl_reset(struct tbl_node *);
diff --git a/usr.bin/mandoc/tbl_layout.c b/usr.bin/mandoc/tbl_layout.c
index 98ff9df9b2b..e09ae25de1e 100644
--- a/usr.bin/mandoc/tbl_layout.c
+++ b/usr.bin/mandoc/tbl_layout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tbl_layout.c,v 1.32 2018/12/12 21:54:30 schwarze Exp $ */
+/* $OpenBSD: tbl_layout.c,v 1.33 2018/12/13 02:05:57 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -27,7 +27,7 @@
#include "mandoc.h"
#include "tbl.h"
#include "libmandoc.h"
-#include "libroff.h"
+#include "tbl_int.h"
struct tbl_phrase {
char name;
diff --git a/usr.bin/mandoc/tbl_opts.c b/usr.bin/mandoc/tbl_opts.c
index 8538c51ad46..330f42a3746 100644
--- a/usr.bin/mandoc/tbl_opts.c
+++ b/usr.bin/mandoc/tbl_opts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tbl_opts.c,v 1.14 2018/12/12 21:54:30 schwarze Exp $ */
+/* $OpenBSD: tbl_opts.c,v 1.15 2018/12/13 02:05:57 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -25,7 +25,7 @@
#include "mandoc.h"
#include "tbl.h"
#include "libmandoc.h"
-#include "libroff.h"
+#include "tbl_int.h"
#define KEY_DPOINT 0
#define KEY_DELIM 1
diff --git a/usr.bin/mandoc/tbl_parse.h b/usr.bin/mandoc/tbl_parse.h
new file mode 100644
index 00000000000..d1bb5bb66b7
--- /dev/null
+++ b/usr.bin/mandoc/tbl_parse.h
@@ -0,0 +1,31 @@
+/* $OpenBSD: tbl_parse.h,v 1.1 2018/12/13 02:05:57 schwarze Exp $ */
+/*
+ * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011, 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 tbl(7) parser.
+ * For use in the roff(7) and tbl(7) parsers only.
+ */
+
+struct mparse;
+struct tbl_node;
+struct tbl_span;
+
+struct tbl_node *tbl_alloc(int, int, struct mparse *, struct tbl_node *);
+int tbl_end(struct tbl_node *, int);
+void tbl_free(struct tbl_node *);
+void tbl_read(struct tbl_node *, int, const char *, int);
+void tbl_restart(int, int, struct tbl_node *);
+struct tbl_span *tbl_span(struct tbl_node *);