=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc.c,v retrieving revision 1.83 retrieving revision 1.84 diff -c -r1.83 -r1.84 *** src/usr.bin/mandoc/mdoc.c 2011/04/24 16:22:02 1.83 --- src/usr.bin/mandoc/mdoc.c 2011/09/18 10:25:28 1.84 *************** *** 1,4 **** ! /* $Id: mdoc.c,v 1.83 2011/04/24 16:22:02 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze --- 1,4 ---- ! /* $Id: mdoc.c,v 1.84 2011/09/18 10:25:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze *************** *** 93,98 **** --- 93,101 ---- enum mdoct, enum mdoc_type); static int node_append(struct mdoc *, struct mdoc_node *); + #if 0 + static int mdoc_preptext(struct mdoc *, int, char *, int); + #endif static int mdoc_ptext(struct mdoc *, int, char *, int); static int mdoc_pmacro(struct mdoc *, int, char *, int); *************** *** 189,202 **** * Allocate volatile and non-volatile parse resources. */ struct mdoc * ! mdoc_alloc(struct regset *regs, struct mparse *parse) { struct mdoc *p; p = mandoc_calloc(1, sizeof(struct mdoc)); p->parse = parse; ! p->regs = regs; mdoc_hash_init(); mdoc_alloc1(p); --- 192,205 ---- * Allocate volatile and non-volatile parse resources. */ struct mdoc * ! mdoc_alloc(struct roff *roff, struct mparse *parse) { struct mdoc *p; p = mandoc_calloc(1, sizeof(struct mdoc)); p->parse = parse; ! p->roff = roff; mdoc_hash_init(); mdoc_alloc1(p); *************** *** 229,239 **** /* No text before an initial macro. */ if (SEC_NONE == m->lastnamed) { ! mdoc_pmsg(m, ep->line, ep->pos, MANDOCERR_NOTEXT); return(1); } ! n = node_alloc(m, ep->line, ep->pos, MDOC_MAX, MDOC_EQN); n->eqn = ep; if ( ! node_append(m, n)) --- 232,242 ---- /* No text before an initial macro. */ if (SEC_NONE == m->lastnamed) { ! mdoc_pmsg(m, ep->ln, ep->pos, MANDOCERR_NOTEXT); return(1); } ! n = node_alloc(m, ep->ln, ep->pos, MDOC_MAX, MDOC_EQN); n->eqn = ep; if ( ! node_append(m, n)) *************** *** 286,293 **** * whether this mode is on or off. * Note that this mode is also switched by the Sh macro. */ ! if (m->regs->regs[(int)REG_nS].set) { ! if (m->regs->regs[(int)REG_nS].v.u) m->flags |= MDOC_SYNOPSIS; else m->flags &= ~MDOC_SYNOPSIS; --- 289,296 ---- * whether this mode is on or off. * Note that this mode is also switched by the Sh macro. */ ! if (roff_regisset(m->roff, REG_nS)) { ! if (roff_regget(m->roff, REG_nS)) m->flags |= MDOC_SYNOPSIS; else m->flags &= ~MDOC_SYNOPSIS; *************** *** 646,651 **** --- 649,707 ---- mdoc_node_free(p); } + #if 0 + /* + * Pre-treat a text line. + * Text lines can consist of equations, which must be handled apart from + * the regular text. + * Thus, use this function to step through a line checking if it has any + * equations embedded in it. + * This must handle multiple equations AND equations that do not end at + * the end-of-line, i.e., will re-enter in the next roff parse. + */ + static int + mdoc_preptext(struct mdoc *m, int line, char *buf, int offs) + { + char *start, *end; + char delim; + + while ('\0' != buf[offs]) { + /* Mark starting position if eqn is set. */ + start = NULL; + if ('\0' != (delim = roff_eqndelim(m->roff))) + if (NULL != (start = strchr(buf + offs, delim))) + *start++ = '\0'; + + /* Parse text as normal. */ + if ( ! mdoc_ptext(m, line, buf, offs)) + return(0); + + /* Continue only if an equation exists. */ + if (NULL == start) + break; + + /* Read past the end of the equation. */ + offs += start - (buf + offs); + assert(start == &buf[offs]); + if (NULL != (end = strchr(buf + offs, delim))) { + *end++ = '\0'; + while (' ' == *end) + end++; + } + + /* Parse the equation itself. */ + roff_openeqn(m->roff, NULL, line, offs, buf); + + /* Process a finished equation? */ + if (roff_closeeqn(m->roff)) + if ( ! mdoc_addeqn(m, roff_eqn(m->roff))) + return(0); + offs += (end - (buf + offs)); + } + + return(1); + } + #endif /* * Parse free-form text, that is, a line that does not begin with the