=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.191 retrieving revision 1.201 diff -u -p -r1.191 -r1.201 --- mandoc/mdoc.c 2011/07/25 15:37:00 1.191 +++ mandoc/mdoc.c 2012/07/18 11:11:12 1.201 @@ -1,7 +1,7 @@ -/* $Id: mdoc.c,v 1.191 2011/07/25 15:37:00 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.201 2012/07/18 11:11:12 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010 Ingo Schwarze + * Copyright (c) 2010, 2012 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 @@ -97,7 +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); @@ -158,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; } @@ -194,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(); @@ -298,9 +302,9 @@ 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_preptext(m, ln, buf, offs)); + mdoc_ptext(m, ln, buf, offs)); } int @@ -566,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); @@ -651,6 +648,15 @@ mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) mdoc_node_free(p); } +int +mdoc_node_relink(struct mdoc *m, struct mdoc_node *p) +{ + + mdoc_node_unlink(m, p); + return(node_append(m, p)); +} + +#if 0 /* * Pre-treat a text line. * Text lines can consist of equations, which must be handled apart from @@ -702,6 +708,7 @@ mdoc_preptext(struct mdoc *m, int line, char *buf, int return(1); } +#endif /* * Parse free-form text, that is, a line that does not begin with the @@ -755,11 +762,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; @@ -807,7 +809,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)) @@ -987,7 +990,7 @@ mdoc_isdelim(const char *p) if (0 == strcmp(p + 1, ".")) return(DELIM_CLOSE); - if (0 == strcmp(p + 1, "*(Ba")) + if (0 == strcmp(p + 1, "fR|\\fP")) return(DELIM_MIDDLE); return(DELIM_NONE);