-/* $Id: eqn.c,v 1.50 2014/10/10 14:02:02 schwarze Exp $ */
+/* $Id: eqn.c,v 1.61 2016/01/08 00:50:45 schwarze Exp $ */
/*
- * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
#include "libmandoc.h"
#include "libroff.h"
-#define EQN_MSG(t, x) \
- mandoc_msg((t), (x)->parse, (x)->eqn.ln, (x)->eqn.pos, NULL)
#define EQN_NEST_MAX 128 /* maximum nesting of defines */
#define STRNEQ(p1, sz1, p2, sz2) \
((sz1) == (sz2) && 0 == strncmp((p1), (p2), (sz1)))
-#define EQNSTREQ(x, p, sz) \
- STRNEQ((x)->name, (x)->sz, (p), (sz))
enum eqn_tok {
EQN_TOK_DYAD = 0,
EQNSYM_equiv,
EQNSYM_lessequal,
EQNSYM_moreequal,
+ EQNSYM_minus,
EQNSYM__MAX
};
{ "cdot", "pc" }, /* EQNSYM_cdot */
{ "nothing", "&" }, /* EQNSYM_nothing */
{ "approx", "~~" }, /* EQNSYM_approx */
- { "prime", "aq" }, /* EQNSYM_prime */
+ { "prime", "fm" }, /* EQNSYM_prime */
{ "half", "12" }, /* EQNSYM_half */
{ "partial", "pd" }, /* EQNSYM_partial */
{ "inf", "if" }, /* EQNSYM_inf */
{ "==", "==" }, /* EQNSYM_equiv */
{ "<=", "<=" }, /* EQNSYM_lessequal */
{ ">=", ">=" }, /* EQNSYM_moreequal */
+ { "-", "mi" }, /* EQNSYM_minus */
};
+static struct eqn_box *eqn_box_alloc(struct eqn_node *, struct eqn_box *);
+static void eqn_box_free(struct eqn_box *);
+static struct eqn_box *eqn_box_makebinary(struct eqn_node *,
+ enum eqn_post, struct eqn_box *);
+static void eqn_def(struct eqn_node *);
+static struct eqn_def *eqn_def_find(struct eqn_node *, const char *, size_t);
+static void eqn_delim(struct eqn_node *);
+static const char *eqn_next(struct eqn_node *, char, size_t *, int);
+static const char *eqn_nextrawtok(struct eqn_node *, size_t *);
+static const char *eqn_nexttok(struct eqn_node *, size_t *);
+static enum rofferr eqn_parse(struct eqn_node *, struct eqn_box *);
+static enum eqn_tok eqn_tok_parse(struct eqn_node *, char **);
+static void eqn_undef(struct eqn_node *);
+
+
enum rofferr
eqn_read(struct eqn_node **epp, int ln,
const char *p, int pos, int *offs)
while (' ' == *p || '\t' == *p)
p++;
if ('\0' == *p)
- return(er);
+ return er;
mandoc_vmsg(MANDOCERR_ARG_SKIP, ep->parse,
ln, pos, "EN %s", p);
- return(er);
+ return er;
}
/*
ep->sz += sz;
strlcat(ep->data, p + pos, ep->sz + 1);
strlcat(ep->data, " ", ep->sz + 1);
- return(ROFF_IGN);
+ return ROFF_IGN;
}
struct eqn_node *
-eqn_alloc(const char *name, int pos, int line, struct mparse *parse)
+eqn_alloc(int pos, int line, struct mparse *parse)
{
struct eqn_node *p;
- size_t sz;
- const char *end;
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->eqn.ln = line;
p->eqn.pos = pos;
p->gsize = EQN_DEFSIZE;
- return(p);
+ return p;
}
/*
for (i = 0; i < (int)ep->defsz; i++)
if (ep->defs[i].keysz && STRNEQ(ep->defs[i].key,
ep->defs[i].keysz, key, sz))
- return(&ep->defs[i]);
+ return &ep->defs[i];
- return(NULL);
+ return NULL;
}
/*
/* Prevent self-definitions. */
if (lim >= EQN_NEST_MAX) {
- EQN_MSG(MANDOCERR_ROFFLOOP, ep);
- return(NULL);
+ mandoc_msg(MANDOCERR_ROFFLOOP, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, NULL);
+ return NULL;
}
ep->cur = ep->rew;
q = 0;
if ('\0' == *start)
- return(NULL);
+ return NULL;
if (quote == *start) {
ep->cur++;
ep->cur++;
} else {
if (q)
- EQN_MSG(MANDOCERR_ARG_QUOTE, ep);
+ mandoc_msg(MANDOCERR_ARG_QUOTE, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, NULL);
next = strchr(start, '\0');
*sz = (size_t)(next - start);
ep->cur += *sz;
/* Quotes aren't expanded for values. */
if (q || ! repl)
- return(start);
+ return start;
if (NULL != (def = eqn_def_find(ep, start, *sz))) {
diff = def->valsz - *sz;
memmove(start + *sz + diff, start + *sz,
(strlen(start) - *sz) + 1);
memcpy(start, def->val, def->valsz);
+ lim++;
goto again;
}
- return(start);
+ return start;
}
/*
eqn_nexttok(struct eqn_node *ep, size_t *sz)
{
- return(eqn_next(ep, '"', sz, 1));
+ return eqn_next(ep, '"', sz, 1);
}
/*
eqn_nextrawtok(struct eqn_node *ep, size_t *sz)
{
- return(eqn_next(ep, '"', sz, 0));
+ return eqn_next(ep, '"', sz, 0);
}
/*
{
const char *start;
size_t i, sz;
+ int quoted;
if (NULL != p)
*p = NULL;
+ quoted = ep->data[ep->cur] == '"';
+
if (NULL == (start = eqn_nexttok(ep, &sz)))
- return(EQN_TOK_EOF);
+ return EQN_TOK_EOF;
+
+ if (quoted) {
+ if (p != NULL)
+ *p = mandoc_strndup(start, sz);
+ return EQN_TOK__MAX;
+ }
for (i = 0; i < EQN_TOK__MAX; i++) {
if (NULL == eqn_toks[i])
if (i == EQN_TOK__MAX && NULL != p)
*p = mandoc_strndup(start, sz);
- return(i);
+ return i;
}
static void
parent->first = bp;
parent->last = bp;
- return(bp);
+ return bp;
}
/*
* The new EQN_SUBEXPR will have a two-child limit.
*/
static struct eqn_box *
-eqn_box_makebinary(struct eqn_node *ep,
+eqn_box_makebinary(struct eqn_node *ep,
enum eqn_post pos, struct eqn_box *parent)
{
struct eqn_box *b, *newb;
newb->first = newb->last = b;
newb->first->next = NULL;
b->parent = newb;
- return(newb);
+ return newb;
+}
+
+/*
+ * Parse the "delim" control statement.
+ */
+static void
+eqn_delim(struct eqn_node *ep)
+{
+ const char *start;
+ size_t sz;
+
+ if ((start = eqn_nextrawtok(ep, &sz)) == NULL)
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, "delim");
+ else if (strncmp(start, "off", 3) == 0)
+ ep->delim = 0;
+ else if (strncmp(start, "on", 2) == 0) {
+ if (ep->odelim && ep->cdelim)
+ ep->delim = 1;
+ } else if (start[1] != '\0') {
+ ep->odelim = start[0];
+ ep->cdelim = start[1];
+ ep->delim = 1;
+ }
}
/*
* Undefine a previously-defined string.
*/
-static int
+static void
eqn_undef(struct eqn_node *ep)
{
const char *start;
struct eqn_def *def;
size_t sz;
- if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
- EQN_MSG(MANDOCERR_EQNEOF, ep);
- return(0);
- } else if (NULL != (def = eqn_def_find(ep, start, sz)))
- def->keysz = 0;
-
- return(1);
+ if ((start = eqn_nextrawtok(ep, &sz)) == NULL) {
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, "undef");
+ return;
+ }
+ if ((def = eqn_def_find(ep, start, sz)) == NULL)
+ return;
+ free(def->key);
+ free(def->val);
+ def->key = def->val = NULL;
+ def->keysz = def->valsz = 0;
}
-static int
+static void
eqn_def(struct eqn_node *ep)
{
const char *start;
struct eqn_def *def;
int i;
- if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
- EQN_MSG(MANDOCERR_EQNEOF, ep);
- return(0);
+ if ((start = eqn_nextrawtok(ep, &sz)) == NULL) {
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, "define");
+ return;
}
/*
ep->defs[i].key = ep->defs[i].val = NULL;
}
- ep->defs[i].keysz = sz;
- ep->defs[i].key = mandoc_realloc(
- ep->defs[i].key, sz + 1);
-
- memcpy(ep->defs[i].key, start, sz);
- ep->defs[i].key[(int)sz] = '\0';
- def = &ep->defs[i];
+ def = ep->defs + i;
+ free(def->key);
+ def->key = mandoc_strndup(start, sz);
+ def->keysz = sz;
}
start = eqn_next(ep, ep->data[(int)ep->cur], &sz, 0);
-
- if (NULL == start) {
- EQN_MSG(MANDOCERR_EQNEOF, ep);
- return(-1);
+ if (start == NULL) {
+ mandoc_vmsg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, "define %s", def->key);
+ free(def->key);
+ free(def->val);
+ def->key = def->val = NULL;
+ def->keysz = def->valsz = 0;
+ return;
}
-
+ free(def->val);
+ def->val = mandoc_strndup(start, sz);
def->valsz = sz;
- def->val = mandoc_realloc(def->val, sz + 1);
- memcpy(def->val, start, sz);
- def->val[(int)sz] = '\0';
- return(1);
}
/*
* Recursively parse an eqn(7) expression.
*/
-static int
+static enum rofferr
eqn_parse(struct eqn_node *ep, struct eqn_box *parent)
{
- char *p;
- enum eqn_tok tok;
- enum eqn_post pos;
- struct eqn_box *cur;
- int rc, size;
- size_t i, sz;
char sym[64];
+ struct eqn_box *cur;
const char *start;
+ char *p;
+ size_t i, sz;
+ enum eqn_tok tok, subtok;
+ enum eqn_post pos;
+ int size;
- assert(NULL != parent);
-again:
-
- switch ((tok = eqn_tok_parse(ep, &p))) {
+ assert(parent != NULL);
+
+ /*
+ * Empty equation.
+ * Do not add it to the high-level syntax tree.
+ */
+
+ if (ep->data == NULL)
+ return ROFF_IGN;
+
+next_tok:
+ tok = eqn_tok_parse(ep, &p);
+
+this_tok:
+ switch (tok) {
case (EQN_TOK_UNDEF):
- if ((rc = eqn_undef(ep)) <= 0)
- return(rc);
+ eqn_undef(ep);
break;
case (EQN_TOK_NDEFINE):
case (EQN_TOK_DEFINE):
- if ((rc = eqn_def(ep)) <= 0)
- return(rc);
+ eqn_def(ep);
break;
case (EQN_TOK_TDEFINE):
- 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);
+ if (eqn_nextrawtok(ep, NULL) == NULL ||
+ eqn_next(ep, ep->data[(int)ep->cur], NULL, 0) == NULL)
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, "tdefine");
break;
case (EQN_TOK_DELIM):
+ eqn_delim(ep);
+ break;
case (EQN_TOK_GFONT):
- if (NULL == eqn_nextrawtok(ep, NULL)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ if (eqn_nextrawtok(ep, NULL) == NULL)
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
break;
case (EQN_TOK_MARK):
case (EQN_TOK_LINEUP):
case (EQN_TOK_HAT):
case (EQN_TOK_DOT):
case (EQN_TOK_DOTDOT):
- if (NULL == parent->last) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
+ if (parent->last == NULL) {
+ mandoc_msg(MANDOCERR_EQN_NOBOX, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ cur = eqn_box_alloc(ep, parent);
+ cur->type = EQN_TEXT;
+ cur->text = mandoc_strdup("");
}
- parent = eqn_box_makebinary
- (ep, EQNPOS_NONE, parent);
+ parent = eqn_box_makebinary(ep, EQNPOS_NONE, parent);
parent->type = EQN_LISTONE;
parent->expectargs = 1;
switch (tok) {
case (EQN_TOK_BACK):
case (EQN_TOK_DOWN):
case (EQN_TOK_UP):
- tok = eqn_tok_parse(ep, NULL);
- if (EQN_TOK__MAX != tok) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
+ subtok = eqn_tok_parse(ep, NULL);
+ if (subtok != EQN_TOK__MAX) {
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ tok = subtok;
+ goto this_tok;
}
break;
case (EQN_TOK_FAT):
case (EQN_TOK_ITALIC):
case (EQN_TOK_BOLD):
while (parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ parent = parent->parent;
/*
* These values apply to the next word or sequence of
* words; thus, we mark that we'll have a child with
case (EQN_TOK_GSIZE):
/* Accept two values: integral size and a single. */
if (NULL == (start = eqn_nexttok(ep, &sz))) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ break;
}
size = mandoc_strntoi(start, sz, 10);
if (-1 == size) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
+ mandoc_msg(MANDOCERR_IT_NONUM, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ break;
}
if (EQN_TOK_GSIZE == tok) {
ep->gsize = size;
* Repivot under a positional node, open a child scope
* and keep on reading.
*/
- if (NULL == parent->last) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
+ if (parent->last == NULL) {
+ mandoc_msg(MANDOCERR_EQN_NOBOX, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ cur = eqn_box_alloc(ep, parent);
+ cur->type = EQN_TEXT;
+ cur->text = mandoc_strdup("");
}
/* Handle the "subsup" and "fromto" positions. */
if (EQN_TOK_SUP == tok && parent->pos == EQNPOS_SUB) {
break;
case (EQN_TOK_SQRT):
while (parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
- /*
+ parent = parent->parent;
+ /*
* Accept a left-right-associative set of arguments just
* like sub and sup and friends but without rebalancing
* under a pivot.
* Close out anything that's currently open, then
* rebalance and continue reading.
*/
- if (NULL == parent->last) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
+ if (parent->last == NULL) {
+ mandoc_msg(MANDOCERR_EQN_NOBOX, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ cur = eqn_box_alloc(ep, parent);
+ cur->type = EQN_TEXT;
+ cur->text = mandoc_strdup("");
}
while (EQN_SUBEXPR == parent->type)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ parent = parent->parent;
parent = eqn_box_makebinary(ep, EQNPOS_OVER, parent);
break;
case (EQN_TOK_RIGHT):
* FIXME: this is a shitty sentinel: we should really
* have a native EQN_BRACE type or whatnot.
*/
- while (parent->type != EQN_LIST)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ for (cur = parent; cur != NULL; cur = cur->parent)
+ if (cur->type == EQN_LIST &&
+ (tok == EQN_TOK_BRACE_CLOSE ||
+ cur->left != NULL))
+ break;
+ if (cur == NULL) {
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ break;
+ }
+ parent = cur;
if (EQN_TOK_RIGHT == tok) {
- if (NULL == parent->left) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
if (NULL == (start = eqn_nexttok(ep, &sz))) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
+ mandoc_msg(MANDOCERR_REQ_EMPTY,
+ ep->parse, ep->eqn.ln,
+ ep->eqn.pos, eqn_toks[tok]);
+ break;
}
/* Handling depends on right/left. */
if (STRNEQ(start, sz, "ceiling", 7)) {
} else if (STRNEQ(start, sz, "floor", 5)) {
strlcpy(sym, "\\[rf]", sizeof(sym));
parent->right = mandoc_strdup(sym);
- } else
+ } else
parent->right = mandoc_strndup(start, sz);
}
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
- if (EQN_TOK_BRACE_CLOSE == tok && parent &&
- (parent->type == EQN_PILE ||
- parent->type == EQN_MATRIX))
+ parent = parent->parent;
+ if (tok == EQN_TOK_BRACE_CLOSE &&
+ (parent->type == EQN_PILE ||
+ parent->type == EQN_MATRIX))
parent = parent->parent;
/* Close out any "singleton" lists. */
- while (parent->type == EQN_LISTONE &&
- parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ while (parent->type == EQN_LISTONE &&
+ parent->args == parent->expectargs)
+ parent = parent->parent;
break;
case (EQN_TOK_BRACE_OPEN):
case (EQN_TOK_LEFT):
* (just like with the text node).
*/
while (parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ parent = parent->parent;
+ if (EQN_TOK_LEFT == tok &&
+ (start = eqn_nexttok(ep, &sz)) == NULL) {
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ break;
+ }
parent = eqn_box_alloc(ep, parent);
parent->type = EQN_LIST;
if (EQN_TOK_LEFT == tok) {
- if (NULL == (start = eqn_nexttok(ep, &sz))) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
- /* Handling depends on right/left. */
if (STRNEQ(start, sz, "ceiling", 7)) {
strlcpy(sym, "\\[lc]", sizeof(sym));
parent->left = mandoc_strdup(sym);
} else if (STRNEQ(start, sz, "floor", 5)) {
strlcpy(sym, "\\[lf]", sizeof(sym));
parent->left = mandoc_strdup(sym);
- } else
+ } else
parent->left = mandoc_strndup(start, sz);
}
break;
case (EQN_TOK_LCOL):
case (EQN_TOK_RCOL):
while (parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
- if (EQN_TOK_BRACE_OPEN != eqn_tok_parse(ep, NULL)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ parent = parent->parent;
parent = eqn_box_alloc(ep, parent);
parent->type = EQN_PILE;
- parent = eqn_box_alloc(ep, parent);
- parent->type = EQN_LIST;
+ parent->expectargs = 1;
break;
case (EQN_TOK_ABOVE):
- while (parent->type != EQN_PILE)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
- parent = eqn_box_alloc(ep, parent);
+ for (cur = parent; cur != NULL; cur = cur->parent)
+ if (cur->type == EQN_PILE)
+ break;
+ if (cur == NULL) {
+ mandoc_msg(MANDOCERR_IT_STRAY, ep->parse,
+ ep->eqn.ln, ep->eqn.pos, eqn_toks[tok]);
+ break;
+ }
+ parent = eqn_box_alloc(ep, cur);
parent->type = EQN_LIST;
break;
case (EQN_TOK_MATRIX):
while (parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
- if (EQN_TOK_BRACE_OPEN != eqn_tok_parse(ep, NULL)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ parent = parent->parent;
parent = eqn_box_alloc(ep, parent);
parent->type = EQN_MATRIX;
- parent = eqn_box_alloc(ep, parent);
- parent->type = EQN_LIST;
+ parent->expectargs = 1;
break;
case (EQN_TOK_EOF):
/*
- * End of file!
+ * End of file!
* TODO: make sure we're not in an open subexpression.
*/
- return(0);
+ return ROFF_EQN;
default:
assert(tok == EQN_TOK__MAX);
assert(NULL != p);
* in an expression, then rewind til we're not any more.
*/
while (parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- free(p);
- return(-1);
- }
+ parent = parent->parent;
cur = eqn_box_alloc(ep, parent);
cur->type = EQN_TEXT;
for (i = 0; i < EQNSYM__MAX; i++)
if (0 == strcmp(eqnsyms[i].str, p)) {
- (void)snprintf(sym, sizeof(sym),
+ (void)snprintf(sym, sizeof(sym),
"\\[%s]", eqnsyms[i].sym);
cur->text = mandoc_strdup(sym);
free(p);
/*
* Post-process list status.
*/
- while (parent->type == EQN_LISTONE &&
- parent->args == parent->expectargs)
- if (NULL == (parent = parent->parent)) {
- EQN_MSG(MANDOCERR_EQNSYNT, ep);
- return(-1);
- }
+ while (parent->type == EQN_LISTONE &&
+ parent->args == parent->expectargs)
+ parent = parent->parent;
break;
}
- goto again;
+ goto next_tok;
}
enum rofferr
-eqn_end(struct eqn_node **epp)
+eqn_end(struct eqn_node **epp)
{
struct eqn_node *ep;
ep->eqn.root = mandoc_calloc(1, sizeof(struct eqn_box));
ep->eqn.root->expectargs = UINT_MAX;
- return(0 == eqn_parse(ep, ep->eqn.root) ? ROFF_EQN : ROFF_IGN);
+ return eqn_parse(ep, ep->eqn.root);
}
void
free(p->defs[i].val);
}
- free(p->eqn.name);
free(p->data);
free(p->defs);
free(p);