summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 13:37:04 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 13:37:04 +0000
commit62a9685b8f83f61948148be5fd01ec614799aeea (patch)
tree5ebaad6490d0723db30fe56c7b089b009a72e490
parentd98b3838b2d49efc6220b1dc7bdb995e37cd4d10 (diff)
downloadmandoc-62a9685b8f83f61948148be5fd01ec614799aeea.tar.gz
Add eqn subexpression fonts.
-rw-r--r--eqn.74
-rw-r--r--eqn.c43
-rw-r--r--mandoc.h13
-rw-r--r--tree.c9
4 files changed, 52 insertions, 17 deletions
diff --git a/eqn.7 b/eqn.7
index a8447f4a..9e558d6d 100644
--- a/eqn.7
+++ b/eqn.7
@@ -68,6 +68,7 @@ box : text
| SET text text
| UNDEF text
| box mark
+ | font box
text : TEXT
mark : DOT
| DOTDOT
@@ -77,6 +78,9 @@ mark : DOT
| DYAD
| BAR
| UNDER
+font : ROMAN
+ | ITALIC
+ | BOLD
.Ed
.Pp
Data in TEXT form is a non-empty sequence of non-space characters or a
diff --git a/eqn.c b/eqn.c
index 7e2eff80..37488919 100644
--- a/eqn.c
+++ b/eqn.c
@@ -31,15 +31,14 @@
#define EQN_NEST_MAX 128 /* maximum nesting of defines */
#define EQN_MSG(t, x) mandoc_msg((t), (x)->parse, (x)->eqn.ln, (x)->eqn.pos, NULL)
-struct eqnpart {
+struct eqnstr {
const char *name;
size_t sz;
- int (*fp)(struct eqn_node *);
};
-struct eqnmark {
- const char *name;
- size_t sz;
+struct eqnpart {
+ struct eqnstr str;
+ int (*fp)(struct eqn_node *);
};
enum eqnpartt {
@@ -63,12 +62,12 @@ static int eqn_box(struct eqn_node *,
struct eqn_box *, struct eqn_box **);
static const struct eqnpart eqnparts[EQN__MAX] = {
- { "define", 6, eqn_do_define }, /* EQN_DEFINE */
- { "set", 3, eqn_do_set }, /* EQN_SET */
- { "undef", 5, eqn_do_undef }, /* EQN_UNDEF */
+ { { "define", 6 }, eqn_do_define }, /* EQN_DEFINE */
+ { { "set", 3 }, eqn_do_set }, /* EQN_SET */
+ { { "undef", 5 }, eqn_do_undef }, /* EQN_UNDEF */
};
-static const struct eqnmark eqnmarks[EQNMARK__MAX] = {
+static const struct eqnstr eqnmarks[EQNMARK__MAX] = {
{ "", 0 }, /* EQNMARK_NONE */
{ "dot", 3 }, /* EQNMARK_DOT */
{ "dotdot", 6 }, /* EQNMARK_DOTDOT */
@@ -80,6 +79,12 @@ static const struct eqnmark eqnmarks[EQNMARK__MAX] = {
{ "under", 5 }, /* EQNMARK_UNDER */
};
+static const struct eqnstr eqnfonts[EQNFONT__MAX] = {
+ { "roman", 5 },
+ { "bold", 4 },
+ { "italic", 6 },
+};
+
/* ARGSUSED */
enum rofferr
eqn_read(struct eqn_node **epp, int ln,
@@ -173,6 +178,7 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last, struct eqn_box **sv)
size_t sz;
const char *start;
int c, i, nextc;
+ enum eqn_fontt font;
struct eqn_box *bp;
/*
@@ -183,18 +189,28 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last, struct eqn_box **sv)
*sv = last;
nextc = 1;
+ font = EQNFONT_NONE;
+
again:
if (NULL == (start = eqn_nexttok(ep, &sz)))
return(0);
+ for (i = 0; i < (int)EQNFONT__MAX; i++) {
+ if (eqnfonts[i].sz != sz)
+ continue;
+ if (strncmp(eqnfonts[i].name, start, sz))
+ continue;
+ font = (enum eqn_fontt)i;
+ goto again;
+ }
+
for (i = 0; i < (int)EQN__MAX; i++) {
- if (eqnparts[i].sz != sz)
+ if (eqnparts[i].str.sz != sz)
continue;
- if (strncmp(eqnparts[i].name, start, sz))
+ if (strncmp(eqnparts[i].str.name, start, sz))
continue;
if ( ! (*eqnparts[i].fp)(ep))
return(-1);
-
goto again;
}
@@ -213,6 +229,9 @@ again:
return(1);
bp = mandoc_calloc(1, sizeof(struct eqn_box));
+ bp->font = font;
+ font = EQNFONT_NONE;
+
if (nextc)
last->child = bp;
else
diff --git a/mandoc.h b/mandoc.h
index eabbf58b..231497e9 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -298,7 +298,15 @@ enum eqn_markt {
EQNMARK__MAX
};
-/*
+enum eqn_fontt {
+ EQNFONT_NONE = 0,
+ EQNFONT_ROMAN,
+ EQNFONT_BOLD,
+ EQNFONT_ITALIC,
+ EQNFONT__MAX
+};
+
+ /*
* A "box" is a parsed mathematical expression as defined by the eqn.7
* grammar.
*/
@@ -307,7 +315,8 @@ struct eqn_box {
struct eqn_box *child; /* child node */
struct eqn_box *next; /* next in tree */
char *text; /* text (or NULL) */
- enum eqn_markt mark; /* whether 'marked' */
+ enum eqn_markt mark; /* a mark about the box */
+ enum eqn_fontt font; /* font of box */
};
struct eqn {
diff --git a/tree.c b/tree.c
index 82bb0a06..722e396c 100644
--- a/tree.c
+++ b/tree.c
@@ -270,15 +270,18 @@ print_box(const struct eqn_box *ep, int indent)
switch (ep->type) {
case (EQN_ROOT):
- printf("eqn-root(%d)\n", ep->mark);
+ printf("eqn-root(%d, %d)\n",
+ ep->font, ep->mark);
print_box(ep->child, indent + 1);
break;
case (EQN_SUBEXPR):
- printf("eqn-subxpr(%d)\n", ep->mark);
+ printf("eqn-subxpr(%d, %d)\n",
+ ep->font, ep->mark);
print_box(ep->child, indent + 1);
break;
case (EQN_TEXT):
- printf("eqn-text(%d): [%s]\n", ep->mark, ep->text);
+ printf("eqn-text(%d, %d): [%s]\n",
+ ep->font, ep->mark, ep->text);
break;
default:
break;