summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-07-08 17:52:49 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-07-08 17:52:49 +0000
commit093b704b943e58cc16bd6065cc571372f7059b56 (patch)
treeb258d28e058a17b345ca4067b1922e772bf9b217
parenta7d3439bd1214fd20650366b5177cb87d787982d (diff)
downloadmandoc-093b704b943e58cc16bd6065cc571372f7059b56.tar.gz
Simplify by creating struct roff_node syntax tree nodes for tbl(7)
right from roff_parseln() rather than delegating to read.c, similar to what i just did for eqn(7). The interface function roff_span() becomes obsolete and is deleted, the former interface function roff_addtbl() becomes static, the interface functions tbl_read() and tbl_cdata() become void, and minus twelve linus of code. No functional change.
-rw-r--r--libmandoc.h6
-rw-r--r--libroff.h8
-rw-r--r--mandoc_headers.322
-rw-r--r--read.c15
-rw-r--r--roff.c72
-rw-r--r--roff_int.h1
-rw-r--r--tbl.c19
-rw-r--r--tbl_data.c8
8 files changed, 58 insertions, 93 deletions
diff --git a/libmandoc.h b/libmandoc.h
index 97a8cbad..0c884814 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013, 2014, 2015, 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
@@ -23,7 +23,6 @@ enum rofferr {
ROFF_REPARSE, /* re-run main parser on the result */
ROFF_SO, /* include another file */
ROFF_IGN, /* ignore current line */
- ROFF_TBL, /* a table row was successfully parsed */
};
struct buf {
@@ -33,7 +32,6 @@ struct buf {
struct mparse;
-struct tbl_span;
struct roff;
struct roff_man;
@@ -73,5 +71,3 @@ char *roff_strdup(const struct roff *, const char *);
int roff_getcontrol(const struct roff *,
const char *, int *);
int roff_getformat(const struct roff *);
-
-const struct tbl_span *roff_span(const struct roff *);
diff --git a/libroff.h b/libroff.h
index 4ad91a00..84741373 100644
--- a/libroff.h
+++ b/libroff.h
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 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
@@ -65,13 +65,13 @@ 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 *);
-enum rofferr tbl_read(struct tbl_node *, int, const char *, int);
+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);
-int tbl_cdata(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 **);
+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/mandoc_headers.3 b/mandoc_headers.3
index 669eee99..f1c07681 100644
--- a/mandoc_headers.3
+++ b/mandoc_headers.3
@@ -264,15 +264,11 @@ and
from
.Pa roff.c
for function prototypes.
-Uses the types
-.Vt struct tbl_span
-from
-.Pa mandoc.h
-and
+Uses the type
.Vt struct roff_man
from
.Pa roff.h
-as opaque types for function prototypes.
+as an opaque type for function prototypes.
.It Qq Pa roff_int.h
Requires
.Qq Pa roff.h
@@ -289,14 +285,11 @@ because the latter two are needed by
.Qq Pa roff.c .
.Pp
Uses the types
-.Vt struct tbl_span
-from
-.Pa mandoc.h ,
.Vt struct roff_man
and
.Vt struct roff_node
from
-.Pa roff.h ,
+.Pa roff.h
and
.Vt struct mdoc_arg
from
@@ -368,16 +361,13 @@ or
Requires
.In sys/types.h
for
-.Vt size_t ,
+.Vt size_t
+and
.Qq Pa mandoc.h
for
.Vt struct tbl_*
and
-.Vt struct eqn_box ,
-and
-.Qq Pa libmandoc.h
-for
-.Vt enum rofferr .
+.Vt struct eqn_box .
.Pp
Provides
.Vt enum tbl_part ,
diff --git a/read.c b/read.c
index bec76815..5e462732 100644
--- a/read.c
+++ b/read.c
@@ -42,7 +42,6 @@
#include "mdoc.h"
#include "man.h"
#include "libmandoc.h"
-#include "roff_int.h"
#define REPARSE_LIMIT 1000
@@ -343,7 +342,6 @@ choose_parser(struct mparse *curp)
static int
mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start)
{
- const struct tbl_span *span;
struct buf ln;
const char *save_file;
char *cp;
@@ -534,18 +532,7 @@ rerun:
if (curp->man->macroset == MACROSET_NONE)
choose_parser(curp);
- /*
- * Lastly, push down into the parsers themselves.
- * If libroff returns ROFF_TBL, then add it to the
- * currently open parse. Since we only get here if
- * there does exist data (see tbl_data.c), we're
- * guaranteed that something's been allocated.
- */
-
- if (rr == ROFF_TBL)
- while ((span = roff_span(curp->roff)) != NULL)
- roff_addtbl(curp->man, span);
- else if ((curp->man->macroset == MACROSET_MDOC ?
+ if ((curp->man->macroset == MACROSET_MDOC ?
mdoc_parseln(curp->man, curp->line, ln.buf, of) :
man_parseln(curp->man, curp->line, ln.buf, of)) == 2)
break;
diff --git a/roff.c b/roff.c
index 7a4992bd..1d181d32 100644
--- a/roff.c
+++ b/roff.c
@@ -153,6 +153,7 @@ static void roffnode_cleanscope(struct roff *);
static void 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 enum rofferr roff_als(ROFF_ARGS);
static enum rofferr roff_block(ROFF_ARGS);
static enum rofferr roff_block_text(ROFF_ARGS);
@@ -979,18 +980,21 @@ roff_body_alloc(struct roff_man *man, int line, int pos, int tok)
return n;
}
-void
-roff_addtbl(struct roff_man *man, const struct tbl_span *tbl)
+static void
+roff_addtbl(struct roff_man *man, struct tbl_node *tbl)
{
struct roff_node *n;
+ const struct tbl_span *span;
if (man->macroset == MACROSET_MAN)
man_breakscope(man, ROFF_TS);
- n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE);
- n->span = tbl;
- roff_node_append(man, n);
- n->flags |= NODE_VALID | NODE_ENDED;
- man->next = ROFF_NEXT_SIBLING;
+ while ((span = tbl_span(tbl)) != NULL) {
+ n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE);
+ n->span = span;
+ roff_node_append(man, n);
+ n->flags |= NODE_VALID | NODE_ENDED;
+ man->next = ROFF_NEXT_SIBLING;
+ }
}
void
@@ -1501,8 +1505,11 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
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 (r->tbl != NULL && (ctl == 0 || buf->buf[pos] == '\0')) {
+ tbl_read(r->tbl, ln, buf->buf, ppos);
+ roff_addtbl(r->man, r->tbl);
+ return ROFF_IGN;
+ }
if ( ! ctl)
return roff_parsetext(r, buf, pos, offs);
@@ -1543,7 +1550,9 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
pos++;
while (buf->buf[pos] == ' ')
pos++;
- return tbl_read(r->tbl, ln, buf->buf, pos);
+ tbl_read(r->tbl, ln, buf->buf, pos);
+ roff_addtbl(r->man, r->tbl);
+ return ROFF_IGN;
}
/* For now, let high level macros abort .ce mode. */
@@ -1572,23 +1581,23 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
void
roff_endparse(struct roff *r)
{
-
- if (r->last)
+ if (r->last != NULL)
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
r->last->line, r->last->col,
roff_name[r->last->tok]);
- if (r->eqn) {
+ if (r->eqn != NULL) {
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
r->eqn->node->line, r->eqn->node->pos, "EQ");
eqn_parse(r->eqn);
r->eqn = NULL;
}
- if (r->tbl) {
+ 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);
+ r->tbl = NULL;
}
}
@@ -2770,16 +2779,19 @@ roff_Dd(ROFF_ARGS)
static enum rofferr
roff_TE(ROFF_ARGS)
{
-
- if (NULL == r->tbl)
+ if (r->tbl == NULL) {
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
ln, ppos, "TE");
- else if ( ! tbl_end(&r->tbl)) {
+ return ROFF_IGN;
+ }
+ if (tbl_end(r->tbl) == 0) {
+ r->tbl = NULL;
free(buf->buf);
buf->buf = mandoc_strdup(".sp");
buf->sz = 4;
return ROFF_REPARSE;
}
+ r->tbl = NULL;
return ROFF_IGN;
}
@@ -2907,22 +2919,17 @@ roff_EN(ROFF_ARGS)
static enum rofferr
roff_TS(ROFF_ARGS)
{
- struct tbl_node *tbl;
-
- if (r->tbl) {
+ if (r->tbl != NULL) {
mandoc_msg(MANDOCERR_BLK_BROKEN, r->parse,
ln, ppos, "TS breaks TS");
- tbl_end(&r->tbl);
+ tbl_end(r->tbl);
}
-
- tbl = tbl_alloc(ppos, ln, r->parse);
-
+ r->tbl = tbl_alloc(ppos, ln, r->parse);
if (r->last_tbl)
- r->last_tbl->next = tbl;
+ r->last_tbl->next = r->tbl;
else
- r->first_tbl = r->last_tbl = tbl;
-
- r->tbl = r->last_tbl = tbl;
+ r->first_tbl = r->tbl;
+ r->last_tbl = r->tbl;
return ROFF_IGN;
}
@@ -3601,13 +3608,6 @@ roff_freestr(struct roffkv *r)
/* --- accessors and utility functions ------------------------------------ */
-const struct tbl_span *
-roff_span(const struct roff *r)
-{
-
- return r->tbl ? tbl_span(r->tbl) : NULL;
-}
-
/*
* Duplicate an input string, making the appropriate character
* conversations (as stipulated by `tr') along the way.
diff --git a/roff_int.h b/roff_int.h
index 81a4bec4..6d45a209 100644
--- a/roff_int.h
+++ b/roff_int.h
@@ -25,7 +25,6 @@ void roff_elem_alloc(struct roff_man *, int, int, int);
struct roff_node *roff_block_alloc(struct roff_man *, int, int, int);
struct roff_node *roff_head_alloc(struct roff_man *, int, int, int);
struct roff_node *roff_body_alloc(struct roff_man *, int, int, int);
-void roff_addtbl(struct roff_man *, const struct tbl_span *);
void roff_node_unlink(struct roff_man *, struct roff_node *);
void roff_node_free(struct roff_node *);
void roff_node_delete(struct roff_man *, struct roff_node *);
diff --git a/tbl.c b/tbl.c
index 83f77348..107c4c49 100644
--- a/tbl.c
+++ b/tbl.c
@@ -31,7 +31,7 @@
#include "libroff.h"
-enum rofferr
+void
tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
{
const char *cp;
@@ -66,7 +66,7 @@ tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
if (*cp == ';') {
tbl_option(tbl, ln, p, &pos);
if (p[pos] == '\0')
- return ROFF_IGN;
+ return;
}
}
@@ -75,15 +75,14 @@ tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
switch (tbl->part) {
case TBL_PART_LAYOUT:
tbl_layout(tbl, ln, p, pos);
- return ROFF_IGN;
+ break;
case TBL_PART_CDATA:
- return tbl_cdata(tbl, ln, p, pos) ? ROFF_TBL : ROFF_IGN;
+ tbl_cdata(tbl, ln, p, pos);
+ break;
default:
+ tbl_data(tbl, ln, p, pos);
break;
}
-
- tbl_data(tbl, ln, p, pos);
- return ROFF_TBL;
}
struct tbl_node *
@@ -160,14 +159,10 @@ tbl_span(struct tbl_node *tbl)
}
int
-tbl_end(struct tbl_node **tblp)
+tbl_end(struct tbl_node *tbl)
{
- struct tbl_node *tbl;
struct tbl_span *sp;
- tbl = *tblp;
- *tblp = NULL;
-
if (tbl->part == TBL_PART_CDATA)
mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse,
tbl->line, tbl->pos, "TE");
diff --git a/tbl_data.c b/tbl_data.c
index 32a169d7..01bc62d2 100644
--- a/tbl_data.c
+++ b/tbl_data.c
@@ -128,7 +128,7 @@ getdata(struct tbl_node *tbl, struct tbl_span *dp,
tbl->parse, ln, sv, dat->string);
}
-int
+void
tbl_cdata(struct tbl_node *tbl, int ln, const char *p, int pos)
{
struct tbl_dat *dat;
@@ -143,10 +143,10 @@ tbl_cdata(struct tbl_node *tbl, int ln, const char *p, int pos)
pos++;
while (p[pos] != '\0')
getdata(tbl, tbl->last_span, ln, p, &pos);
- return 1;
+ return;
} else if (p[pos] == '\0') {
tbl->part = TBL_PART_DATA;
- return 1;
+ return;
}
/* Fallthrough: T} is part of a word. */
@@ -166,8 +166,6 @@ tbl_cdata(struct tbl_node *tbl, int ln, const char *p, int pos)
if (dat->layout->pos == TBL_CELL_DOWN)
mandoc_msg(MANDOCERR_TBLDATA_SPAN, tbl->parse,
ln, pos, dat->string);
-
- return 0;
}
static struct tbl_span *