summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-01-01 12:59:17 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-01-01 12:59:17 +0000
commit131de1ee113c08ea304f934c38488baa917375f6 (patch)
tree5f9c4e393a821b0b372d6dcc62bd76de3c8850da
parent98371213a082f1d2d7f5faac716b9818680d3140 (diff)
downloadmandoc-131de1ee113c08ea304f934c38488baa917375f6.tar.gz
Add -man support for tables. Like -mdoc, this consists of an
external-facing function man_addspan() (this required shuffling around the descope routine) and hooks elsewhere. Also fixed mdoc.c's post-validation of tables.
-rw-r--r--man.38
-rw-r--r--man.c78
-rw-r--r--man.h6
-rw-r--r--man_html.c17
-rw-r--r--man_term.c10
-rw-r--r--man_validate.c14
-rw-r--r--mdoc.c2
7 files changed, 96 insertions, 39 deletions
diff --git a/man.3 b/man.3
index f640f445..4d327b62 100644
--- a/man.3
+++ b/man.3
@@ -31,6 +31,11 @@
.In mandoc.h
.In man.h
.Vt extern const char * const * man_macronames;
+.Ft int
+.Fo man_addspan
+.Fa "struct man *man"
+.Fa "const struct tbl_span *span"
+.Fc
.Ft "struct man *"
.Fo man_alloc
.Fa "struct regset *regs"
@@ -101,6 +106,9 @@ for details.
.El
.Ss Functions
.Bl -ohang
+.It Fn man_addspan
+Add a table span to the parsing stream.
+Returns 0 on failure, 1 on success.
.It Fn man_alloc
Allocates a parsing structure.
The
diff --git a/man.c b/man.c
index a8c097ec..61657041 100644
--- a/man.c
+++ b/man.c
@@ -48,6 +48,8 @@ static struct man_node *man_node_alloc(int, int,
enum man_type, enum mant);
static int man_node_append(struct man *,
struct man_node *);
+static int man_span_alloc(struct man *,
+ const struct tbl_span *);
static void man_node_free(struct man_node *);
static void man_node_unlink(struct man *,
struct man_node *);
@@ -55,6 +57,7 @@ static int man_ptext(struct man *, int, char *, int);
static int man_pmacro(struct man *, int, char *, int);
static void man_free1(struct man *);
static void man_alloc1(struct man *);
+static int man_descope(struct man *, int, int);
const struct man_node *
@@ -212,6 +215,8 @@ man_node_append(struct man *man, struct man_node *p)
man->last = p;
switch (p->type) {
+ case (MAN_TBL):
+ /* FALLTHROUGH */
case (MAN_TEXT):
if ( ! man_valid_post(man))
return(0);
@@ -289,6 +294,20 @@ man_block_alloc(struct man *m, int line, int pos, enum mant tok)
return(1);
}
+static int
+man_span_alloc(struct man *m, const struct tbl_span *span)
+{
+ struct man_node *n;
+
+ /* FIXME: grab from span */
+ n = man_node_alloc(0, 0, MAN_TBL, MAN_MAX);
+
+ if ( ! man_node_append(m, n))
+ return(0);
+
+ m->next = MAN_NEXT_SIBLING;
+ return(1);
+}
int
man_word_alloc(struct man *m, int line, int pos, const char *word)
@@ -339,6 +358,40 @@ man_node_delete(struct man *m, struct man_node *p)
}
+int
+man_addspan(struct man *m, const struct tbl_span *sp)
+{
+
+ if ( ! man_span_alloc(m, sp))
+ return(0);
+ return(man_descope(m, 0, 0));
+}
+
+static int
+man_descope(struct man *m, int line, int offs)
+{
+ /*
+ * Co-ordinate what happens with having a next-line scope open:
+ * first close out the element scope (if applicable), then close
+ * out the block scope (also if applicable).
+ */
+
+ if (MAN_ELINE & m->flags) {
+ m->flags &= ~MAN_ELINE;
+ if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
+ return(0);
+ }
+
+ if ( ! (MAN_BLINE & m->flags))
+ return(1);
+ m->flags &= ~MAN_BLINE;
+
+ if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
+ return(0);
+ return(man_body_alloc(m, line, offs, m->last->tok));
+}
+
+
static int
man_ptext(struct man *m, int line, char *buf, int offs)
{
@@ -358,7 +411,7 @@ man_ptext(struct man *m, int line, char *buf, int offs)
if (MAN_LITERAL & m->flags) {
if ( ! man_word_alloc(m, line, offs, buf + offs))
return(0);
- goto descope;
+ return(man_descope(m, line, offs));
}
/* Pump blank lines directly into the backend. */
@@ -370,7 +423,7 @@ man_ptext(struct man *m, int line, char *buf, int offs)
/* Allocate a blank entry. */
if ( ! man_word_alloc(m, line, offs, ""))
return(0);
- goto descope;
+ return(man_descope(m, line, offs));
}
/*
@@ -407,26 +460,7 @@ man_ptext(struct man *m, int line, char *buf, int offs)
if (mandoc_eos(buf, (size_t)i, 0))
m->last->flags |= MAN_EOS;
-descope:
- /*
- * Co-ordinate what happens with having a next-line scope open:
- * first close out the element scope (if applicable), then close
- * out the block scope (also if applicable).
- */
-
- if (MAN_ELINE & m->flags) {
- m->flags &= ~MAN_ELINE;
- if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
- return(0);
- }
-
- if ( ! (MAN_BLINE & m->flags))
- return(1);
- m->flags &= ~MAN_BLINE;
-
- if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
- return(0);
- return(man_body_alloc(m, line, offs, m->last->tok));
+ return(man_descope(m, line, offs));
}
diff --git a/man.h b/man.h
index 042163fa..ffd4cf33 100644
--- a/man.h
+++ b/man.h
@@ -66,7 +66,8 @@ enum man_type {
MAN_ROOT,
MAN_BLOCK,
MAN_HEAD,
- MAN_BODY
+ MAN_BODY,
+ MAN_TBL
};
/*
@@ -100,6 +101,7 @@ struct man_node {
char *string; /* TEXT node argument */
struct man_node *head; /* BLOCK node HEAD ptr */
struct man_node *body; /* BLOCK node BODY ptr */
+ const struct tbl_span *span; /* TBL */
};
/*
@@ -117,6 +119,8 @@ struct man *man_alloc(struct regset *, void *, mandocmsg);
void man_reset(struct man *);
int man_parseln(struct man *, int, char *, int);
int man_endparse(struct man *);
+int man_addspan(struct man *,
+ const struct tbl_span *);
const struct man_node *man_node(const struct man *);
const struct man_meta *man_meta(const struct man *);
diff --git a/man_html.c b/man_html.c
index 0f6d2376..eabbde06 100644
--- a/man_html.c
+++ b/man_html.c
@@ -198,10 +198,10 @@ print_man_node(MAN_ARGS)
break;
case (MAN_TEXT):
print_text(h, n->string);
-
if (MANH_LITERAL & mh->fl)
print_otag(h, TAG_BR, 0, NULL);
-
+ return;
+ case (MAN_TBL):
return;
default:
/*
@@ -226,17 +226,10 @@ print_man_node(MAN_ARGS)
bufinit(h);
- switch (n->type) {
- case (MAN_ROOT):
+ if (MAN_ROOT == n->type)
man_root_post(m, n, mh, h);
- break;
- case (MAN_TEXT):
- break;
- default:
- if (mans[n->tok].post)
- (*mans[n->tok].post)(m, n, mh, h);
- break;
- }
+ else if (mans[n->tok].post)
+ (*mans[n->tok].post)(m, n, mh, h);
}
diff --git a/man_term.c b/man_term.c
index 5a0f67b4..9e041625 100644
--- a/man_term.c
+++ b/man_term.c
@@ -865,6 +865,8 @@ print_man_node(DECL_ARGS)
p->maxrmargin = rmax;
}
break;
+ case (MAN_TBL):
+ break;
default:
if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
term_fontrepl(p, TERMFONT_NONE);
@@ -876,11 +878,17 @@ print_man_node(DECL_ARGS)
if (c && n->child)
print_man_nodelist(p, mt, n->child, m);
- if (MAN_TEXT != n->type) {
+ switch (n->type) {
+ case (MAN_TEXT):
+ /* FALLTHROUGH */
+ case (MAN_TBL):
+ break;
+ default:
if (termacts[n->tok].post)
(*termacts[n->tok].post)(p, mt, n, m);
if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
term_fontrepl(p, TERMFONT_NONE);
+ break;
}
if (MAN_EOS & n->flags)
diff --git a/man_validate.c b/man_validate.c
index a7dcac7c..68584688 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -117,10 +117,16 @@ man_valid_pre(struct man *m, struct man_node *n)
{
v_check *cp;
- if (MAN_TEXT == n->type)
- return(1);
- if (MAN_ROOT == n->type)
+ switch (n->type) {
+ case (MAN_TEXT):
+ /* FALLTHROUGH */
+ case (MAN_ROOT):
+ /* FALLTHROUGH */
+ case (MAN_TBL):
return(1);
+ default:
+ break;
+ }
if (NULL == (cp = man_valids[n->tok].pres))
return(1);
@@ -145,6 +151,8 @@ man_valid_post(struct man *m)
return(check_text(m, m->last));
case (MAN_ROOT):
return(check_root(m, m->last));
+ case (MAN_TBL):
+ return(1);
default:
break;
}
diff --git a/mdoc.c b/mdoc.c
index 324ec9f7..389f0bc1 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -391,6 +391,8 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
mdoc->last = p;
switch (p->type) {
+ case (MDOC_TBL):
+ /* FALLTHROUGH */
case (MDOC_TEXT):
if ( ! mdoc_valid_post(mdoc))
return(0);