=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/man.c,v retrieving revision 1.75 retrieving revision 1.76 diff -c -r1.75 -r1.76 *** src/usr.bin/mandoc/man.c 2014/03/21 22:17:01 1.75 --- src/usr.bin/mandoc/man.c 2014/03/22 00:56:07 1.76 *************** *** 1,4 **** ! /* $Id: man.c,v 1.75 2014/03/21 22:17:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze --- 1,4 ---- ! /* $Id: man.c,v 1.76 2014/03/22 00:56:07 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze *************** *** 19,24 **** --- 19,25 ---- #include #include + #include #include #include #include *************** *** 701,704 **** --- 702,744 ---- assert(man && man->parse); return(man->parse); + } + + void + man_deroff(char **dest, const struct man_node *n) + { + char *cp; + size_t sz; + + if (MAN_TEXT != n->type) { + for (n = n->child; n; n = n->next) + man_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; }