aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--libroff.h7
-rw-r--r--main.c3
-rw-r--r--mandoc.h3
-rw-r--r--roff.316
-rw-r--r--roff.c10
-rw-r--r--tbl.c14
6 files changed, 41 insertions, 12 deletions
diff --git a/libroff.h b/libroff.h
index c5aff63e..d6f8f92d 100644
--- a/libroff.h
+++ b/libroff.h
@@ -1,4 +1,4 @@
-/* $Id: libroff.h,v 1.11 2010/12/31 18:19:43 kristaps Exp $ */
+/* $Id: libroff.h,v 1.12 2011/01/01 15:45:18 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -31,6 +31,8 @@ struct tbl {
enum tbl_part part;
char tab; /* cell-separator */
char decimal; /* decimal point */
+ int pos; /* invocation column */
+ int line; /* invocation line */
int linesize;
char delims[2];
int opts;
@@ -51,7 +53,7 @@ struct tbl {
#define TBL_MSG(tblp, type, line, col) \
(*(tblp)->msg)((type), (tblp)->data, (line), (col), NULL)
-struct tbl *tbl_alloc(void *, mandocmsg);
+struct tbl *tbl_alloc(int, int, void *, mandocmsg);
void tbl_restart(struct tbl *);
void tbl_free(struct tbl *);
void tbl_reset(struct tbl *);
@@ -60,6 +62,7 @@ int tbl_option(struct tbl *, int, const char *);
int tbl_layout(struct tbl *, int, const char *);
int tbl_data(struct tbl *, int, const char *);
const struct tbl_span *tbl_span(const struct tbl *);
+void tbl_end(struct tbl *);
__END_DECLS
diff --git a/main.c b/main.c
index 595a0a2b..6b101492 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.128 2011/01/01 13:37:40 kristaps Exp $ */
+/* $Id: main.c,v 1.129 2011/01/01 15:45:18 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -183,6 +183,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"bad table option",
"bad table layout",
"no table layout cells specified",
+ "no table data cells specified",
"input stack limit exceeded, infinite loop?",
"skipping bad character",
"skipping text before the first section header",
diff --git a/mandoc.h b/mandoc.h
index 81f9de5f..1d8913ab 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.38 2010/12/31 18:19:43 kristaps Exp $ */
+/* $Id: mandoc.h,v 1.39 2011/01/01 15:45:18 kristaps Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -105,6 +105,7 @@ enum mandocerr {
MANDOCERR_TBLOPT, /* bad table option */
MANDOCERR_TBLLAYOUT, /* bad table layout */
MANDOCERR_TBLNOLAYOUT, /* no table layout cells specified */
+ MANDOCERR_TBLNODATA, /* no table data cells specified */
MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
MANDOCERR_BADCHAR, /* skipping bad character */
MANDOCERR_NOTEXT, /* skipping text before the first section header */
diff --git a/roff.3 b/roff.3
index bd0d98f8..a52fbf61 100644
--- a/roff.3
+++ b/roff.3
@@ -1,4 +1,4 @@
-.\" $Id: roff.3,v 1.8 2010/08/20 01:02:07 schwarze Exp $
+.\" $Id: roff.3,v 1.9 2011/01/01 15:45:18 kristaps Exp $
.\"
.\" Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 20 2010 $
+.Dd $Mdocdate: January 1 2011 $
.Dt ROFF 3
.Os
.Sh NAME
@@ -23,7 +23,8 @@
.Nm roff_endparse ,
.Nm roff_free ,
.Nm roff_parseln ,
-.Nm roff_reset
+.Nm roff_reset ,
+.Nm roff_span
.Nd roff macro compiler library
.Sh SYNOPSIS
.In mandoc.h
@@ -49,6 +50,8 @@
.Fc
.Ft void
.Fn roff_reset "struct roff *roff"
+.Ft "const struct tbl_span *"
+.Fn roff_span "const struct roff *roff"
.Sh DESCRIPTION
The
.Nm
@@ -139,6 +142,13 @@ Returns 0 on failure, 1 on success.
.It Fn roff_endparse
Signals that the parse is complete.
Returns 0 on failure, 1 on success.
+.It Fn roff_span
+If
+.Fn roff_parseln
+returned
+.Va ROFF_TBL ,
+return the last parsed table row.
+Returns NULL otherwise.
.El
.Sh EXAMPLES
See
diff --git a/roff.c b/roff.c
index 5531dc86..a1c21ed2 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.114 2010/12/31 18:19:43 kristaps Exp $ */
+/* $Id: roff.c,v 1.115 2011/01/01 15:45:18 kristaps Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -1123,6 +1123,8 @@ roff_TE(ROFF_ARGS)
if (NULL == r->tbl)
(*r->msg)(MANDOCERR_NOSCOPE, r->data, ln, ppos, NULL);
+ else
+ tbl_end(r->tbl);
r->tbl = NULL;
return(ROFF_IGN);
@@ -1147,10 +1149,12 @@ roff_TS(ROFF_ARGS)
{
struct tbl *t;
- if (r->tbl)
+ if (r->tbl) {
(*r->msg)(MANDOCERR_SCOPEBROKEN, r->data, ln, ppos, NULL);
+ tbl_end(r->tbl);
+ }
- t = tbl_alloc(r->data, r->msg);
+ t = tbl_alloc(ppos, ln, r->data, r->msg);
if (r->last_tbl)
r->last_tbl->next = t;
diff --git a/tbl.c b/tbl.c
index 65e1d87e..7407d11d 100644
--- a/tbl.c
+++ b/tbl.c
@@ -1,4 +1,4 @@
-/* $Id: tbl.c,v 1.12 2011/01/01 13:37:40 kristaps Exp $ */
+/* $Id: tbl.c,v 1.13 2011/01/01 15:45:18 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -64,11 +64,13 @@ tbl_read(struct tbl *tbl, int ln, const char *p, int offs)
}
struct tbl *
-tbl_alloc(void *data, const mandocmsg msg)
+tbl_alloc(int pos, int line, void *data, const mandocmsg msg)
{
struct tbl *p;
p = mandoc_calloc(1, sizeof(struct tbl));
+ p->line = line;
+ p->pos = pos;
p->data = data;
p->msg = msg;
p->part = TBL_PART_OPTS;
@@ -127,3 +129,11 @@ tbl_span(const struct tbl *tbl)
assert(tbl);
return(tbl->last_span);
}
+
+void
+tbl_end(struct tbl *tbl)
+{
+
+ if (NULL == tbl->first_span || NULL == tbl->first_span->first)
+ TBL_MSG(tbl, MANDOCERR_TBLNODATA, tbl->line, tbl->pos);
+}