From 16ee2910b2d5d0fad6b303e92efff26c0543db03 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 23 Apr 2015 16:17:44 +0000 Subject: Unify mdoc_deroff() and man_deroff() into a common function deroff(). No functional change except that for mdoc(7), it now skips leading escape sequences just like it already did for man(7). Escape sequences rarely occur in mdoc(7) code and if they do, skipping them is an improvement in this context. Minus 30 lines of code. --- mdoc.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) (limited to 'mdoc.c') diff --git a/mdoc.c b/mdoc.c index 25b6f0a5..3ecf1f89 100644 --- a/mdoc.c +++ b/mdoc.c @@ -507,42 +507,3 @@ mdoc_isdelim(const char *p) return(DELIM_NONE); } - -void -mdoc_deroff(char **dest, const struct roff_node *n) -{ - char *cp; - size_t sz; - - if (n->type != ROFFT_TEXT) { - for (n = n->child; n; n = n->next) - mdoc_deroff(dest, n); - return; - } - - /* Skip leading whitespace. */ - - for (cp = n->string; '\0' != *cp; cp++) - if (0 == isspace((unsigned char)*cp)) - break; - - /* Skip trailing whitespace. */ - - for (sz = strlen(cp); sz; sz--) - if (0 == isspace((unsigned char)cp[sz-1])) - break; - - /* Skip empty strings. */ - - if (0 == sz) - return; - - if (NULL == *dest) { - *dest = mandoc_strndup(cp, sz); - return; - } - - mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp); - free(*dest); - *dest = cp; -} -- cgit