diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-02-09 09:05:52 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-02-09 09:05:52 +0000 |
commit | 31585348ea96dc3d531dd9a8fdbea4ad5ce4b927 (patch) | |
tree | 5ec5f6dd3a3a8484263747c3ea413fb5e90adf13 | |
parent | 39f12eb291ae2c50f721965715032dae57e1162e (diff) | |
download | mandoc-31585348ea96dc3d531dd9a8fdbea4ad5ce4b927.tar.gz |
Allow EQN data to be pushed down into libmdoc via mdoc_addeqn(). Only
the adding itself is implemented; equation data is not yet shown.
-rw-r--r-- | eqn.c | 4 | ||||
-rw-r--r-- | libroff.h | 2 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | mandoc.h | 2 | ||||
-rw-r--r-- | mdoc.3 | 9 | ||||
-rw-r--r-- | mdoc.c | 24 | ||||
-rw-r--r-- | mdoc.h | 3 | ||||
-rw-r--r-- | roff.c | 2 | ||||
-rw-r--r-- | roff.h | 1 | ||||
-rw-r--r-- | tree.c | 2 |
10 files changed, 46 insertions, 6 deletions
@@ -59,8 +59,8 @@ eqn_alloc(int pos, int line) struct eqn_node *p; p = mandoc_calloc(1, sizeof(struct eqn_node)); - p->line = line; - p->pos = pos; + p->eqn.line = line; + p->eqn.pos = pos; return(p); } @@ -44,8 +44,6 @@ struct tbl_node { }; struct eqn_node { - int pos; /* invocation column */ - int line; /* invocation line */ struct eqn eqn; struct eqn_node *next; }; @@ -865,6 +865,9 @@ rerun: } } else if (ROFF_EQN == rr) { assert(curp->man || curp->mdoc); + assert(roff_eqn(curp->roff)); + if (curp->mdoc) + mdoc_addeqn(curp->mdoc, roff_eqn(curp->roff)); } else if (curp->man || curp->mdoc) { rc = curp->man ? man_parseln(curp->man, @@ -271,6 +271,8 @@ struct tbl_span { struct eqn { size_t sz; char *data; + int line; /* invocation line */ + int pos; /* invocation position */ }; /* @@ -34,6 +34,11 @@ .Vt extern const char * const * mdoc_macronames; .Vt extern const char * const * mdoc_argnames; .Ft int +.Fo mdoc_addeqn +.Fa "struct mdoc *mdoc" +.Fa "const struct eqn *eqn" +.Fc +.Ft int .Fo mdoc_addspan .Fa "struct mdoc *mdoc" .Fa "const struct tbl_span *span" @@ -97,6 +102,7 @@ for details. .El .Ss Functions If +.Fn mdoc_addeqn , .Fn mdoc_addspan , .Fn mdoc_parseln , or @@ -107,6 +113,9 @@ or .Fn mdoc_free will raise an assertion. .Bl -ohang +.It Fn mdoc_addeqn +Add an equation to the parsing stream. +Returns 0 on failure, 1 on success. .It Fn mdoc_addspan Add a table span to the parsing stream. Returns 0 on failure, 1 on success. @@ -222,6 +222,30 @@ mdoc_endparse(struct mdoc *m) } int +mdoc_addeqn(struct mdoc *m, const struct eqn *ep) +{ + struct mdoc_node *n; + + assert( ! (MDOC_HALT & m->flags)); + + /* No text before an initial macro. */ + + if (SEC_NONE == m->lastnamed) { + mdoc_pmsg(m, ep->line, ep->pos, MANDOCERR_NOTEXT); + return(1); + } + + n = node_alloc(m, ep->line, ep->pos, MDOC_MAX, MDOC_EQN); + n->eqn = ep; + + if ( ! node_append(m, n)) + return(0); + + m->next = MDOC_NEXT_SIBLING; + return(1); +} + +int mdoc_addspan(struct mdoc *m, const struct tbl_span *sp) { struct mdoc_node *n; @@ -402,6 +402,7 @@ struct mdoc_node { struct mdoc_node *tail; /* BLOCK */ char *string; /* TEXT */ const struct tbl_span *span; /* TBL */ + const struct eqn *eqn; /* EQN */ enum mdoc_endbody end; /* BODY */ }; @@ -431,6 +432,8 @@ const struct mdoc_meta *mdoc_meta(const struct mdoc *); int mdoc_endparse(struct mdoc *); int mdoc_addspan(struct mdoc *, const struct tbl_span *); +int mdoc_addeqn(struct mdoc *, + const struct eqn *); __END_DECLS @@ -560,7 +560,7 @@ roff_endparse(struct roff *r) if (r->eqn) { (*r->msg)(MANDOCERR_SCOPEEXIT, r->data, - r->eqn->line, r->eqn->pos, NULL); + r->eqn->eqn.line, r->eqn->eqn.pos, NULL); eqn_end(r->eqn); r->eqn = NULL; } @@ -40,6 +40,7 @@ enum rofferr roff_parseln(struct roff *, int, char **, size_t *, int, int *); void roff_endparse(struct roff *); const struct tbl_span *roff_span(const struct roff *); +const struct eqn *roff_eqn(const struct roff *); __END_DECLS @@ -132,7 +132,7 @@ print_mdoc(const struct mdoc_node *n, int indent) case (MDOC_TBL): break; case (MDOC_EQN): - p = "eqn"; + p = n->eqn->data; break; case (MDOC_ROOT): p = "root"; |