=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.189 retrieving revision 1.199 diff -u -p -r1.189 -r1.199 --- mandoc/mdoc.c 2011/07/18 07:46:41 1.189 +++ mandoc/mdoc.c 2012/07/16 09:51:54 1.199 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.189 2011/07/18 07:46:41 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.199 2012/07/16 09:51:54 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -97,6 +97,9 @@ static struct mdoc_node *node_alloc(struct mdoc *, int 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); @@ -157,6 +160,7 @@ mdoc_alloc1(struct mdoc *mdoc) mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node)); mdoc->first = mdoc->last; mdoc->last->type = MDOC_ROOT; + mdoc->last->tok = MDOC_MAX; mdoc->next = MDOC_NEXT_CHILD; } @@ -193,13 +197,14 @@ mdoc_free(struct mdoc *mdoc) * Allocate volatile and non-volatile parse resources. */ struct mdoc * -mdoc_alloc(struct roff *roff, struct mparse *parse) +mdoc_alloc(struct roff *roff, struct mparse *parse, char *defos) { struct mdoc *p; p = mandoc_calloc(1, sizeof(struct mdoc)); p->parse = parse; + p->defos = defos; p->roff = roff; mdoc_hash_init(); @@ -233,11 +238,11 @@ mdoc_addeqn(struct mdoc *m, const struct eqn *ep) /* No text before an initial macro. */ if (SEC_NONE == m->lastnamed) { - mdoc_pmsg(m, ep->line, ep->pos, MANDOCERR_NOTEXT); + mdoc_pmsg(m, ep->ln, ep->pos, MANDOCERR_NOTEXT); return(1); } - n = node_alloc(m, ep->line, ep->pos, MDOC_MAX, MDOC_EQN); + n = node_alloc(m, ep->ln, ep->pos, MDOC_MAX, MDOC_EQN); n->eqn = ep; if ( ! node_append(m, n)) @@ -297,7 +302,7 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int of m->flags &= ~MDOC_SYNOPSIS; } - return(mandoc_getcontrol(buf, &offs) ? + return(roff_getcontrol(m->roff, buf, &offs) ? mdoc_pmacro(m, ln, buf, offs) : mdoc_ptext(m, ln, buf, offs)); } @@ -565,17 +570,10 @@ int mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p) { struct mdoc_node *n; - size_t sv, len; - len = strlen(p); - n = node_alloc(m, line, pos, MDOC_MAX, MDOC_TEXT); - n->string = mandoc_malloc(len + 1); - sv = strlcpy(n->string, p, len + 1); + n->string = roff_strdup(m->roff, p); - /* Prohibit truncation. */ - assert(sv < len + 1); - if ( ! node_append(m, n)) return(0); @@ -650,7 +648,60 @@ mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) 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 * control character. @@ -703,11 +754,6 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int of ws = NULL; for (c = end = buf + offs; *c; c++) { switch (*c) { - case '-': - if (mandoc_hyph(buf + offs, c)) - *c = ASCII_HYPH; - ws = NULL; - break; case ' ': if (NULL == ws) ws = c; @@ -755,7 +801,8 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int of return(0); m->next = MDOC_NEXT_SIBLING; - return(1); + + return(mdoc_valid_post(m)); } if ( ! mdoc_word_alloc(m, line, offs, buf+offs))