=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc.c,v retrieving revision 1.102 retrieving revision 1.103 diff -c -r1.102 -r1.103 *** src/usr.bin/mandoc/mdoc.c 2014/03/30 19:47:32 1.102 --- src/usr.bin/mandoc/mdoc.c 2014/04/20 16:44:44 1.103 *************** *** 1,4 **** ! /* $Id: mdoc.c,v 1.102 2014/03/30 19:47:32 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze --- 1,4 ---- ! /* $Id: mdoc.c,v 1.103 2014/04/20 16:44:44 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze *************** *** 31,37 **** #include "libmdoc.h" #include "libmandoc.h" ! const char *const __mdoc_macronames[MDOC_MAX] = { "Ap", "Dd", "Dt", "Os", "Sh", "Ss", "Pp", "D1", "Dl", "Bd", "Ed", "Bl", --- 31,37 ---- #include "libmdoc.h" #include "libmandoc.h" ! const char *const __mdoc_macronames[MDOC_MAX] = { "Ap", "Dd", "Dt", "Os", "Sh", "Ss", "Pp", "D1", "Dl", "Bd", "Ed", "Bl", *************** *** 42,52 **** "Ic", "In", "Li", "Nd", "Nm", "Op", "Ot", "Pa", "Rv", "St", "Va", "Vt", - /* LINTED */ "Xr", "%A", "%B", "%D", - /* LINTED */ "%I", "%J", "%N", "%O", - /* LINTED */ "%P", "%R", "%T", "%V", "Ac", "Ao", "Aq", "At", "Bc", "Bf", "Bo", "Bq", --- 42,49 ---- *************** *** 63,84 **** "Bk", "Ek", "Bt", "Hf", "Fr", "Ud", "Lb", "Lp", "Lk", "Mt", "Brq", "Bro", - /* LINTED */ "Brc", "%C", "Es", "En", - /* LINTED */ "Dx", "%Q", "br", "sp", - /* LINTED */ "%U", "Ta", "ll", }; ! const char *const __mdoc_argnames[MDOC_ARG_MAX] = { "split", "nosplit", "ragged", ! "unfilled", "literal", "file", ! "offset", "bullet", "dash", ! "hyphen", "item", "enum", ! "tag", "diag", "hang", ! "ohang", "inset", "column", ! "width", "compact", "std", "filled", "words", "emphasis", "symbolic", "nested", "centered" }; --- 60,78 ---- "Bk", "Ek", "Bt", "Hf", "Fr", "Ud", "Lb", "Lp", "Lk", "Mt", "Brq", "Bro", "Brc", "%C", "Es", "En", "Dx", "%Q", "br", "sp", "%U", "Ta", "ll", }; ! const char *const __mdoc_argnames[MDOC_ARG_MAX] = { "split", "nosplit", "ragged", ! "unfilled", "literal", "file", ! "offset", "bullet", "dash", ! "hyphen", "item", "enum", ! "tag", "diag", "hang", ! "ohang", "inset", "column", ! "width", "compact", "std", "filled", "words", "emphasis", "symbolic", "nested", "centered" }; *************** *** 87,99 **** const char * const *mdoc_argnames = __mdoc_argnames; static void mdoc_node_free(struct mdoc_node *); ! static void mdoc_node_unlink(struct mdoc *, struct mdoc_node *); static void mdoc_free1(struct mdoc *); static void mdoc_alloc1(struct mdoc *); ! static struct mdoc_node *node_alloc(struct mdoc *, int, 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); --- 81,93 ---- const char * const *mdoc_argnames = __mdoc_argnames; static void mdoc_node_free(struct mdoc_node *); ! static void mdoc_node_unlink(struct mdoc *, struct mdoc_node *); static void mdoc_free1(struct mdoc *); static void mdoc_alloc1(struct mdoc *); ! static struct mdoc_node *node_alloc(struct mdoc *, int, 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); *************** *** 101,106 **** --- 95,101 ---- static int mdoc_ptext(struct mdoc *, int, char *, int); static int mdoc_pmacro(struct mdoc *, int, char *, int); + const struct mdoc_node * mdoc_node(const struct mdoc *mdoc) { *************** *** 109,115 **** return(mdoc->first); } - const struct mdoc_meta * mdoc_meta(const struct mdoc *mdoc) { --- 104,109 ---- *************** *** 118,124 **** return(&mdoc->meta); } - /* * Frees volatile resources (parse tree, meta-data, fields). */ --- 112,117 ---- *************** *** 144,150 **** free(mdoc->meta.date); } - /* * Allocate all volatile resources (parse tree, meta-data, fields). */ --- 137,142 ---- *************** *** 162,168 **** mdoc->next = MDOC_NEXT_CHILD; } - /* * Free up volatile resources (see mdoc_free1()) then re-initialises the * data with mdoc_alloc1(). After invocation, parse data has been reset --- 154,159 ---- *************** *** 177,183 **** mdoc_alloc1(mdoc); } - /* * Completely free up all volatile and non-volatile parse resources. * After invocation, the pointer is no longer usable. --- 168,173 ---- *************** *** 190,198 **** free(mdoc); } - /* ! * Allocate volatile and non-volatile parse resources. */ struct mdoc * mdoc_alloc(struct roff *roff, struct mparse *parse, --- 180,187 ---- free(mdoc); } /* ! * Allocate volatile and non-volatile parse resources. */ struct mdoc * mdoc_alloc(struct roff *roff, struct mparse *parse, *************** *** 212,218 **** return(p); } - /* * Climb back up the parse tree, validating open scopes. Mostly calls * through to macro_end() in macro.c. --- 201,206 ---- *************** *** 276,282 **** return(1); } - /* * Main parse routine. Parses a single line -- really just hands off to * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). --- 264,269 ---- *************** *** 301,308 **** mdoc->flags &= ~MDOC_SYNOPSIS; return(roff_getcontrol(mdoc->roff, buf, &offs) ? ! mdoc_pmacro(mdoc, ln, buf, offs) : ! mdoc_ptext(mdoc, ln, buf, offs)); } int --- 288,295 ---- mdoc->flags &= ~MDOC_SYNOPSIS; return(roff_getcontrol(mdoc->roff, buf, &offs) ? ! mdoc_pmacro(mdoc, ln, buf, offs) : ! mdoc_ptext(mdoc, ln, buf, offs)); } int *************** *** 312,327 **** /* If we're in the body, deny prologue calls. */ ! if (MDOC_PROLOGUE & mdoc_macros[tok].flags && ! MDOC_PBODY & mdoc->flags) { mdoc_pmsg(mdoc, line, ppos, MANDOCERR_BADBODY); return(1); } /* If we're in the prologue, deny "body" macros. */ ! if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && ! ! (MDOC_PBODY & mdoc->flags)) { mdoc_pmsg(mdoc, line, ppos, MANDOCERR_BADPROLOG); if (NULL == mdoc->meta.msec) mdoc->meta.msec = mandoc_strdup("1"); --- 299,314 ---- /* If we're in the body, deny prologue calls. */ ! if (MDOC_PROLOGUE & mdoc_macros[tok].flags && ! MDOC_PBODY & mdoc->flags) { mdoc_pmsg(mdoc, line, ppos, MANDOCERR_BADBODY); return(1); } /* If we're in the prologue, deny "body" macros. */ ! if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && ! ! (MDOC_PBODY & mdoc->flags)) { mdoc_pmsg(mdoc, line, ppos, MANDOCERR_BADPROLOG); if (NULL == mdoc->meta.msec) mdoc->meta.msec = mandoc_strdup("1"); *************** *** 350,361 **** assert(MDOC_ROOT != p->type); switch (mdoc->next) { ! case (MDOC_NEXT_SIBLING): mdoc->last->next = p; p->prev = mdoc->last; p->parent = mdoc->last->parent; break; ! case (MDOC_NEXT_CHILD): mdoc->last->child = p; p->parent = mdoc->last; break; --- 337,348 ---- assert(MDOC_ROOT != p->type); switch (mdoc->next) { ! case MDOC_NEXT_SIBLING: mdoc->last->next = p; p->prev = mdoc->last; p->parent = mdoc->last->parent; break; ! case MDOC_NEXT_CHILD: mdoc->last->child = p; p->parent = mdoc->last; break; *************** *** 372,384 **** */ switch (p->type) { ! case (MDOC_BODY): if (ENDBODY_NOT != p->end) break; /* FALLTHROUGH */ ! case (MDOC_TAIL): /* FALLTHROUGH */ ! case (MDOC_HEAD): p->norm = p->parent->norm; break; default: --- 359,371 ---- */ switch (p->type) { ! case MDOC_BODY: if (ENDBODY_NOT != p->end) break; /* FALLTHROUGH */ ! case MDOC_TAIL: /* FALLTHROUGH */ ! case MDOC_HEAD: p->norm = p->parent->norm; break; default: *************** *** 389,403 **** return(0); switch (p->type) { ! case (MDOC_HEAD): assert(MDOC_BLOCK == p->parent->type); p->parent->head = p; break; ! case (MDOC_TAIL): assert(MDOC_BLOCK == p->parent->type); p->parent->tail = p; break; ! case (MDOC_BODY): if (p->end) break; assert(MDOC_BLOCK == p->parent->type); --- 376,390 ---- return(0); switch (p->type) { ! case MDOC_HEAD: assert(MDOC_BLOCK == p->parent->type); p->parent->head = p; break; ! case MDOC_TAIL: assert(MDOC_BLOCK == p->parent->type); p->parent->tail = p; break; ! case MDOC_BODY: if (p->end) break; assert(MDOC_BLOCK == p->parent->type); *************** *** 410,418 **** mdoc->last = p; switch (p->type) { ! case (MDOC_TBL): /* FALLTHROUGH */ ! case (MDOC_TEXT): if ( ! mdoc_valid_post(mdoc)) return(0); break; --- 397,405 ---- mdoc->last = p; switch (p->type) { ! case MDOC_TBL: /* FALLTHROUGH */ ! case MDOC_TEXT: if ( ! mdoc_valid_post(mdoc)) return(0); break; *************** *** 423,431 **** return(1); } - static struct mdoc_node * ! node_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, enum mdoc_type type) { struct mdoc_node *p; --- 410,417 ---- return(1); } static struct mdoc_node * ! node_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, enum mdoc_type type) { struct mdoc_node *p; *************** *** 451,457 **** return(p); } - int mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) { --- 437,442 ---- *************** *** 464,470 **** return(1); } - int mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) { --- 449,454 ---- *************** *** 480,486 **** return(1); } - int mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) { --- 464,469 ---- *************** *** 493,499 **** return(1); } - int mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_node *body, enum mdoc_endbody end) --- 476,481 ---- *************** *** 510,518 **** return(1); } - int ! mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; --- 492,499 ---- return(1); } int ! mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; *************** *** 523,535 **** (args->refcnt)++; switch (tok) { ! case (MDOC_Bd): /* FALLTHROUGH */ ! case (MDOC_Bf): /* FALLTHROUGH */ ! case (MDOC_Bl): /* FALLTHROUGH */ ! case (MDOC_Rs): p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: --- 504,516 ---- (args->refcnt)++; switch (tok) { ! case MDOC_Bd: /* FALLTHROUGH */ ! case MDOC_Bf: /* FALLTHROUGH */ ! case MDOC_Bl: /* FALLTHROUGH */ ! case MDOC_Rs: p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: *************** *** 542,550 **** return(1); } - int ! mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; --- 523,530 ---- return(1); } int ! mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; *************** *** 555,561 **** (args->refcnt)++; switch (tok) { ! case (MDOC_An): p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: --- 535,541 ---- (args->refcnt)++; switch (tok) { ! case MDOC_An: p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: *************** *** 611,617 **** free(p); } - static void mdoc_node_unlink(struct mdoc *mdoc, struct mdoc_node *n) { --- 591,596 ---- *************** *** 649,655 **** mdoc->first = NULL; } - void mdoc_node_delete(struct mdoc *mdoc, struct mdoc_node *p) { --- 628,633 ---- *************** *** 720,726 **** if ( ! mdoc_addeqn(mdoc, roff_eqn(mdoc->roff))) return(0); offs += (end - (buf + offs)); ! } return(1); } --- 698,704 ---- if ( ! mdoc_addeqn(mdoc, roff_eqn(mdoc->roff))) return(0); offs += (end - (buf + offs)); ! } return(1); } *************** *** 754,769 **** */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && ! LIST_column == n->norm->Bl.type) { /* `Bl' is open without any children. */ mdoc->flags |= MDOC_FREECOL; return(mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf)); } if (MDOC_It == n->tok && MDOC_BLOCK == n->type && ! NULL != n->parent && ! MDOC_Bl == n->parent->tok && ! LIST_column == n->parent->norm->Bl.type) { /* `Bl' has block-level `It' children. */ mdoc->flags |= MDOC_FREECOL; return(mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf)); --- 732,747 ---- */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && ! LIST_column == n->norm->Bl.type) { /* `Bl' is open without any children. */ mdoc->flags |= MDOC_FREECOL; return(mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf)); } if (MDOC_It == n->tok && MDOC_BLOCK == n->type && ! NULL != n->parent && ! MDOC_Bl == n->parent->tok && ! LIST_column == n->parent->norm->Bl.type) { /* `Bl' has block-level `It' children. */ mdoc->flags |= MDOC_FREECOL; return(mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf)); *************** *** 849,855 **** return(1); } - /* * Parse a macro line, that is, a line beginning with the control * character. --- 827,832 ---- *************** *** 872,885 **** sv = offs; ! /* * Copy the first word into a nil-terminated buffer. * Stop copying when a tab, space, or eoln is encountered. */ i = 0; ! while (i < 4 && '\0' != buf[offs] && ! ' ' != buf[offs] && '\t' != buf[offs]) mac[i++] = buf[offs++]; mac[i] = '\0'; --- 849,862 ---- sv = offs; ! /* * Copy the first word into a nil-terminated buffer. * Stop copying when a tab, space, or eoln is encountered. */ i = 0; ! while (i < 4 && '\0' != buf[offs] && ' ' != buf[offs] && ! '\t' != buf[offs]) mac[i++] = buf[offs++]; mac[i] = '\0'; *************** *** 887,894 **** tok = (i > 1 || i < 4) ? mdoc_hash_find(mac) : MDOC_MAX; if (MDOC_MAX == tok) { ! mandoc_vmsg(MANDOCERR_MACRO, mdoc->parse, ! ln, sv, "%s", buf + sv - 1); return(1); } --- 864,871 ---- tok = (i > 1 || i < 4) ? mdoc_hash_find(mac) : MDOC_MAX; if (MDOC_MAX == tok) { ! mandoc_vmsg(MANDOCERR_MACRO, mdoc->parse, ! ln, sv, "%s", buf + sv - 1); return(1); } *************** *** 902,908 **** while (buf[offs] && ' ' == buf[offs]) offs++; ! /* * Trailing whitespace. Note that tabs are allowed to be passed * into the parser as "text", so we only warn about spaces here. */ --- 879,885 ---- while (buf[offs] && ' ' == buf[offs]) offs++; ! /* * Trailing whitespace. Note that tabs are allowed to be passed * into the parser as "text", so we only warn about spaces here. */ *************** *** 916,922 **** */ if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) { ! if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) goto err; return(1); } --- 893,899 ---- */ if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) { ! if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) goto err; return(1); } *************** *** 930,936 **** */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && ! LIST_column == n->norm->Bl.type) { mdoc->flags |= MDOC_FREECOL; if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)) goto err; --- 907,913 ---- */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && ! LIST_column == n->norm->Bl.type) { mdoc->flags |= MDOC_FREECOL; if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)) goto err; *************** *** 944,961 **** */ if (MDOC_It == n->tok && MDOC_BLOCK == n->type && ! NULL != n->parent && ! MDOC_Bl == n->parent->tok && ! LIST_column == n->parent->norm->Bl.type) { mdoc->flags |= MDOC_FREECOL; ! if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)) goto err; return(1); } /* Normal processing of a macro. */ ! if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) goto err; /* In quick mode (for mandocdb), abort after the NAME section. */ --- 921,938 ---- */ if (MDOC_It == n->tok && MDOC_BLOCK == n->type && ! NULL != n->parent && ! MDOC_Bl == n->parent->tok && ! LIST_column == n->parent->norm->Bl.type) { mdoc->flags |= MDOC_FREECOL; ! if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)) goto err; return(1); } /* Normal processing of a macro. */ ! if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) goto err; /* In quick mode (for mandocdb), abort after the NAME section. */ *************** *** 981,1007 **** if ('\0' == p[1]) switch (p[0]) { ! case('('): /* FALLTHROUGH */ ! case('['): return(DELIM_OPEN); ! case('|'): return(DELIM_MIDDLE); ! case('.'): /* FALLTHROUGH */ ! case(','): /* FALLTHROUGH */ ! case(';'): /* FALLTHROUGH */ ! case(':'): /* FALLTHROUGH */ ! case('?'): /* FALLTHROUGH */ ! case('!'): /* FALLTHROUGH */ ! case(')'): /* FALLTHROUGH */ ! case(']'): return(DELIM_CLOSE); default: return(DELIM_NONE); --- 958,984 ---- if ('\0' == p[1]) switch (p[0]) { ! case '(': /* FALLTHROUGH */ ! case '[': return(DELIM_OPEN); ! case '|': return(DELIM_MIDDLE); ! case '.': /* FALLTHROUGH */ ! case ',': /* FALLTHROUGH */ ! case ';': /* FALLTHROUGH */ ! case ':': /* FALLTHROUGH */ ! case '?': /* FALLTHROUGH */ ! case '!': /* FALLTHROUGH */ ! case ')': /* FALLTHROUGH */ ! case ']': return(DELIM_CLOSE); default: return(DELIM_NONE);