=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.250 retrieving revision 1.256 diff -u -p -r1.250 -r1.256 --- mandoc/mdoc_validate.c 2014/10/11 21:14:16 1.250 +++ mandoc/mdoc_validate.c 2014/11/26 19:24:03 1.256 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.250 2014/10/11 21:14:16 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.256 2014/11/26 19:24:03 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -70,6 +70,7 @@ static void check_args(struct mdoc *, struct mdoc_nod static int child_an(const struct mdoc_node *); static enum mdoc_sec a2sec(const char *); static size_t macro2len(enum mdoct); +static void rewrite_macro2len(char **); static int ebool(POST_ARGS); static int berr_ge1(POST_ARGS); @@ -88,7 +89,6 @@ static int post_bf(POST_ARGS); static int post_bk(POST_ARGS); static int post_bl(POST_ARGS); static int post_bl_block(POST_ARGS); -static int post_bl_block_width(POST_ARGS); static int post_bl_block_tag(POST_ARGS); static int post_bl_head(POST_ARGS); static int post_bx(POST_ARGS); @@ -209,7 +209,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Eo */ { NULL, NULL }, /* Fx */ { NULL, NULL }, /* Ms */ - { NULL, ewarn_eq0 }, /* No */ + { NULL, NULL }, /* No */ { NULL, post_ns }, /* Ns */ { NULL, NULL }, /* Nx */ { NULL, NULL }, /* Ox */ @@ -353,6 +353,20 @@ mdoc_valid_post(struct mdoc *mdoc) case MDOC_ROOT: return(post_root(mdoc)); default: + + /* + * Closing delimiters are not special at the + * beginning of a block, opening delimiters + * are not special at the end. + */ + + if (n->child != NULL) + n->child->flags &= ~MDOC_DELIMC; + if (n->last != NULL) + n->last->flags &= ~MDOC_DELIMO; + + /* Call the macro's postprocessor. */ + p = mdoc_valids[n->tok].post; return(*p ? (*p)(mdoc) : 1); } @@ -597,6 +611,7 @@ pre_bl(PRE_ARGS) mdoc->parse, argv->line, argv->pos, "Bl -width %s", argv->value[0]); + rewrite_macro2len(argv->value); n->norm->Bl.width = argv->value[0]; break; case MDOC_Offset: @@ -611,6 +626,7 @@ pre_bl(PRE_ARGS) mdoc->parse, argv->line, argv->pos, "Bl -offset %s", argv->value[0]); + rewrite_macro2len(argv->value); n->norm->Bl.offs = argv->value[0]; break; default: @@ -758,6 +774,7 @@ pre_bd(PRE_ARGS) mdoc->parse, argv->line, argv->pos, "Bd -offset %s", argv->value[0]); + rewrite_macro2len(argv->value); n->norm->Bd.offs = argv->value[0]; break; case MDOC_Compact: @@ -1004,12 +1021,14 @@ post_eoln(POST_ARGS) static int post_fname(POST_ARGS) { - const struct mdoc_node *n; - size_t pos; + const struct mdoc_node *n; + const char *cp; + size_t pos; n = mdoc->last->child; pos = strcspn(n->string, "()"); - if (n->string[pos] != '\0') + cp = n->string + pos; + if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*'))) mandoc_msg(MANDOCERR_FN_PAREN, mdoc->parse, n->line, n->pos + pos, n->string); return(1); @@ -1030,7 +1049,7 @@ post_fo(POST_ARGS) hwarn_eq1(mdoc); bwarn_ge1(mdoc); - if (mdoc->last->type == MDOC_HEAD) + if (mdoc->last->type == MDOC_HEAD && mdoc->last->nchild) post_fname(mdoc); return(1); } @@ -1157,10 +1176,6 @@ post_defaults(POST_ARGS) if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "...")) return(0); break; - case MDOC_Li: - if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "")) - return(0); - break; case MDOC_Pa: /* FALLTHROUGH */ case MDOC_Mt: @@ -1334,10 +1349,6 @@ post_bl_block(POST_ARGS) if ( ! post_bl_block_tag(mdoc)) return(0); assert(n->norm->Bl.width); - } else if (NULL != n->norm->Bl.width) { - if ( ! post_bl_block_width(mdoc)) - return(0); - assert(n->norm->Bl.width); } for (ni = n->body->child; ni; ni = ni->next) { @@ -1377,50 +1388,27 @@ post_bl_block(POST_ARGS) return(1); } -static int -post_bl_block_width(POST_ARGS) +/* + * If the argument of -offset or -width is a macro, + * replace it with the associated default width. + */ +void +rewrite_macro2len(char **arg) { size_t width; - int i; enum mdoct tok; - struct mdoc_node *n; - char buf[24]; - n = mdoc->last; - - /* - * Calculate the real width of a list from the -width string, - * which may contain a macro (with a known default width), a - * literal string, or a scaling width. - * - * If the value to -width is a macro, then we re-write it to be - * the macro's width as set in share/tmac/mdoc/doc-common. - */ - - if (0 == strcmp(n->norm->Bl.width, "Ds")) + if (*arg == NULL) + return; + else if ( ! strcmp(*arg, "Ds")) width = 6; - else if (MDOC_MAX == (tok = mdoc_hash_find(n->norm->Bl.width))) - return(1); + else if ((tok = mdoc_hash_find(*arg)) == MDOC_MAX) + return; else width = macro2len(tok); - /* The value already exists: free and reallocate it. */ - - assert(n->args); - - for (i = 0; i < (int)n->args->argc; i++) - if (MDOC_Width == n->args->argv[i].arg) - break; - - assert(i < (int)n->args->argc); - - (void)snprintf(buf, sizeof(buf), "%un", (unsigned int)width); - free(n->args->argv[i].value[0]); - n->args->argv[i].value[0] = mandoc_strdup(buf); - - /* Set our width! */ - n->norm->Bl.width = n->args->argv[i].value[0]; - return(1); + free(*arg); + mandoc_asprintf(arg, "%zun", width); } static int @@ -1435,7 +1423,7 @@ post_bl_block_tag(POST_ARGS) * Calculate the -width for a `Bl -tag' list if it hasn't been * provided. Uses the first head macro. NOTE AGAIN: this is * ONLY if the -width argument has NOT been provided. See - * post_bl_block_width() for converting the -width string. + * rewrite_macro2len() for converting the -width string. */ sz = 10; @@ -1648,8 +1636,6 @@ ebool(struct mdoc *mdoc) return(1); } - check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_LT, 2); - assert(MDOC_TEXT == nch->type); if (0 == strcmp(nch->string, "on")) { @@ -1987,7 +1973,8 @@ post_sh_see_also(POST_ARGS) mdoc->parse, n->line, n->pos, "%s(%s) after %s(%s)", name, sec, lastname, lastsec); - else if (cmp == 0 && strcmp(lastname, name) > 0) + else if (cmp == 0 && + strcasecmp(lastname, name) > 0) mandoc_vmsg(MANDOCERR_XR_ORDER, mdoc->parse, n->line, n->pos, "%s after %s", name, lastname);