Index: mandocdb.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v retrieving revision 1.25 diff -u -p -r1.25 mandocdb.c --- mandocdb.c 7 Dec 2011 01:57:20 -0000 1.25 +++ mandocdb.c 7 Dec 2011 14:55:39 -0000 @@ -1301,31 +1301,69 @@ pformatted(DB *hash, struct buf *buf, st } fclose(stream); + /* + * Strip out backspace-encoding. + * Also handle the bogus case where the backspace is malformed + * at the beginning or end of the line. + */ + + while (NULL != (p = memchr(line, '\b', len))) { + plen = p - line; + if (plen == --len) + continue; + if (plen > 0) { + memmove(p - 1, p + 1, len - plen); + len--; + } else + memmove(p, p + 1, len); + } + + /* + * Check if there's no name/description information. This + * happens with some manuals, e.g., LAPACK. If not, reuse our + * title. + */ + + if (len > 0 && '\n' == line[len - 1]) { + line[--len] = '\0'; + if (0 == strcmp(line, "SYNOPSIS")) { + buf_appendb(dbuf, buf->cp, buf->size); + hash_put(hash, buf, TYPE_Nd); + return; + } + } else if (0 == len) { + buf_appendb(dbuf, buf->cp, buf->size); + hash_put(hash, buf, TYPE_Nd); + return; + } + /* * If there is a dash, skip to the text following it. */ - for (p = line, plen = len; plen; p++, plen--) - if ('-' == *p) - break; + p = memchr(line, '-', len); + plen = len - (p - line); + for ( ; plen; p++, plen--) - if ('-' != *p && ' ' != *p && 8 != *p) + if ('-' != *p && ' ' != *p) break; - if (0 == plen) { - p = line; - plen = len; - } /* * Copy the rest of the line, but no more than 70 bytes. */ - if (70 < plen) + if (0 == plen) { + p = line; + plen = len; + } else if (70 < plen) plen = 70; - p[plen-1] = '\0'; + buf_appendb(dbuf, p, plen); + buf_appendb(dbuf, "", 1); + buf->len = 0; buf_appendb(buf, p, plen); + buf_appendb(buf, "", 1); hash_put(hash, buf, TYPE_Nd); }