summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mdoc.38
-rw-r--r--mdoc.c36
-rw-r--r--mdoc.h4
-rw-r--r--mdoc_html.c2
-rw-r--r--mdoc_term.c29
-rw-r--r--mdoc_validate.c19
6 files changed, 88 insertions, 10 deletions
diff --git a/mdoc.3 b/mdoc.3
index 83ad2f2f..358008d8 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -33,6 +33,11 @@
.In mdoc.h
.Vt extern const char * const * mdoc_macronames;
.Vt extern const char * const * mdoc_argnames;
+.Ft int
+.Fo mdoc_addspan
+.Fa "struct mdoc *mdoc"
+.Fa "const struct tbl_span *span"
+.Fc
.Ft "struct mdoc *"
.Fo mdoc_alloc
.Fa "struct regset *regs"
@@ -92,6 +97,9 @@ for details.
.El
.Ss Functions
.Bl -ohang
+.It Fn mdoc_addspan
+Add a table span to the parsing stream.
+Returns 0 on failure, 1 on success.
.It Fn mdoc_alloc
Allocates a parsing structure.
The
diff --git a/mdoc.c b/mdoc.c
index 92615c5d..324ec9f7 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -98,6 +98,8 @@ static int node_append(struct mdoc *,
struct mdoc_node *);
static int mdoc_ptext(struct mdoc *, int, char *, int);
static int mdoc_pmacro(struct mdoc *, int, char *, int);
+static int mdoc_span_alloc(struct mdoc *,
+ const struct tbl_span *);
const struct mdoc_node *
@@ -221,6 +223,24 @@ mdoc_endparse(struct mdoc *m)
return(0);
}
+int
+mdoc_addspan(struct mdoc *m, const struct tbl_span *sp)
+{
+
+ if (MDOC_HALT & m->flags)
+ return(0);
+
+ /* No text before an initial macro. */
+
+ if (SEC_NONE == m->lastnamed) {
+ /* FIXME: grab from span. */
+ mdoc_pmsg(m, 0, 0, MANDOCERR_NOTEXT);
+ return(1);
+ }
+
+ return(mdoc_span_alloc(m, sp));
+}
+
/*
* Main parse routine. Parses a single line -- really just hands off to
@@ -525,6 +545,22 @@ mdoc_elem_alloc(struct mdoc *m, int line, int pos,
return(1);
}
+static int
+mdoc_span_alloc(struct mdoc *m, const struct tbl_span *sp)
+{
+ struct mdoc_node *n;
+
+ /* FIXME: grab from tbl_span. */
+ n = node_alloc(m, 0, 0, MDOC_MAX, MDOC_TBL);
+ n->span = sp;
+
+ if ( ! node_append(m, n))
+ return(0);
+
+ m->next = MDOC_NEXT_SIBLING;
+ return(1);
+}
+
int
mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p)
diff --git a/mdoc.h b/mdoc.h
index 07927dd5..c54fe605 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -190,6 +190,7 @@ enum mdoc_type {
MDOC_TAIL,
MDOC_BODY,
MDOC_BLOCK,
+ MDOC_TBL,
MDOC_ROOT
};
@@ -399,6 +400,7 @@ struct mdoc_node {
struct mdoc_node *body; /* BLOCK */
struct mdoc_node *tail; /* BLOCK */
char *string; /* TEXT */
+ const struct tbl_span *span; /* TBL */
enum mdoc_endbody end; /* BODY */
};
@@ -426,6 +428,8 @@ int mdoc_parseln(struct mdoc *, int, char *, int);
const struct mdoc_node *mdoc_node(const struct mdoc *);
const struct mdoc_meta *mdoc_meta(const struct mdoc *);
int mdoc_endparse(struct mdoc *);
+int mdoc_addspan(struct mdoc *,
+ const struct tbl_span *);
__END_DECLS
diff --git a/mdoc_html.c b/mdoc_html.c
index f4b7f485..bb2d0b3f 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -422,6 +422,8 @@ print_mdoc_node(MDOC_ARGS)
case (MDOC_TEXT):
print_text(h, n->string);
return;
+ case (MDOC_TBL):
+ return;
default:
if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
child = (*mdocs[n->tok].pre)(m, n, h);
diff --git a/mdoc_term.c b/mdoc_term.c
index c76ba3d9..b7417569 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -312,11 +312,19 @@ print_mdoc_node(DECL_ARGS)
memset(&npair, 0, sizeof(struct termpair));
npair.ppair = pair;
-
- if (MDOC_TEXT == n->type)
- term_word(p, n->string);
- else if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
- chld = (*termacts[n->tok].pre)(p, &npair, m, n);
+
+ switch (n->type) {
+ case (MDOC_TEXT):
+ term_word(p, n->string);
+ break;
+ case (MDOC_TBL):
+ break;
+ default:
+ if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
+ chld = (*termacts[n->tok].pre)
+ (p, &npair, m, n);
+ break;
+ }
/*
* Keeps only work until the end of a line. If a keep was
@@ -353,8 +361,14 @@ print_mdoc_node(DECL_ARGS)
term_fontpopq(p, font);
- if (MDOC_TEXT != n->type && termacts[n->tok].post &&
- ! (MDOC_ENDED & n->flags)) {
+ switch (n->type) {
+ case (MDOC_TEXT):
+ break;
+ case (MDOC_TBL):
+ break;
+ default:
+ if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
+ break;
(void)(*termacts[n->tok].post)(p, &npair, m, n);
/*
@@ -372,6 +386,7 @@ print_mdoc_node(DECL_ARGS)
*/
if (ENDBODY_NOSPACE == n->end)
p->flags |= TERMP_NOSPACE;
+ break;
}
if (MDOC_EOS & n->flags)
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 19215261..9622409a 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -329,12 +329,19 @@ mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n)
int line, pos;
char *tp;
- if (MDOC_TEXT == n->type) {
+ switch (n->type) {
+ case (MDOC_TEXT):
tp = n->string;
line = n->line;
pos = n->pos;
check_text(mdoc, line, pos, tp);
+ /* FALLTHROUGH */
+ case (MDOC_TBL):
+ /* FALLTHROUGH */
+ case (MDOC_ROOT):
return(1);
+ default:
+ break;
}
check_args(mdoc, n);
@@ -357,10 +364,16 @@ mdoc_valid_post(struct mdoc *mdoc)
return(1);
mdoc->last->flags |= MDOC_VALID;
- if (MDOC_TEXT == mdoc->last->type)
+ switch (mdoc->last->type) {
+ case (MDOC_TEXT):
+ /* FALLTHROUGH */
+ case (MDOC_TBL):
return(1);
- if (MDOC_ROOT == mdoc->last->type)
+ case (MDOC_ROOT):
return(post_root(mdoc));
+ default:
+ break;
+ }
if (NULL == mdoc_valids[mdoc->last->tok].post)
return(1);