summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-01-01 12:18:37 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-01-01 12:18:37 +0000
commite6cfc592798a7e03016169696640f0dd9f11d5e6 (patch)
treee9e5e188e11b13d858969b59b69d45953be7504d
parent0b95ed5dc93d34749b819aa398725ff81f524b89 (diff)
downloadmandoc-e6cfc592798a7e03016169696640f0dd9f11d5e6.tar.gz
mandoc-e6cfc592798a7e03016169696640f0dd9f11d5e6.tar.zst
mandoc-e6cfc592798a7e03016169696640f0dd9f11d5e6.zip
Add table processing structures to -mdoc. This consists of an
external-facing function mdoc_addspan(), then various bits to prohibit printing and scanning (this requires some if's to be converted into switch's).
-rw-r--r--mdoc.312
-rw-r--r--mdoc.c38
-rw-r--r--mdoc.h6
-rw-r--r--mdoc_html.c4
-rw-r--r--mdoc_term.c31
-rw-r--r--mdoc_validate.c21
6 files changed, 95 insertions, 17 deletions
diff --git a/mdoc.3 b/mdoc.3
index be982ddc..49bd4f6b 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -1,4 +1,4 @@
-.\" $Id: mdoc.3,v 1.51 2010/12/17 11:41:45 kristaps Exp $
+.\" $Id: mdoc.3,v 1.52 2011/01/01 12:18:37 kristaps Exp $
.\"
.\" Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,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 MDOC 3
.Os
.Sh NAME
@@ -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 d4f8b49c..d408449e 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.174 2011/01/01 10:51:30 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.175 2011/01/01 12:18:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 17f0cfab..9c22c336 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.113 2010/12/26 14:44:13 kristaps Exp $ */
+/* $Id: mdoc.h,v 1.114 2011/01/01 12:18:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 36008de5..3cfab636 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.139 2010/12/24 22:47:37 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.140 2011/01/01 12:18:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 b9e4b080..3bf82b5f 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.205 2010/12/25 23:27:50 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.206 2011/01/01 12:18:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 aa167454..f5ac5be7 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.149 2010/12/25 23:25:53 kristaps Exp $ */
+/* $Id: mdoc_validate.c,v 1.150 2011/01/01 12:18:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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);