version 1.35, 2011/07/23 13:31:03 |
version 1.38, 2011/07/25 15:37:00 |
|
|
EQNSYM__MAX |
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 { |
struct eqnstr { |
const char *name; |
const char *name; |
size_t sz; |
size_t sz; |
|
|
const char *sym; |
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 enum eqn_rest eqn_box(struct eqn_node *, struct eqn_box *); |
static struct eqn_box *eqn_box_alloc(struct eqn_node *, |
static struct eqn_box *eqn_box_alloc(struct eqn_node *, |
Line 146 static int eqn_do_gsize(struct eqn_node *); |
|
Line 149 static int eqn_do_gsize(struct eqn_node *); |
|
static int eqn_do_define(struct eqn_node *); |
static int eqn_do_define(struct eqn_node *); |
static int eqn_do_ign1(struct eqn_node *); |
static int eqn_do_ign1(struct eqn_node *); |
static int eqn_do_ign2(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 int eqn_do_undef(struct eqn_node *); |
static enum eqn_rest eqn_eqn(struct eqn_node *, struct eqn_box *); |
static enum eqn_rest eqn_eqn(struct eqn_node *, struct eqn_box *); |
static enum eqn_rest eqn_list(struct eqn_node *, struct eqn_box *); |
static enum eqn_rest eqn_list(struct eqn_node *, struct eqn_box *); |
Line 158 static void eqn_rewind(struct eqn_node *); |
|
Line 162 static void eqn_rewind(struct eqn_node *); |
|
|
|
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 */ |
|
{ { "ndefine", 7 }, eqn_do_define }, /* EQN_NDEFINE */ |
|
{ { "tdefine", 7 }, eqn_do_tdefine }, /* EQN_TDEFINE */ |
{ { "set", 3 }, eqn_do_ign2 }, /* EQN_SET */ |
{ { "set", 3 }, eqn_do_ign2 }, /* EQN_SET */ |
{ { "undef", 5 }, eqn_do_undef }, /* EQN_UNDEF */ |
{ { "undef", 5 }, eqn_do_undef }, /* EQN_UNDEF */ |
{ { "gfont", 5 }, eqn_do_gfont }, /* EQN_GFONT */ |
{ { "gfont", 5 }, eqn_do_gfont }, /* EQN_GFONT */ |
Line 199 static const struct eqnstr eqnposs[EQNPOS__MAX] = { |
|
Line 205 static const struct eqnstr eqnposs[EQNPOS__MAX] = { |
|
|
|
static const struct eqnstr eqnpiles[EQNPILE__MAX] = { |
static const struct eqnstr eqnpiles[EQNPILE__MAX] = { |
{ "", 0 }, /* EQNPILE_NONE */ |
{ "", 0 }, /* EQNPILE_NONE */ |
|
{ "pile", 4 }, /* EQNPILE_PILE */ |
{ "cpile", 5 }, /* EQNPILE_CPILE */ |
{ "cpile", 5 }, /* EQNPILE_CPILE */ |
{ "rpile", 5 }, /* EQNPILE_RPILE */ |
{ "rpile", 5 }, /* EQNPILE_RPILE */ |
{ "lpile", 5 }, /* EQNPILE_LPILE */ |
{ "lpile", 5 }, /* EQNPILE_LPILE */ |
|
{ "col", 3 }, /* EQNPILE_COL */ |
{ "ccol", 4 }, /* EQNPILE_CCOL */ |
{ "ccol", 4 }, /* EQNPILE_CCOL */ |
{ "rcol", 4 }, /* EQNPILE_RCOL */ |
{ "rcol", 4 }, /* EQNPILE_RCOL */ |
{ "lcol", 4 }, /* EQNPILE_LCOL */ |
{ "lcol", 4 }, /* EQNPILE_LCOL */ |
Line 286 eqn_read(struct eqn_node **epp, int ln, |
|
Line 294 eqn_read(struct eqn_node **epp, int ln, |
|
*/ |
*/ |
|
|
if (0 == strncmp(p, ".EN", 3)) { |
if (0 == strncmp(p, ".EN", 3)) { |
er = eqn_end(ep); |
er = eqn_end(epp); |
*epp = NULL; |
|
p += 3; |
p += 3; |
while (' ' == *p || '\t' == *p) |
while (' ' == *p || '\t' == *p) |
p++; |
p++; |
Line 317 eqn_read(struct eqn_node **epp, int ln, |
|
Line 324 eqn_read(struct eqn_node **epp, int ln, |
|
} |
} |
|
|
struct eqn_node * |
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; |
struct eqn_node *p; |
|
size_t sz; |
|
const char *end; |
|
|
p = mandoc_calloc(1, sizeof(struct eqn_node)); |
p = mandoc_calloc(1, sizeof(struct eqn_node)); |
|
|
|
if (name && '\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->parse = parse; |
p->eqn.ln = line; |
p->eqn.ln = line; |
p->eqn.pos = pos; |
p->eqn.pos = pos; |
Line 331 eqn_alloc(int pos, int line, struct mparse *parse) |
|
Line 351 eqn_alloc(int pos, int line, struct mparse *parse) |
|
} |
} |
|
|
enum rofferr |
enum rofferr |
eqn_end(struct eqn_node *ep) |
eqn_end(struct eqn_node **epp) |
{ |
{ |
|
struct eqn_node *ep; |
struct eqn_box *root; |
struct eqn_box *root; |
enum eqn_rest c; |
enum eqn_rest c; |
|
|
|
ep = *epp; |
|
*epp = NULL; |
|
|
ep->eqn.root = mandoc_calloc(1, sizeof(struct eqn_box)); |
ep->eqn.root = mandoc_calloc(1, sizeof(struct eqn_box)); |
|
|
root = ep->eqn.root; |
root = ep->eqn.root; |
Line 488 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
Line 512 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
for (i = 0; i < (int)EQN__MAX; i++) { |
for (i = 0; i < (int)EQN__MAX; i++) { |
if ( ! EQNSTREQ(&eqnparts[i].str, start, sz)) |
if ( ! EQNSTREQ(&eqnparts[i].str, start, sz)) |
continue; |
continue; |
return((*eqnparts[i].fp)(ep) ? EQN_OK : EQN_ERR); |
return((*eqnparts[i].fp)(ep) ? |
|
EQN_OK : EQN_ERR); |
} |
} |
|
|
if (STRNEQ(start, sz, "{", 1)) { |
if (STRNEQ(start, sz, "{", 1)) { |
Line 625 eqn_free(struct eqn_node *p) |
|
Line 650 eqn_free(struct eqn_node *p) |
|
free(p->defs[i].val); |
free(p->defs[i].val); |
} |
} |
|
|
|
free(p->eqn.name); |
free(p->data); |
free(p->data); |
free(p->defs); |
free(p->defs); |
free(p); |
free(p); |
|
|
/* Prevent self-definitions. */ |
/* Prevent self-definitions. */ |
|
|
if (lim >= EQN_NEST_MAX) { |
if (lim >= EQN_NEST_MAX) { |
EQN_MSG(MANDOCERR_EQNNEST, ep); |
EQN_MSG(MANDOCERR_ROFFLOOP, ep); |
return(NULL); |
return(NULL); |
} |
} |
|
|
|
|
static int |
static int |
eqn_do_ign1(struct eqn_node *ep) |
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); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
else |
else |
return(1); |
return(1); |
Line 789 eqn_do_ign1(struct eqn_node *ep) |
|
Line 814 eqn_do_ign1(struct eqn_node *ep) |
|
static int |
static int |
eqn_do_ign2(struct eqn_node *ep) |
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); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
else if (NULL == (start = eqn_nextrawtok(ep, NULL))) |
else if (NULL == eqn_nextrawtok(ep, NULL)) |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
else |
else |
return(1); |
return(1); |
Line 802 eqn_do_ign2(struct eqn_node *ep) |
|
Line 826 eqn_do_ign2(struct eqn_node *ep) |
|
} |
} |
|
|
static int |
static int |
|
eqn_do_tdefine(struct eqn_node *ep) |
|
{ |
|
|
|
if (NULL == eqn_nextrawtok(ep, NULL)) |
|
EQN_MSG(MANDOCERR_EQNEOF, ep); |
|
else if (NULL == eqn_next(ep, ep->data[(int)ep->cur], NULL, 0)) |
|
EQN_MSG(MANDOCERR_EQNEOF, ep); |
|
else |
|
return(1); |
|
|
|
return(0); |
|
} |
|
|
|
static int |
eqn_do_define(struct eqn_node *ep) |
eqn_do_define(struct eqn_node *ep) |
{ |
{ |
const char *start; |
const char *start; |
Line 859 eqn_do_define(struct eqn_node *ep) |
|
Line 897 eqn_do_define(struct eqn_node *ep) |
|
static int |
static int |
eqn_do_gfont(struct eqn_node *ep) |
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); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
return(0); |
return(0); |
} |
} |
Line 878 eqn_do_gsize(struct eqn_node *ep) |
|
Line 915 eqn_do_gsize(struct eqn_node *ep) |
|
EQN_MSG(MANDOCERR_EQNEOF, ep); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
return(0); |
return(0); |
} |
} |
|
|
ep->gsize = mandoc_strntoi(start, sz, 10); |
ep->gsize = mandoc_strntoi(start, sz, 10); |
return(1); |
return(1); |
} |
} |