version 1.189, 2011/07/18 07:46:41 |
version 1.192, 2011/07/27 07:09:41 |
Line 97 static struct mdoc_node *node_alloc(struct mdoc *, int |
|
Line 97 static struct mdoc_node *node_alloc(struct mdoc *, int |
|
enum mdoct, enum mdoc_type); |
enum mdoct, enum mdoc_type); |
static int node_append(struct mdoc *, |
static int node_append(struct mdoc *, |
struct mdoc_node *); |
struct mdoc_node *); |
|
static int mdoc_preptext(struct mdoc *, int, char *, int); |
static int mdoc_ptext(struct mdoc *, int, char *, int); |
static int mdoc_ptext(struct mdoc *, int, char *, int); |
static int mdoc_pmacro(struct mdoc *, int, char *, int); |
static int mdoc_pmacro(struct mdoc *, int, char *, int); |
|
|
Line 233 mdoc_addeqn(struct mdoc *m, const struct eqn *ep) |
|
Line 234 mdoc_addeqn(struct mdoc *m, const struct eqn *ep) |
|
/* No text before an initial macro. */ |
/* No text before an initial macro. */ |
|
|
if (SEC_NONE == m->lastnamed) { |
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); |
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; |
n->eqn = ep; |
|
|
if ( ! node_append(m, n)) |
if ( ! node_append(m, n)) |
Line 299 mdoc_parseln(struct mdoc *m, int ln, char *buf, int of |
|
Line 300 mdoc_parseln(struct mdoc *m, int ln, char *buf, int of |
|
|
|
return(mandoc_getcontrol(buf, &offs) ? |
return(mandoc_getcontrol(buf, &offs) ? |
mdoc_pmacro(m, ln, buf, offs) : |
mdoc_pmacro(m, ln, buf, offs) : |
mdoc_ptext(m, ln, buf, offs)); |
mdoc_preptext(m, ln, buf, offs)); |
} |
} |
|
|
int |
int |
Line 650 mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) |
|
Line 651 mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) |
|
mdoc_node_free(p); |
mdoc_node_free(p); |
} |
} |
|
|
|
/* |
|
* 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); |
|
} |
|
|
/* |
/* |
* Parse free-form text, that is, a line that does not begin with the |
* Parse free-form text, that is, a line that does not begin with the |
* control character. |
* control character. |
Line 703 mdoc_ptext(struct mdoc *m, int line, char *buf, int of |
|
Line 755 mdoc_ptext(struct mdoc *m, int line, char *buf, int of |
|
ws = NULL; |
ws = NULL; |
for (c = end = buf + offs; *c; c++) { |
for (c = end = buf + offs; *c; c++) { |
switch (*c) { |
switch (*c) { |
case '-': |
|
if (mandoc_hyph(buf + offs, c)) |
|
*c = ASCII_HYPH; |
|
ws = NULL; |
|
break; |
|
case ' ': |
case ' ': |
if (NULL == ws) |
if (NULL == ws) |
ws = c; |
ws = c; |