version 1.37, 2011/07/23 18:44:42 |
version 1.42, 2014/04/23 21:06:41 |
|
|
#include <time.h> |
#include <time.h> |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
|
#include "mandoc_aux.h" |
#include "libmandoc.h" |
#include "libmandoc.h" |
#include "libroff.h" |
#include "libroff.h" |
|
|
|
|
const char *sym; |
const char *sym; |
}; |
}; |
|
|
|
|
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 *, |
struct eqn_box *); |
struct eqn_box *); |
static void eqn_box_free(struct eqn_box *); |
static void eqn_box_free(struct eqn_box *); |
static struct eqn_def *eqn_def_find(struct eqn_node *, |
static struct eqn_def *eqn_def_find(struct eqn_node *, |
const char *, size_t); |
const char *, size_t); |
static int eqn_do_gfont(struct eqn_node *); |
static int eqn_do_gfont(struct eqn_node *); |
static int eqn_do_gsize(struct eqn_node *); |
static int eqn_do_gsize(struct eqn_node *); |
Line 156 static enum eqn_rest eqn_list(struct eqn_node *, stru |
|
Line 156 static enum eqn_rest eqn_list(struct eqn_node *, stru |
|
static enum eqn_rest eqn_matrix(struct eqn_node *, struct eqn_box *); |
static enum eqn_rest eqn_matrix(struct eqn_node *, struct eqn_box *); |
static const char *eqn_nexttok(struct eqn_node *, size_t *); |
static const char *eqn_nexttok(struct eqn_node *, size_t *); |
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 void eqn_rewind(struct eqn_node *); |
static void eqn_rewind(struct eqn_node *); |
|
|
Line 277 static const struct eqnsym eqnsyms[EQNSYM__MAX] = { |
|
Line 277 static const struct eqnsym eqnsyms[EQNSYM__MAX] = { |
|
{ { ">=", 2 }, ">=" }, /* EQNSYM_moreequal */ |
{ { ">=", 2 }, ">=" }, /* EQNSYM_moreequal */ |
}; |
}; |
|
|
/* ARGSUSED */ |
|
enum rofferr |
enum rofferr |
eqn_read(struct eqn_node **epp, int ln, |
eqn_read(struct eqn_node **epp, int ln, |
const char *p, int pos, int *offs) |
const char *p, int pos, int *offs) |
{ |
{ |
size_t sz; |
size_t sz; |
Line 294 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++; |
if ('\0' == *p) |
if ('\0' == *p) |
return(er); |
return(er); |
mandoc_msg(MANDOCERR_ARGSLOST, ep->parse, ln, pos, NULL); |
mandoc_msg(MANDOCERR_ARGSLOST, ep->parse, ln, pos, NULL); |
return(er); |
return(er); |
Line 333 eqn_alloc(const char *name, int pos, int line, struct |
|
Line 332 eqn_alloc(const char *name, int pos, int line, struct |
|
|
|
p = mandoc_calloc(1, sizeof(struct eqn_node)); |
p = mandoc_calloc(1, sizeof(struct eqn_node)); |
|
|
if ('\0' != *name) { |
if (name && '\0' != *name) { |
sz = strlen(name); |
sz = strlen(name); |
assert(sz); |
assert(sz); |
do { |
do { |
Line 352 eqn_alloc(const char *name, int pos, int line, struct |
|
Line 351 eqn_alloc(const char *name, int pos, int line, struct |
|
} |
} |
|
|
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 410 eqn_matrix(struct eqn_node *ep, struct eqn_box *last) |
|
Line 413 eqn_matrix(struct eqn_node *ep, struct eqn_box *last) |
|
|
|
while (EQN_OK == (c = eqn_box(ep, bp))) |
while (EQN_OK == (c = eqn_box(ep, bp))) |
switch (bp->last->pile) { |
switch (bp->last->pile) { |
case (EQNPILE_LCOL): |
case EQNPILE_LCOL: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (EQNPILE_CCOL): |
case EQNPILE_CCOL: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (EQNPILE_RCOL): |
case EQNPILE_RCOL: |
continue; |
continue; |
default: |
default: |
EQN_MSG(MANDOCERR_EQNSYNT, ep); |
EQN_MSG(MANDOCERR_EQNSYNT, ep); |
Line 509 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) ? |
return((*eqnparts[i].fp)(ep) ? EQN_OK : EQN_ERR); |
EQN_OK : EQN_ERR); |
} |
} |
|
|
|
if (STRNEQ(start, sz, "{", 1)) { |
if (STRNEQ(start, sz, "{", 1)) { |
if (EQN_DESCOPE != (c = eqn_eqn(ep, last))) { |
if (EQN_DESCOPE != (c = eqn_eqn(ep, last))) { |
Line 526 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
Line 528 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
return(EQN_OK); |
return(EQN_OK); |
EQN_MSG(MANDOCERR_EQNBADSCOPE, ep); |
EQN_MSG(MANDOCERR_EQNBADSCOPE, ep); |
return(EQN_ERR); |
return(EQN_ERR); |
} |
} |
|
|
for (i = 0; i < (int)EQNPILE__MAX; i++) { |
for (i = 0; i < (int)EQNPILE__MAX; i++) { |
if ( ! EQNSTREQ(&eqnpiles[i], start, sz)) |
if ( ! EQNSTREQ(&eqnpiles[i], start, sz)) |
Line 572 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
Line 574 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
if (NULL == last->last) { |
if (NULL == last->last) { |
EQN_MSG(MANDOCERR_EQNSYNT, ep); |
EQN_MSG(MANDOCERR_EQNSYNT, ep); |
return(EQN_ERR); |
return(EQN_ERR); |
} |
} |
last->last->pos = (enum eqn_post)i; |
last->last->pos = (enum eqn_post)i; |
if (EQN_EOF == (c = eqn_box(ep, last))) { |
if (EQN_EOF == (c = eqn_box(ep, last))) { |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
Line 587 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
Line 589 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
if (NULL == last->last) { |
if (NULL == last->last) { |
EQN_MSG(MANDOCERR_EQNSYNT, ep); |
EQN_MSG(MANDOCERR_EQNSYNT, ep); |
return(EQN_ERR); |
return(EQN_ERR); |
} |
} |
last->last->mark = (enum eqn_markt)i; |
last->last->mark = (enum eqn_markt)i; |
if (EQN_EOF == (c = eqn_box(ep, last))) { |
if (EQN_EOF == (c = eqn_box(ep, last))) { |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
Line 626 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
Line 628 eqn_box(struct eqn_node *ep, struct eqn_box *last) |
|
for (i = 0; i < (int)EQNSYM__MAX; i++) |
for (i = 0; i < (int)EQNSYM__MAX; i++) |
if (EQNSTREQ(&eqnsyms[i].str, start, sz)) { |
if (EQNSTREQ(&eqnsyms[i].str, start, sz)) { |
sym[63] = '\0'; |
sym[63] = '\0'; |
snprintf(sym, 62, "\\[%s]", eqnsyms[i].sym); |
(void)snprintf(sym, 62, "\\[%s]", eqnsyms[i].sym); |
bp->text = mandoc_strdup(sym); |
bp->text = mandoc_strdup(sym); |
return(EQN_OK); |
return(EQN_OK); |
} |
} |
|
|
if (q) |
if (q) |
ep->cur++; |
ep->cur++; |
while (' ' == ep->data[(int)ep->cur] || |
while (' ' == ep->data[(int)ep->cur] || |
'\t' == ep->data[(int)ep->cur] || |
'\t' == ep->data[(int)ep->cur] || |
'^' == ep->data[(int)ep->cur] || |
'^' == ep->data[(int)ep->cur] || |
'~' == ep->data[(int)ep->cur]) |
'~' == ep->data[(int)ep->cur]) |
ep->cur++; |
ep->cur++; |
} else { |
} else { |
if (q) |
if (q) |
|
|
} |
} |
|
|
diff = def->valsz - *sz; |
diff = def->valsz - *sz; |
memmove(start + *sz + diff, start + *sz, |
memmove(start + *sz + diff, start + *sz, |
(strlen(start) - *sz) + 1); |
(strlen(start) - *sz) + 1); |
memcpy(start, def->val, def->valsz); |
memcpy(start, def->val, def->valsz); |
goto again; |
goto again; |
} |
} |
Line 849 eqn_do_define(struct eqn_node *ep) |
|
Line 851 eqn_do_define(struct eqn_node *ep) |
|
return(0); |
return(0); |
} |
} |
|
|
/* |
/* |
* Search for a key that already exists. |
* Search for a key that already exists. |
* Create a new key if none is found. |
* Create a new key if none is found. |
*/ |
*/ |
|
|
Line 862 eqn_do_define(struct eqn_node *ep) |
|
Line 864 eqn_do_define(struct eqn_node *ep) |
|
|
|
if (i == (int)ep->defsz) { |
if (i == (int)ep->defsz) { |
ep->defsz++; |
ep->defsz++; |
ep->defs = mandoc_realloc |
ep->defs = mandoc_reallocarray(ep->defs, |
(ep->defs, ep->defsz * |
ep->defsz, sizeof(struct eqn_def)); |
sizeof(struct eqn_def)); |
|
ep->defs[i].key = ep->defs[i].val = NULL; |
ep->defs[i].key = ep->defs[i].val = NULL; |
} |
} |
|
|
ep->defs[i].keysz = sz; |
ep->defs[i].keysz = sz; |
ep->defs[i].key = mandoc_realloc |
ep->defs[i].key = mandoc_realloc( |
(ep->defs[i].key, sz + 1); |
ep->defs[i].key, sz + 1); |
|
|
memcpy(ep->defs[i].key, start, sz); |
memcpy(ep->defs[i].key, start, sz); |
ep->defs[i].key[(int)sz] = '\0'; |
ep->defs[i].key[(int)sz] = '\0'; |
Line 898 eqn_do_gfont(struct eqn_node *ep) |
|
Line 899 eqn_do_gfont(struct eqn_node *ep) |
|
if (NULL == eqn_nextrawtok(ep, NULL)) { |
if (NULL == eqn_nextrawtok(ep, NULL)) { |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
EQN_MSG(MANDOCERR_EQNEOF, ep); |
return(0); |
return(0); |
} |
} |
return(1); |
return(1); |
} |
} |
|
|
Line 911 eqn_do_gsize(struct eqn_node *ep) |
|
Line 912 eqn_do_gsize(struct eqn_node *ep) |
|
if (NULL == (start = eqn_nextrawtok(ep, &sz))) { |
if (NULL == (start = eqn_nextrawtok(ep, &sz))) { |
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); |
} |
} |
Line 937 eqn_def_find(struct eqn_node *ep, const char *key, siz |
|
Line 938 eqn_def_find(struct eqn_node *ep, const char *key, siz |
|
{ |
{ |
int i; |
int i; |
|
|
for (i = 0; i < (int)ep->defsz; i++) |
for (i = 0; i < (int)ep->defsz; i++) |
if (ep->defs[i].keysz && STRNEQ(ep->defs[i].key, |
if (ep->defs[i].keysz && STRNEQ(ep->defs[i].key, |
ep->defs[i].keysz, key, sz)) |
ep->defs[i].keysz, key, sz)) |
return(&ep->defs[i]); |
return(&ep->defs[i]); |
|
|
return(NULL); |
return(NULL); |