aboutsummaryrefslogtreecommitdiffstatshomepage
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
commitc80b8c034f0e42db26a04a17527b0b7e3dc6512b (patch)
tree7a146488e062534e63eb8c284052e30e2d869cd6
parent625153bf5457ded8b8946e7f0f831993b94dd863 (diff)
downloadmandoc-c80b8c034f0e42db26a04a17527b0b7e3dc6512b.tar.gz
mandoc-c80b8c034f0e42db26a04a17527b0b7e3dc6512b.tar.zst
mandoc-c80b8c034f0e42db26a04a17527b0b7e3dc6512b.zip
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.312
-rw-r--r--man.c80
-rw-r--r--man.h8
-rw-r--r--man_html.c19
-rw-r--r--man_term.c12
-rw-r--r--man_validate.c16
-rw-r--r--mdoc.c4
7 files changed, 104 insertions, 47 deletions
diff --git a/man.3 b/man.3
index 826c6bda..e72b5297 100644
--- a/man.3
+++ b/man.3
@@ -1,4 +1,4 @@
-.\" $Id: man.3,v 1.27 2010/12/17 11:41:45 kristaps Exp $
+.\" $Id: man.3,v 1.28 2011/01/01 12:59:17 kristaps Exp $
.\"
.\" Copyright (c) 2009-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: December 17 2010 $
+.Dd $Mdocdate: January 1 2011 $
.Dt MAN 3
.Os
.Sh NAME
@@ -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 2792921d..0bdbf59c 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.93 2011/01/01 10:51:30 kristaps Exp $ */
+/* $Id: man.c,v 1.94 2011/01/01 12:59:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 a45eac2b..581f55ff 100644
--- a/man.h
+++ b/man.h
@@ -1,4 +1,4 @@
-/* $Id: man.h,v 1.49 2010/12/26 14:44:13 kristaps Exp $ */
+/* $Id: man.h,v 1.50 2011/01/01 12:59:17 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 4bcdf3dc..31015adb 100644
--- a/man_html.c
+++ b/man_html.c
@@ -1,4 +1,4 @@
-/* $Id: man_html.c,v 1.57 2010/12/24 00:46:49 kristaps Exp $ */
+/* $Id: man_html.c,v 1.58 2011/01/01 12:59:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 77e88aee..4517e98d 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.90 2010/12/08 10:58:22 kristaps Exp $ */
+/* $Id: man_term.c,v 1.91 2011/01/01 12:59:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 d3665d6b..bcfcbacf 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -1,4 +1,4 @@
-/* $Id: man_validate.c,v 1.56 2010/12/08 10:58:22 kristaps Exp $ */
+/* $Id: man_validate.c,v 1.57 2011/01/01 12:59:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 d408449e..1ec309f8 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.175 2011/01/01 12:18:37 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.176 2011/01/01 12:59:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);