=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc.c,v retrieving revision 1.102 retrieving revision 1.103 diff -u -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 +1,4 @@ -/* $Id: mdoc.c,v 1.102 2014/03/30 19:47:32 schwarze Exp $ */ +/* $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,7 +31,7 @@ #include "libmdoc.h" #include "libmandoc.h" -const char *const __mdoc_macronames[MDOC_MAX] = { +const char *const __mdoc_macronames[MDOC_MAX] = { "Ap", "Dd", "Dt", "Os", "Sh", "Ss", "Pp", "D1", "Dl", "Bd", "Ed", "Bl", @@ -42,11 +42,8 @@ "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", @@ -63,22 +60,19 @@ "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] = { +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", + "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,13 +81,13 @@ const char * const *mdoc_argnames = __mdoc_argnames; static void mdoc_node_free(struct mdoc_node *); -static void mdoc_node_unlink(struct mdoc *, +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, +static struct mdoc_node *node_alloc(struct mdoc *, int, int, enum mdoct, enum mdoc_type); -static int node_append(struct mdoc *, +static int node_append(struct mdoc *, struct mdoc_node *); #if 0 static int mdoc_preptext(struct mdoc *, int, char *, int); @@ -101,6 +95,7 @@ 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,7 +104,6 @@ return(mdoc->first); } - const struct mdoc_meta * mdoc_meta(const struct mdoc *mdoc) { @@ -118,7 +112,6 @@ return(&mdoc->meta); } - /* * Frees volatile resources (parse tree, meta-data, fields). */ @@ -144,7 +137,6 @@ free(mdoc->meta.date); } - /* * Allocate all volatile resources (parse tree, meta-data, fields). */ @@ -162,7 +154,6 @@ 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 @@ -177,7 +168,6 @@ mdoc_alloc1(mdoc); } - /* * Completely free up all volatile and non-volatile parse resources. * After invocation, the pointer is no longer usable. @@ -190,9 +180,8 @@ free(mdoc); } - /* - * Allocate volatile and non-volatile parse resources. + * Allocate volatile and non-volatile parse resources. */ struct mdoc * mdoc_alloc(struct roff *roff, struct mparse *parse, @@ -212,7 +201,6 @@ return(p); } - /* * Climb back up the parse tree, validating open scopes. Mostly calls * through to macro_end() in macro.c. @@ -276,7 +264,6 @@ return(1); } - /* * Main parse routine. Parses a single line -- really just hands off to * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). @@ -301,8 +288,8 @@ mdoc->flags &= ~MDOC_SYNOPSIS; return(roff_getcontrol(mdoc->roff, buf, &offs) ? - mdoc_pmacro(mdoc, ln, buf, offs) : - mdoc_ptext(mdoc, ln, buf, offs)); + mdoc_pmacro(mdoc, ln, buf, offs) : + mdoc_ptext(mdoc, ln, buf, offs)); } int @@ -312,16 +299,16 @@ /* If we're in the body, deny prologue calls. */ - if (MDOC_PROLOGUE & mdoc_macros[tok].flags && - MDOC_PBODY & mdoc->flags) { + 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)) { + 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,12 +337,12 @@ assert(MDOC_ROOT != p->type); switch (mdoc->next) { - case (MDOC_NEXT_SIBLING): + case MDOC_NEXT_SIBLING: mdoc->last->next = p; p->prev = mdoc->last; p->parent = mdoc->last->parent; break; - case (MDOC_NEXT_CHILD): + case MDOC_NEXT_CHILD: mdoc->last->child = p; p->parent = mdoc->last; break; @@ -372,13 +359,13 @@ */ switch (p->type) { - case (MDOC_BODY): + case MDOC_BODY: if (ENDBODY_NOT != p->end) break; /* FALLTHROUGH */ - case (MDOC_TAIL): + case MDOC_TAIL: /* FALLTHROUGH */ - case (MDOC_HEAD): + case MDOC_HEAD: p->norm = p->parent->norm; break; default: @@ -389,15 +376,15 @@ return(0); switch (p->type) { - case (MDOC_HEAD): + case MDOC_HEAD: assert(MDOC_BLOCK == p->parent->type); p->parent->head = p; break; - case (MDOC_TAIL): + case MDOC_TAIL: assert(MDOC_BLOCK == p->parent->type); p->parent->tail = p; break; - case (MDOC_BODY): + case MDOC_BODY: if (p->end) break; assert(MDOC_BLOCK == p->parent->type); @@ -410,9 +397,9 @@ mdoc->last = p; switch (p->type) { - case (MDOC_TBL): + case MDOC_TBL: /* FALLTHROUGH */ - case (MDOC_TEXT): + case MDOC_TEXT: if ( ! mdoc_valid_post(mdoc)) return(0); break; @@ -423,9 +410,8 @@ return(1); } - static struct mdoc_node * -node_alloc(struct mdoc *mdoc, int line, int pos, +node_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, enum mdoc_type type) { struct mdoc_node *p; @@ -451,7 +437,6 @@ return(p); } - int mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) { @@ -464,7 +449,6 @@ return(1); } - int mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) { @@ -480,7 +464,6 @@ return(1); } - int mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok) { @@ -493,7 +476,6 @@ return(1); } - int mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_node *body, enum mdoc_endbody end) @@ -510,9 +492,8 @@ return(1); } - int -mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, +mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; @@ -523,13 +504,13 @@ (args->refcnt)++; switch (tok) { - case (MDOC_Bd): + case MDOC_Bd: /* FALLTHROUGH */ - case (MDOC_Bf): + case MDOC_Bf: /* FALLTHROUGH */ - case (MDOC_Bl): + case MDOC_Bl: /* FALLTHROUGH */ - case (MDOC_Rs): + case MDOC_Rs: p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: @@ -542,9 +523,8 @@ return(1); } - int -mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, +mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; @@ -555,7 +535,7 @@ (args->refcnt)++; switch (tok) { - case (MDOC_An): + case MDOC_An: p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: @@ -611,7 +591,6 @@ free(p); } - static void mdoc_node_unlink(struct mdoc *mdoc, struct mdoc_node *n) { @@ -649,7 +628,6 @@ mdoc->first = NULL; } - void mdoc_node_delete(struct mdoc *mdoc, struct mdoc_node *p) { @@ -720,7 +698,7 @@ if ( ! mdoc_addeqn(mdoc, roff_eqn(mdoc->roff))) return(0); offs += (end - (buf + offs)); - } + } return(1); } @@ -754,16 +732,16 @@ */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && - LIST_column == n->norm->Bl.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) { + 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,7 +827,6 @@ return(1); } - /* * Parse a macro line, that is, a line beginning with the control * character. @@ -872,14 +849,14 @@ 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]) + while (i < 4 && '\0' != buf[offs] && ' ' != buf[offs] && + '\t' != buf[offs]) mac[i++] = buf[offs++]; mac[i] = '\0'; @@ -887,8 +864,8 @@ 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); + mandoc_vmsg(MANDOCERR_MACRO, mdoc->parse, + ln, sv, "%s", buf + sv - 1); return(1); } @@ -902,7 +879,7 @@ 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,7 +893,7 @@ */ if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) { - if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) + if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) goto err; return(1); } @@ -930,7 +907,7 @@ */ if (MDOC_Bl == n->tok && MDOC_BODY == n->type && - LIST_column == n->norm->Bl.type) { + LIST_column == n->norm->Bl.type) { mdoc->flags |= MDOC_FREECOL; if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf)) goto err; @@ -944,18 +921,18 @@ */ if (MDOC_It == n->tok && MDOC_BLOCK == n->type && - NULL != n->parent && - MDOC_Bl == n->parent->tok && - LIST_column == n->parent->norm->Bl.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)) + 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)) + if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) goto err; /* In quick mode (for mandocdb), abort after the NAME section. */ @@ -981,27 +958,27 @@ if ('\0' == p[1]) switch (p[0]) { - case('('): + case '(': /* FALLTHROUGH */ - case('['): + case '[': return(DELIM_OPEN); - case('|'): + case '|': return(DELIM_MIDDLE); - case('.'): + case '.': /* FALLTHROUGH */ - case(','): + case ',': /* FALLTHROUGH */ - case(';'): + case ';': /* FALLTHROUGH */ - case(':'): + case ':': /* FALLTHROUGH */ - case('?'): + case '?': /* FALLTHROUGH */ - case('!'): + case '!': /* FALLTHROUGH */ - case(')'): + case ')': /* FALLTHROUGH */ - case(']'): + case ']': return(DELIM_CLOSE); default: return(DELIM_NONE);