summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-23 18:41:18 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-23 18:41:18 +0000
commit44d2f7a5fb2e3d577c9344af556326294473069d (patch)
tree1ecbd175921931b31834c13fdf382939af9b3d6a
parent806c80ef1d9f307a8386c90d661a9d26f212190c (diff)
downloadmandoc-44d2f7a5fb2e3d577c9344af556326294473069d.tar.gz
Add support for tdefine and ndefine. Consolidate some error messages. Add
somem more version notes (getting there). Have the equation nanme be captured.
-rw-r--r--eqn.715
-rw-r--r--eqn.c77
-rw-r--r--index.sgml8
-rw-r--r--libroff.h2
-rw-r--r--mandoc.h2
-rw-r--r--read.c1
-rw-r--r--roff.c2
7 files changed, 75 insertions, 32 deletions
diff --git a/eqn.7 b/eqn.7
index 85d80b91..ea05fdaf 100644
--- a/eqn.7
+++ b/eqn.7
@@ -30,11 +30,13 @@ and
.Xr man 7
.Ux
manual pages.
-This manual describes the subset of the
+This manual describes the
.Nm
language accepted by the
.Xr mandoc 1
-utility.
+utility, which correspond to the Second Edition eqn specification (see
+.Sx SEE ALSO
+for references).
.Pp
Equations within
.Xr mdoc 7
@@ -66,6 +68,8 @@ eqn : box | eqn box
box : text
| \*q{\*q eqn \*q}\*q
| \*qdefine\*q text text
+ | \*qndefine\*q text text
+ | \*qtdefine\*q text text
| \*qgfont\*q text
| \*qgsize\*q text
| \*qset\*q text text
@@ -145,6 +149,13 @@ foo bar 'baz'
.Ed
.Pp
Self-referencing definitions will raise an error.
+The
+.Cm ndefine
+statement is a synonym for
+.Cm define ,
+while
+.Cm tdefine
+is discarded.
.It Cm gfont
Set the default font of subsequent output.
Its syntax is as follows:
diff --git a/eqn.c b/eqn.c
index 8cdef7b6..64538498 100644
--- a/eqn.c
+++ b/eqn.c
@@ -102,6 +102,21 @@ enum eqn_symt {
EQNSYM__MAX
};
+enum eqnpartt {
+ EQN_DEFINE = 0,
+ EQN_NDEFINE,
+ EQN_TDEFINE,
+ EQN_SET,
+ EQN_UNDEF,
+ EQN_GFONT,
+ EQN_GSIZE,
+ EQN_BACK,
+ EQN_FWD,
+ EQN_UP,
+ EQN_DOWN,
+ EQN__MAX
+};
+
struct eqnstr {
const char *name;
size_t sz;
@@ -122,18 +137,6 @@ struct eqnsym {
const char *sym;
};
-enum eqnpartt {
- EQN_DEFINE = 0,
- EQN_SET,
- EQN_UNDEF,
- EQN_GFONT,
- EQN_GSIZE,
- EQN_BACK,
- EQN_FWD,
- EQN_UP,
- EQN_DOWN,
- EQN__MAX
-};
static enum eqn_rest eqn_box(struct eqn_node *, struct eqn_box *);
static struct eqn_box *eqn_box_alloc(struct eqn_node *,
@@ -146,6 +149,7 @@ static int eqn_do_gsize(struct eqn_node *);
static int eqn_do_define(struct eqn_node *);
static int eqn_do_ign1(struct eqn_node *);
static int eqn_do_ign2(struct eqn_node *);
+static int eqn_do_tdefine(struct eqn_node *);
static int eqn_do_undef(struct eqn_node *);
static enum eqn_rest eqn_eqn(struct eqn_node *, struct eqn_box *);
static enum eqn_rest eqn_list(struct eqn_node *, struct eqn_box *);
@@ -158,6 +162,8 @@ static void eqn_rewind(struct eqn_node *);
static const struct eqnpart eqnparts[EQN__MAX] = {
{ { "define", 6 }, eqn_do_define }, /* EQN_DEFINE */
+ { { "ndefine", 7 }, eqn_do_define }, /* EQN_NDEFINE */
+ { { "tdefine", 7 }, eqn_do_tdefine }, /* EQN_TDEFINE */
{ { "set", 3 }, eqn_do_ign2 }, /* EQN_SET */
{ { "undef", 5 }, eqn_do_undef }, /* EQN_UNDEF */
{ { "gfont", 5 }, eqn_do_gfont }, /* EQN_GFONT */
@@ -317,11 +323,24 @@ eqn_read(struct eqn_node **epp, int ln,
}
struct eqn_node *
-eqn_alloc(int pos, int line, struct mparse *parse)
+eqn_alloc(const char *name, int pos, int line, struct mparse *parse)
{
struct eqn_node *p;
+ size_t sz;
+ const char *end;
p = mandoc_calloc(1, sizeof(struct eqn_node));
+
+ if ('\0' != *name) {
+ sz = strlen(name);
+ assert(sz);
+ do {
+ sz--;
+ end = name + (int)sz;
+ } while (' ' == *end || '\t' == *end);
+ p->eqn.name = mandoc_strndup(name, sz + 1);
+ }
+
p->parse = parse;
p->eqn.ln = line;
p->eqn.pos = pos;
@@ -488,7 +507,8 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last)
for (i = 0; i < (int)EQN__MAX; i++) {
if ( ! EQNSTREQ(&eqnparts[i].str, start, sz))
continue;
- return((*eqnparts[i].fp)(ep) ? EQN_OK : EQN_ERR);
+ return((*eqnparts[i].fp)(ep) ?
+ EQN_OK : EQN_ERR);
}
if (STRNEQ(start, sz, "{", 1)) {
@@ -625,6 +645,7 @@ eqn_free(struct eqn_node *p)
free(p->defs[i].val);
}
+ free(p->eqn.name);
free(p->data);
free(p->defs);
free(p);
@@ -701,7 +722,7 @@ again:
/* Prevent self-definitions. */
if (lim >= EQN_NEST_MAX) {
- EQN_MSG(MANDOCERR_EQNNEST, ep);
+ EQN_MSG(MANDOCERR_ROFFLOOP, ep);
return(NULL);
}
@@ -776,9 +797,8 @@ again:
static int
eqn_do_ign1(struct eqn_node *ep)
{
- const char *start;
- if (NULL == (start = eqn_nextrawtok(ep, NULL)))
+ if (NULL == eqn_nextrawtok(ep, NULL))
EQN_MSG(MANDOCERR_EQNEOF, ep);
else
return(1);
@@ -789,11 +809,24 @@ eqn_do_ign1(struct eqn_node *ep)
static int
eqn_do_ign2(struct eqn_node *ep)
{
- const char *start;
- if (NULL == (start = eqn_nextrawtok(ep, NULL)))
+ if (NULL == eqn_nextrawtok(ep, NULL))
+ EQN_MSG(MANDOCERR_EQNEOF, ep);
+ else if (NULL == eqn_nextrawtok(ep, NULL))
+ EQN_MSG(MANDOCERR_EQNEOF, ep);
+ else
+ return(1);
+
+ return(0);
+}
+
+static int
+eqn_do_tdefine(struct eqn_node *ep)
+{
+
+ if (NULL == eqn_nextrawtok(ep, NULL))
EQN_MSG(MANDOCERR_EQNEOF, ep);
- else if (NULL == (start = eqn_nextrawtok(ep, NULL)))
+ else if (NULL == eqn_next(ep, ep->data[(int)ep->cur], NULL, 0))
EQN_MSG(MANDOCERR_EQNEOF, ep);
else
return(1);
@@ -859,9 +892,8 @@ eqn_do_define(struct eqn_node *ep)
static int
eqn_do_gfont(struct eqn_node *ep)
{
- const char *start;
- if (NULL == (start = eqn_nextrawtok(ep, NULL))) {
+ if (NULL == eqn_nextrawtok(ep, NULL)) {
EQN_MSG(MANDOCERR_EQNEOF, ep);
return(0);
}
@@ -878,7 +910,6 @@ eqn_do_gsize(struct eqn_node *ep)
EQN_MSG(MANDOCERR_EQNEOF, ep);
return(0);
}
-
ep->gsize = mandoc_strntoi(start, sz, 10);
return(1);
}
diff --git a/index.sgml b/index.sgml
index 60386bcb..3dd46ffc 100644
--- a/index.sgml
+++ b/index.sgml
@@ -314,9 +314,11 @@
xx-07-2011: version 1.11.5
</P>
<P>
- Significant <A HREF="eqn.7.html">eqn</A> improvements. <SPAN CLASS="nm">mdocml</SPAN> can now parse arbitrary equations
- (although few GNU troff extensions are accepted, nor is mixing low-level roff with eqn). See the <A
- HREF="eqn.7.html">eqn</A> manual for details. For the time being, equations are rendered as simple in-line text.
+ Significant <A HREF="eqn.7.html">eqn</A> improvements. <SPAN CLASS="nm">mdocml</SPAN> can now parse arbitrary eqn input
+ (although few GNU extensions are accepted, nor is mixing low-level roff with eqn). See the <A HREF="eqn.7.html">eqn</A>
+ manual for details. For the time being, equations are rendered as simple in-line text. The equation parser satisfies
+ the language specified in the <A CLASS="external" HREF="http://www.kohala.com/start/troff/v7man/eqn/eqn2e.ps">Second
+ Edition eqn User's Guide</A>.
</P>
<P CLASS="news">
12-07-2011: version 1.11.4
diff --git a/libroff.h b/libroff.h
index 8ef8a605..f6317a96 100644
--- a/libroff.h
+++ b/libroff.h
@@ -73,7 +73,7 @@ int tbl_data(struct tbl_node *, int, const char *);
int tbl_cdata(struct tbl_node *, int, const char *);
const struct tbl_span *tbl_span(struct tbl_node *);
void tbl_end(struct tbl_node *);
-struct eqn_node *eqn_alloc(int, int, struct mparse *);
+struct eqn_node *eqn_alloc(const char *, int, int, struct mparse *);
enum rofferr eqn_end(struct eqn_node *);
void eqn_free(struct eqn_node *);
enum rofferr eqn_read(struct eqn_node **, int,
diff --git a/mandoc.h b/mandoc.h
index dcd4927b..f5e5ba06 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -110,7 +110,6 @@ enum mandocerr {
MANDOCERR_ERROR, /* ===== start of errors ===== */
/* related to equations */
- MANDOCERR_EQNNEST, /* too many nested equation defines */
MANDOCERR_EQNNSCOPE, /* unexpected equation scope closure*/
MANDOCERR_EQNSCOPE, /* equation scope open on exit */
MANDOCERR_EQNBADSCOPE, /* overlapping equation scopes */
@@ -358,6 +357,7 @@ struct eqn_box {
* line and position.
*/
struct eqn {
+ char *name; /* identifier (or NULL) */
struct eqn_box *root; /* root mathematical expression */
int ln; /* invocation line */
int pos; /* invocation position */
diff --git a/read.c b/read.c
index 4c4b3308..a5a860a6 100644
--- a/read.c
+++ b/read.c
@@ -152,7 +152,6 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"generic error",
/* related to equations */
- "too many nested equation defines",
"unexpected equation scope closure",
"equation scope open on exit",
"overlapping equation scopes",
diff --git a/roff.c b/roff.c
index 0bec5549..c6757a29 100644
--- a/roff.c
+++ b/roff.c
@@ -1208,7 +1208,7 @@ roff_EQ(ROFF_ARGS)
struct eqn_node *e;
assert(NULL == r->eqn);
- e = eqn_alloc(ppos, ln, r->parse);
+ e = eqn_alloc(*bufp + pos, ppos, ln, r->parse);
if (r->last_eqn)
r->last_eqn->next = e;