=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.49 retrieving revision 1.52 diff -u -p -r1.49 -r1.52 --- mandoc/mdoc.c 2009/03/01 23:14:15 1.49 +++ mandoc/mdoc.c 2009/03/06 14:13:47 1.52 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.49 2009/03/01 23:14:15 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.52 2009/03/06 14:13:47 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -74,7 +74,7 @@ const char *const __mdoc_macronames[MDOC_MAX] = { "Tn", "Ux", "Xc", "Xo", "Fo", "Fc", "Oo", "Oc", "Bk", "Ek", "Bt", "Hf", - "Fr", "Ud", + "Fr", "Ud", "Lb", }; const char *const __mdoc_argnames[MDOC_ARG_MAX] = { @@ -85,20 +85,8 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = { "tag", "diag", "hang", "ohang", "inset", "column", "width", "compact", "std", - "p1003.1-88", "p1003.1-90", "p1003.1-96", - "p1003.1-2001", "p1003.1-2004", "p1003.1", - "p1003.1b", "p1003.1b-93", "p1003.1c-95", - "p1003.1g-2000", "p1003.2-92", "p1387.2-95", - "p1003.2", "p1387.2", "isoC-90", - "isoC-amd1", "isoC-tcor1", "isoC-tcor2", - "isoC-99", "ansiC", "ansiC-89", - "ansiC-99", "ieee754", "iso8802-3", - "xpg3", "xpg4", "xpg4.2", - "xpg4.3", "xbd5", "xcu5", - "xsh5", "xns5", "xns5.2d2.0", - "xcurses4.2", "susv2", "susv3", - "svid4", "filled", "words", - "emphasis", "symbolic", + "filled", "words", "emphasis", + "symbolic" }; const char * const *mdoc_macronames = __mdoc_macronames; @@ -135,6 +123,10 @@ mdoc_free(struct mdoc *mdoc) free(mdoc->meta.os); if (mdoc->meta.name) free(mdoc->meta.name); + if (mdoc->meta.arch) + free(mdoc->meta.arch); + if (mdoc->meta.vol) + free(mdoc->meta.vol); free(mdoc); } @@ -180,6 +172,12 @@ mdoc_endparse(struct mdoc *mdoc) } +/* + * Main line-parsing routine. If the line is a macro-line (started with + * a '.' control character), then pass along to the parser, which parses + * subsequent macros until the end of line. If normal text, simply + * append the entire line to the chain. + */ int mdoc_parseln(struct mdoc *mdoc, int line, char *buf) { @@ -191,26 +189,31 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf) mdoc->linetok = 0; - /* - * FIXME: should puke on whitespace in non-literal displays. - */ - if ('.' != *buf) { + /* + * Free-form text. Not allowed in the prologue. + */ if (SEC_PROLOGUE == mdoc->lastnamed) return(mdoc_perr(mdoc, line, 0, - "no text in document prologue")); + "no text in prologue")); + if ( ! mdoc_word_alloc(mdoc, line, 0, buf)) return(0); mdoc->next = MDOC_NEXT_SIBLING; return(1); } + /* + * Control-character detected. Begin the parsing sequence. + */ + if (buf[1] && '\\' == buf[1]) if (buf[2] && '\"' == buf[2]) return(1); i = 1; - while (buf[i] && ! isspace((int)buf[i]) && i < (int)sizeof(tmp)) + while (buf[i] && ! isspace((u_char)buf[i]) && + i < (int)sizeof(tmp)) i++; if (i == (int)sizeof(tmp)) { @@ -231,13 +234,14 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf) return(mdoc_perr(mdoc, line, 1, "unknown macro")); } - while (buf[i] && isspace((int)buf[i])) + while (buf[i] && isspace((u_char)buf[i])) i++; if ( ! mdoc_macro(mdoc, c, line, 1, &i, buf)) { mdoc->flags |= MDOC_HALT; return(0); } + return(1); } @@ -314,7 +318,6 @@ mdoc_macro(struct mdoc *mdoc, int tok, static int mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p) { - const char *nn, *nt, *on, *ot, *act; assert(mdoc->last); assert(mdoc->first); @@ -341,34 +344,15 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node * MDOC_LINEARG_SOFTMAX, mdoc->linetok)) return(0); - if (MDOC_TEXT == mdoc->last->type) - on = ""; - else if (MDOC_ROOT == mdoc->last->type) - on = ""; - else - on = mdoc_macronames[mdoc->last->tok]; - - if (MDOC_TEXT == p->type) - nn = ""; - else if (MDOC_ROOT == p->type) - nn = ""; - else - nn = mdoc_macronames[p->tok]; - - ot = mdoc_type2a(mdoc->last->type); - nt = mdoc_type2a(p->type); - switch (mdoc->next) { case (MDOC_NEXT_SIBLING): mdoc->last->next = p; p->prev = mdoc->last; p->parent = mdoc->last->parent; - act = "sibling"; break; case (MDOC_NEXT_CHILD): mdoc->last->child = p; p->parent = mdoc->last; - act = "child"; break; default: abort(); @@ -396,8 +380,6 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node * } mdoc->last = p; - mdoc_msg(mdoc, "parse: %s `%s' %s of %s `%s'", - nt, nn, act, ot, on); return(1); } @@ -660,28 +642,4 @@ argdup(size_t argsz, const struct mdoc_arg *args) return(pp); } - - -/* FIXME: deprecate. */ -char * -mdoc_node2a(struct mdoc_node *node) -{ - static char buf[64]; - - assert(node); - - buf[0] = 0; - (void)xstrlcat(buf, mdoc_type2a(node->type), 64); - if (MDOC_ROOT == node->type) - return(buf); - (void)xstrlcat(buf, " `", 64); - if (MDOC_TEXT == node->type) - (void)xstrlcat(buf, node->data.text.string, 64); - else - (void)xstrlcat(buf, mdoc_macronames[node->tok], 64); - (void)xstrlcat(buf, "'", 64); - - return(buf); -} -