=================================================================== RCS file: /cvs/mandoc/eqn.c,v retrieving revision 1.52 retrieving revision 1.55 diff -u -p -r1.52 -r1.55 --- mandoc/eqn.c 2014/10/12 19:31:41 1.52 +++ mandoc/eqn.c 2014/10/25 14:35:37 1.55 @@ -1,6 +1,7 @@ -/* $Id: eqn.c,v 1.52 2014/10/12 19:31:41 schwarze Exp $ */ +/* $Id: eqn.c,v 1.55 2014/10/25 14:35:37 schwarze Exp $ */ /* * Copyright (c) 2011, 2014 Kristaps Dzonsons + * Copyright (c) 2014 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -35,8 +36,6 @@ #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, @@ -314,24 +313,12 @@ eqn_read(struct eqn_node **epp, int ln, } 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; @@ -486,13 +473,22 @@ eqn_tok_parse(struct eqn_node *ep, char **p) { 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); + 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]) continue; @@ -578,6 +574,30 @@ eqn_box_makebinary(struct eqn_node *ep, } /* + * 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 @@ -688,6 +708,8 @@ this_tok: EQN_MSG(MANDOCERR_EQNEOF, ep); break; case (EQN_TOK_DELIM): + eqn_delim(ep); + break; case (EQN_TOK_GFONT): if (eqn_nextrawtok(ep, NULL) == NULL) mandoc_msg(MANDOCERR_REQ_EMPTY, ep->parse, @@ -1072,7 +1094,6 @@ eqn_free(struct eqn_node *p) free(p->defs[i].val); } - free(p->eqn.name); free(p->data); free(p->defs); free(p);