=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.211 retrieving revision 1.213 diff -u -p -r1.211 -r1.213 --- mandoc/mdoc_validate.c 2014/04/20 19:40:13 1.211 +++ mandoc/mdoc_validate.c 2014/04/23 16:08:33 1.213 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.211 2014/04/20 19:40:13 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.213 2014/04/23 16:08:33 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -1044,34 +1044,25 @@ post_bf(POST_ARGS) static int post_lb(POST_ARGS) { - const char *p; - char *buf; - size_t sz; + struct mdoc_node *n; + const char *stdlibname; + char *libname; check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1); - assert(mdoc->last->child); - assert(MDOC_TEXT == mdoc->last->child->type); + n = mdoc->last->child; - p = mdoc_a2lib(mdoc->last->child->string); + assert(n); + assert(MDOC_TEXT == n->type); - /* If lookup ok, replace with table value. */ + if (NULL == (stdlibname = mdoc_a2lib(n->string))) + mandoc_asprintf(&libname, + "library \\(lq%s\\(rq", n->string); + else + libname = mandoc_strdup(stdlibname); - if (p) { - free(mdoc->last->child->string); - mdoc->last->child->string = mandoc_strdup(p); - return(1); - } - - /* If not, use "library ``xxxx''. */ - - sz = strlen(mdoc->last->child->string) + 2 + - strlen("\\(lqlibrary\\(rq"); - buf = mandoc_malloc(sz); - snprintf(buf, sz, "library \\(lq%s\\(rq", - mdoc->last->child->string); - free(mdoc->last->child->string); - mdoc->last->child->string = buf; + free(n->string); + n->string = libname; return(1); } @@ -1192,9 +1183,9 @@ post_defaults(POST_ARGS) static int post_at(POST_ARGS) { - const char *p, *q; - char *buf; - size_t sz; + struct mdoc_node *n; + const char *std_att; + char *att; /* * If we have a child, look it up in the standard keys. If a @@ -1202,27 +1193,18 @@ post_at(POST_ARGS) * prefix "AT&T UNIX " to the existing data. */ - if (NULL == mdoc->last->child) + if (NULL == (n = mdoc->last->child)) return(1); - assert(MDOC_TEXT == mdoc->last->child->type); - p = mdoc_a2att(mdoc->last->child->string); - - if (p) { - free(mdoc->last->child->string); - mdoc->last->child->string = mandoc_strdup(p); - } else { + assert(MDOC_TEXT == n->type); + if (NULL == (std_att = mdoc_a2att(n->string))) { mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADATT); - p = "AT&T UNIX "; - q = mdoc->last->child->string; - sz = strlen(p) + strlen(q) + 1; - buf = mandoc_malloc(sz); - strlcpy(buf, p, sz); - strlcat(buf, q, sz); - free(mdoc->last->child->string); - mdoc->last->child->string = buf; - } + mandoc_asprintf(&att, "AT&T UNIX %s", n->string); + } else + att = mandoc_strdup(std_att); + free(n->string); + n->string = att; return(1); }