aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-07-08 14:51:04 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-07-08 14:51:04 +0000
commitcf63fca8357771e9f99c05319bf7ae1d9325cbd8 (patch)
tree283184101587a0e648dd5fcc99c2e2c91519bf49 /roff.c
parent9ef0c733fd442e250894494f24d6a17d1db58500 (diff)
downloadmandoc-cf63fca8357771e9f99c05319bf7ae1d9325cbd8.tar.gz
mandoc-cf63fca8357771e9f99c05319bf7ae1d9325cbd8.tar.zst
mandoc-cf63fca8357771e9f99c05319bf7ae1d9325cbd8.zip
1. Eliminate struct eqn, instead use the existing members
of struct roff_node which is allocated for each equation anyway. 2. Do not keep a list of equation parsers, one parser is enough. Minus fifty lines of code, no functional change.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c86
1 files changed, 38 insertions, 48 deletions
diff --git a/roff.c b/roff.c
index d1d2490c..f377280b 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.318 2017/07/04 22:52:00 schwarze Exp $ */
+/* $Id: roff.c,v 1.319 2017/07/08 14:51:04 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -98,9 +98,8 @@ struct roff {
struct tbl_node *first_tbl; /* first table parsed */
struct tbl_node *last_tbl; /* last table parsed */
struct tbl_node *tbl; /* current table being parsed */
- struct eqn_node *last_eqn; /* last equation parsed */
- struct eqn_node *first_eqn; /* first equation parsed */
- struct eqn_node *eqn; /* current equation being parsed */
+ struct eqn_node *last_eqn; /* equation parser */
+ struct eqn_node *eqn; /* active equation parser */
int eqn_inline; /* current equation is inline */
int options; /* parse options */
int rstacksz; /* current size limit of rstack */
@@ -695,7 +694,6 @@ static void
roff_free1(struct roff *r)
{
struct tbl_node *tbl;
- struct eqn_node *e;
int i;
while (NULL != (tbl = r->first_tbl)) {
@@ -704,11 +702,9 @@ roff_free1(struct roff *r)
}
r->first_tbl = r->last_tbl = r->tbl = NULL;
- while (NULL != (e = r->first_eqn)) {
- r->first_eqn = e->next;
- eqn_free(e);
- }
- r->first_eqn = r->last_eqn = r->eqn = NULL;
+ if (r->last_eqn != NULL)
+ eqn_free(r->last_eqn);
+ r->last_eqn = r->eqn = NULL;
while (r->last)
roffnode_pop(r);
@@ -984,19 +980,6 @@ roff_body_alloc(struct roff_man *man, int line, int pos, int tok)
}
void
-roff_addeqn(struct roff_man *man, const struct eqn *eqn)
-{
- struct roff_node *n;
-
- n = roff_node_alloc(man, eqn->ln, eqn->pos, ROFFT_EQN, TOKEN_NONE);
- n->eqn = eqn;
- if (eqn->ln > man->last->line)
- n->flags |= NODE_LINE;
- roff_node_append(man, n);
- man->next = ROFF_NEXT_SIBLING;
-}
-
-void
roff_addtbl(struct roff_man *man, const struct tbl_span *tbl)
{
struct roff_node *n;
@@ -1055,6 +1038,8 @@ 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);
free(n->string);
free(n);
}
@@ -1512,8 +1497,10 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
return e;
assert(e == ROFF_CONT);
}
- if (r->eqn != NULL)
- return eqn_read(&r->eqn, ln, buf->buf, ppos, offs);
+ if (r->eqn != NULL && strncmp(buf->buf + ppos, ".EN", 3)) {
+ eqn_read(r->eqn, buf->buf + ppos);
+ return ROFF_IGN;
+ }
if (r->tbl != NULL && ( ! ctl || buf->buf[pos] == '\0'))
return tbl_read(r->tbl, ln, buf->buf, ppos);
if ( ! ctl)
@@ -1593,8 +1580,9 @@ roff_endparse(struct roff *r)
if (r->eqn) {
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
- r->eqn->eqn.ln, r->eqn->eqn.pos, "EQ");
- eqn_end(&r->eqn);
+ r->eqn->node->line, r->eqn->node->pos, "EQ");
+ eqn_parse(r->eqn);
+ r->eqn = NULL;
}
if (r->tbl) {
@@ -2877,20 +2865,23 @@ roff_eqndelim(struct roff *r, struct buf *buf, int pos)
static enum rofferr
roff_EQ(ROFF_ARGS)
{
- struct eqn_node *e;
-
- assert(r->eqn == NULL);
- e = eqn_alloc(ppos, ln, r->parse);
+ struct roff_node *n;
- if (r->last_eqn) {
- r->last_eqn->next = e;
- e->delim = r->last_eqn->delim;
- e->odelim = r->last_eqn->odelim;
- e->cdelim = r->last_eqn->cdelim;
- } else
- r->first_eqn = r->last_eqn = e;
+ 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;
+ roff_node_append(r->man, n);
+ r->man->next = ROFF_NEXT_SIBLING;
- r->eqn = r->last_eqn = e;
+ assert(r->eqn == NULL);
+ if (r->last_eqn == NULL)
+ r->last_eqn = eqn_alloc(r->parse);
+ else
+ eqn_reset(r->last_eqn);
+ r->eqn = r->last_eqn;
+ r->eqn->node = n;
if (buf->buf[pos] != '\0')
mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
@@ -2902,8 +2893,14 @@ roff_EQ(ROFF_ARGS)
static enum rofferr
roff_EN(ROFF_ARGS)
{
-
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "EN");
+ if (r->eqn != NULL) {
+ eqn_parse(r->eqn);
+ r->eqn = NULL;
+ } else
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "EN");
+ if (buf->buf[pos] != '\0')
+ mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
+ "EN %s", buf->buf + pos);
return ROFF_IGN;
}
@@ -3610,13 +3607,6 @@ roff_span(const struct roff *r)
return r->tbl ? tbl_span(r->tbl) : NULL;
}
-const struct eqn *
-roff_eqn(const struct roff *r)
-{
-
- return r->last_eqn ? &r->last_eqn->eqn : NULL;
-}
-
/*
* Duplicate an input string, making the appropriate character
* conversations (as stipulated by `tr') along the way.