aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 14:13:00 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 14:13:00 +0000
commit610da288ad1c36332f5bc333692f49e2326fa30d (patch)
tree41428bda139fbccd0a81dd5648fefa91a1813b46
parent460878425b46952fed9a61e74b53e8ecd243a9c2 (diff)
downloadmandoc-610da288ad1c36332f5bc333692f49e2326fa30d.tar.gz
mandoc-610da288ad1c36332f5bc333692f49e2326fa30d.tar.zst
mandoc-610da288ad1c36332f5bc333692f49e2326fa30d.zip
Full support for eqn positionals (above, over, sup, sub, etc.).
-rw-r--r--eqn.78
-rw-r--r--eqn.c25
-rw-r--r--mandoc.h18
-rw-r--r--tree.c14
4 files changed, 53 insertions, 12 deletions
diff --git a/eqn.7 b/eqn.7
index a1836e1e..7304a307 100644
--- a/eqn.7
+++ b/eqn.7
@@ -1,4 +1,4 @@
-.\" $Id: eqn.7,v 1.10 2011/07/21 13:37:04 kristaps Exp $
+.\" $Id: eqn.7,v 1.11 2011/07/21 14:13:00 kristaps Exp $
.\"
.\" Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -67,9 +67,15 @@ box : text
| DEFINE text text
| SET text text
| UNDEF text
+ | box pos box
| box mark
| font box
text : TEXT
+pos : OVER
+ | SUP
+ | SUB
+ | TO
+ | FROM
mark : DOT
| DOTDOT
| HAT
diff --git a/eqn.c b/eqn.c
index d10156b0..23dd934e 100644
--- a/eqn.c
+++ b/eqn.c
@@ -1,4 +1,4 @@
-/* $Id: eqn.c,v 1.17 2011/07/21 13:37:04 kristaps Exp $ */
+/* $Id: eqn.c,v 1.18 2011/07/21 14:13:00 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -80,11 +80,22 @@ static const struct eqnstr eqnmarks[EQNMARK__MAX] = {
};
static const struct eqnstr eqnfonts[EQNFONT__MAX] = {
+ { "", 0 },
{ "roman", 5 },
{ "bold", 4 },
{ "italic", 6 },
};
+static const struct eqnstr eqnposs[EQNPOS__MAX] = {
+ { "", 0 },
+ { "over", 4 },
+ { "sup", 3 },
+ { "sub", 3 },
+ { "to", 2 },
+ { "from", 4 },
+ { "above", 5 },
+};
+
/* ARGSUSED */
enum rofferr
eqn_read(struct eqn_node **epp, int ln,
@@ -189,8 +200,7 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last, struct eqn_box **sv)
*sv = last;
nextc = 1;
- font = EQNFONT_NONE;
-
+ font = EQNFONT_NONE;
again:
if (NULL == (start = eqn_nexttok(ep, &sz)))
return(0);
@@ -204,6 +214,15 @@ again:
goto again;
}
+ for (i = 0; i < (int)EQNFONT__MAX; i++) {
+ if (eqnposs[i].sz != sz)
+ continue;
+ if (strncmp(eqnposs[i].name, start, sz))
+ continue;
+ last->pos = (enum eqn_post)i;
+ goto again;
+ }
+
for (i = 0; i < (int)EQN__MAX; i++) {
if (eqnparts[i].str.sz != sz)
continue;
diff --git a/mandoc.h b/mandoc.h
index 4e14f44f..cd29e688 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.86 2011/07/21 13:37:04 kristaps Exp $ */
+/* $Id: mandoc.h,v 1.87 2011/07/21 14:13:00 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -306,6 +306,17 @@ enum eqn_fontt {
EQNFONT__MAX
};
+enum eqn_post {
+ EQNPOS_NONE = 0,
+ EQNPOS_OVER,
+ EQNPOS_SUP,
+ EQNPOS_SUB,
+ EQNPOS_TO,
+ EQNPOS_FROM,
+ EQNPOS_ABOVE,
+ EQNPOS__MAX
+};
+
/*
* A "box" is a parsed mathematical expression as defined by the eqn.7
* grammar.
@@ -314,11 +325,16 @@ struct eqn_box {
enum eqn_boxt type; /* type of node */
struct eqn_box *child; /* child node */
struct eqn_box *next; /* next in tree */
+ enum eqn_post pos; /* position of next box */
char *text; /* text (or NULL) */
enum eqn_markt mark; /* a mark about the box */
enum eqn_fontt font; /* font of box */
};
+/*
+ * An equation consists of a tree of expressions starting at a given
+ * line and position.
+ */
struct eqn {
struct eqn_box *root; /* root mathematical expression */
int ln; /* invocation line */
diff --git a/tree.c b/tree.c
index e36132a0..1c03c716 100644
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.41 2011/07/21 13:37:04 kristaps Exp $ */
+/* $Id: tree.c,v 1.42 2011/07/21 14:13:00 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -270,18 +270,18 @@ print_box(const struct eqn_box *ep, int indent)
switch (ep->type) {
case (EQN_ROOT):
- printf("eqn-root(%d, %d)\n",
- ep->font, ep->mark);
+ printf("eqn-root(%d, %d, %d)\n",
+ ep->pos, ep->font, ep->mark);
print_box(ep->child, indent + 1);
break;
case (EQN_SUBEXPR):
- printf("eqn-subxpr(%d, %d)\n",
- ep->font, ep->mark);
+ printf("eqn-subxpr(%d, %d, %d)\n",
+ ep->pos, ep->font, ep->mark);
print_box(ep->child, indent + 1);
break;
case (EQN_TEXT):
- printf("eqn-text(%d, %d): [%s]\n",
- ep->font, ep->mark, ep->text);
+ printf("eqn-text(%d, %d, %d): [%s]\n",
+ ep->pos, ep->font, ep->mark, ep->text);
break;
default:
break;