summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-02-09 09:05:52 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-02-09 09:05:52 +0000
commit31585348ea96dc3d531dd9a8fdbea4ad5ce4b927 (patch)
tree5ec5f6dd3a3a8484263747c3ea413fb5e90adf13
parent39f12eb291ae2c50f721965715032dae57e1162e (diff)
downloadmandoc-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.c4
-rw-r--r--libroff.h2
-rw-r--r--main.c3
-rw-r--r--mandoc.h2
-rw-r--r--mdoc.39
-rw-r--r--mdoc.c24
-rw-r--r--mdoc.h3
-rw-r--r--roff.c2
-rw-r--r--roff.h1
-rw-r--r--tree.c2
10 files changed, 46 insertions, 6 deletions
diff --git a/eqn.c b/eqn.c
index 83bade95..908d919d 100644
--- a/eqn.c
+++ b/eqn.c
@@ -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);
}
diff --git a/libroff.h b/libroff.h
index c882d487..6d236dbe 100644
--- a/libroff.h
+++ b/libroff.h
@@ -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;
};
diff --git a/main.c b/main.c
index 59063397..8ef19e68 100644
--- a/main.c
+++ b/main.c
@@ -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,
diff --git a/mandoc.h b/mandoc.h
index e8286aee..af4632c1 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -271,6 +271,8 @@ struct tbl_span {
struct eqn {
size_t sz;
char *data;
+ int line; /* invocation line */
+ int pos; /* invocation position */
};
/*
diff --git a/mdoc.3 b/mdoc.3
index ca71f7b3..fe0b41de 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -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.
diff --git a/mdoc.c b/mdoc.c
index 842baec0..ef8a3dc2 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -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;
diff --git a/mdoc.h b/mdoc.h
index 5e846d76..8fc80f0e 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -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
diff --git a/roff.c b/roff.c
index 91e4dcbd..0eff6973 100644
--- a/roff.c
+++ b/roff.c
@@ -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;
}
diff --git a/roff.h b/roff.h
index f8555539..089d6603 100644
--- a/roff.h
+++ b/roff.h
@@ -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
diff --git a/tree.c b/tree.c
index 3b6aa0a8..c88d5eb6 100644
--- a/tree.c
+++ b/tree.c
@@ -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";