summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-01-01 15:45:18 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-01-01 15:45:18 +0000
commit11a4a49536978db711f68cc010fec41f76c2f970 (patch)
tree898f1e145588b487ca875c4fd3df9e132eddb1ff
parent31916df7856f6ea8b704f200c8a68d72e536fd32 (diff)
downloadmandoc-11a4a49536978db711f68cc010fec41f76c2f970.tar.gz
Add documentation bits for libroff's new roff_span().
Add bits to remember tbl's invocation point. Add ERROR class message if no data's in the table.
-rw-r--r--libroff.h5
-rw-r--r--main.c1
-rw-r--r--mandoc.h1
-rw-r--r--roff.312
-rw-r--r--roff.c8
-rw-r--r--tbl.c12
6 files changed, 34 insertions, 5 deletions
diff --git a/libroff.h b/libroff.h
index 890a7414..4c9617a9 100644
--- a/libroff.h
+++ b/libroff.h
@@ -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 d20c36fb..f437a526 100644
--- a/main.c
+++ b/main.c
@@ -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 96265da5..1fad6f3d 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -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 50ada862..bf67671a 100644
--- a/roff.3
+++ b/roff.3
@@ -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 eecba18c..56202846 100644
--- a/roff.c
+++ b/roff.c
@@ -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 a4d3fa92..7f37405c 100644
--- a/tbl.c
+++ b/tbl.c
@@ -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);
+}