version 1.14, 2011/07/21 11:57:56 |
version 1.16, 2011/07/21 13:18:24 |
|
|
int (*fp)(struct eqn_node *); |
int (*fp)(struct eqn_node *); |
}; |
}; |
|
|
|
struct eqnmark { |
|
const char *name; |
|
size_t sz; |
|
}; |
|
|
enum eqnpartt { |
enum eqnpartt { |
EQN_DEFINE = 0, |
EQN_DEFINE = 0, |
EQN_SET, |
EQN_SET, |
Line 54 static const char *eqn_nexttok(struct eqn_node *, size |
|
Line 59 static const char *eqn_nexttok(struct eqn_node *, size |
|
static const char *eqn_nextrawtok(struct eqn_node *, size_t *); |
static const char *eqn_nextrawtok(struct eqn_node *, size_t *); |
static const char *eqn_next(struct eqn_node *, |
static const char *eqn_next(struct eqn_node *, |
char, size_t *, int); |
char, size_t *, int); |
static int eqn_box(struct eqn_node *, struct eqn_box *); |
static int eqn_box(struct eqn_node *, |
|
struct eqn_box *, struct eqn_box **); |
|
|
static const struct eqnpart eqnparts[EQN__MAX] = { |
static const struct eqnpart eqnparts[EQN__MAX] = { |
{ "define", 6, eqn_do_define }, /* EQN_DEFINE */ |
{ "define", 6, eqn_do_define }, /* EQN_DEFINE */ |
Line 62 static const struct eqnpart eqnparts[EQN__MAX] = { |
|
Line 68 static const struct eqnpart eqnparts[EQN__MAX] = { |
|
{ "undef", 5, eqn_do_undef }, /* EQN_UNDEF */ |
{ "undef", 5, eqn_do_undef }, /* EQN_UNDEF */ |
}; |
}; |
|
|
|
static const struct eqnmark eqnmarks[EQNMARK__MAX] = { |
|
{ "", 0 }, /* EQNMARK_NONE */ |
|
{ "dot", 3 }, /* EQNMARK_DOT */ |
|
{ "dotdot", 6 }, /* EQNMARK_DOTDOT */ |
|
{ "hat", 3 }, /* EQNMARK_HAT */ |
|
{ "tilde", 5 }, /* EQNMARK_TILDE */ |
|
{ "vec", 3 }, /* EQNMARK_VEC */ |
|
{ "dyad", 4 }, /* EQNMARK_DYAD */ |
|
{ "bar", 3 }, /* EQNMARK_BAR */ |
|
{ "under", 5 }, /* EQNMARK_UNDER */ |
|
}; |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
enum rofferr |
enum rofferr |
eqn_read(struct eqn_node **epp, int ln, |
eqn_read(struct eqn_node **epp, int ln, |
Line 119 eqn_alloc(int pos, int line, struct mparse *parse) |
|
Line 137 eqn_alloc(int pos, int line, struct mparse *parse) |
|
enum rofferr |
enum rofferr |
eqn_end(struct eqn_node *ep) |
eqn_end(struct eqn_node *ep) |
{ |
{ |
struct eqn_box *root; |
struct eqn_box *root, *last; |
|
int c; |
|
|
ep->eqn.root = root = |
ep->eqn.root = root = |
mandoc_calloc(1, sizeof(struct eqn_box)); |
mandoc_calloc(1, sizeof(struct eqn_box)); |
Line 129 eqn_end(struct eqn_node *ep) |
|
Line 148 eqn_end(struct eqn_node *ep) |
|
return(ROFF_IGN); |
return(ROFF_IGN); |
|
|
/* |
/* |
* Validate the expression. |
* Run the parser. |
* Use the grammar found in the literature. |
* If we return before reaching the end of our input, our scope |
|
* is still open somewhere. |
|
* If we return alright but don't have a symmetric scoping, then |
|
* something's not right either. |
|
* Otherwise, return the equation. |
*/ |
*/ |
|
|
return(eqn_box(ep, root) < 0 ? ROFF_IGN : ROFF_EQN); |
if (0 == (c = eqn_box(ep, root, &last))) { |
|
if (last != root) { |
|
EQN_MSG(MANDOCERR_EQNSCOPE, ep); |
|
c = 0; |
|
} |
|
} else if (c > 0) |
|
EQN_MSG(MANDOCERR_EQNNSCOPE, ep); |
|
|
|
return(0 == c ? ROFF_EQN : ROFF_IGN); |
} |
} |
|
|
static int |
static int |
eqn_box(struct eqn_node *ep, struct eqn_box *last) |
eqn_box(struct eqn_node *ep, struct eqn_box *last, struct eqn_box **sv) |
{ |
{ |
size_t sz; |
size_t sz; |
const char *start; |
const char *start; |
int i, nextc; |
int c, i, nextc; |
struct eqn_box *bp; |
struct eqn_box *bp; |
|
|
|
/* |
|
* Mark our last level of subexpression. |
|
* Also mark whether that the next node should be a |
|
* subexpression node. |
|
*/ |
|
|
|
*sv = last; |
nextc = 1; |
nextc = 1; |
again: |
again: |
if (NULL == (start = eqn_nexttok(ep, &sz))) |
if (NULL == (start = eqn_nexttok(ep, &sz))) |
|
|
goto again; |
goto again; |
} |
} |
|
|
bp = mandoc_calloc(1, sizeof(struct eqn_box)); |
for (i = 0; i < (int)EQNMARK__MAX; i++) { |
bp->type = EQN_TEXT; |
if (eqnmarks[i].sz != sz) |
|
continue; |
|
if (strncmp(eqnmarks[i].name, start, sz)) |
|
continue; |
|
last->mark = (enum eqn_markt)i; |
|
goto again; |
|
} |
|
|
|
/* Exit this [hopefully] subexpression. */ |
|
|
|
if (sz == 1 && 0 == strncmp("}", start, 1)) |
|
return(1); |
|
|
|
bp = mandoc_calloc(1, sizeof(struct eqn_box)); |
if (nextc) |
if (nextc) |
last->child = bp; |
last->child = bp; |
else |
else |
last->next = bp; |
last->next = bp; |
|
|
|
last = bp; |
|
|
|
/* |
|
* See if we're to open a new subexpression. |
|
* If so, mark our node as such and descend. |
|
*/ |
|
|
|
if (sz == 1 && 0 == strncmp("{", start, 1)) { |
|
bp->type = EQN_SUBEXPR; |
|
c = eqn_box(ep, bp, sv); |
|
|
|
nextc = 0; |
|
goto again; |
|
} |
|
|
|
/* A regular text node. */ |
|
|
|
bp->type = EQN_TEXT; |
bp->text = mandoc_malloc(sz + 1); |
bp->text = mandoc_malloc(sz + 1); |
*bp->text = '\0'; |
*bp->text = '\0'; |
strlcat(bp->text, start, sz + 1); |
strlcat(bp->text, start, sz + 1); |
|
|
last = bp; |
|
nextc = 0; |
nextc = 0; |
goto again; |
goto again; |
} |
} |