=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mandocdb.c,v retrieving revision 1.21 retrieving revision 1.22 diff -c -r1.21 -r1.22 *** src/usr.bin/mandoc/mandocdb.c 2011/12/09 00:53:10 1.21 --- src/usr.bin/mandoc/mandocdb.c 2011/12/09 01:47:11 1.22 *************** *** 1,4 **** ! /* $Id: mandocdb.c,v 1.21 2011/12/09 00:53:10 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze --- 1,4 ---- ! /* $Id: mandocdb.c,v 1.22 2011/12/09 01:47:11 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze *************** *** 1276,1327 **** buf_append(buf, of->title); hash_put(hash, buf, TYPE_Nm); ! while (NULL != (line = fgetln(stream, &len)) && '\n' != *line) ! /* Skip to first blank line. */ ; ! while (NULL != (line = fgetln(stream, &len)) && ! ('\n' == *line || ' ' == *line)) ! /* Skip to first section header. */ ; /* ! * If no page content can be found, ! * reuse the page title as the page description. */ ! if (NULL == (line = fgetln(stream, &len))) { buf_appendb(dbuf, buf->cp, buf->size); hash_put(hash, buf, TYPE_Nd); fclose(stream); return; } - fclose(stream); /* ! * If there is a dash, skip to the text following it. */ ! for (p = line, plen = len; plen; p++, plen--) ! if ('-' == *p) ! break; ! for ( ; plen; p++, plen--) ! if ('-' != *p && ' ' != *p && 8 != *p) ! break; ! if (0 == plen) { p = line; ! plen = len; } ! /* ! * Copy the rest of the line, but no more than 70 bytes. ! */ ! if (70 < plen) ! plen = 70; ! p[plen-1] = '\0'; ! buf_appendb(dbuf, p, plen); buf->len = 0; ! buf_appendb(buf, p, plen); hash_put(hash, buf, TYPE_Nd); } static void --- 1276,1347 ---- buf_append(buf, of->title); hash_put(hash, buf, TYPE_Nm); ! /* Skip to first blank line. */ ! while (NULL != (line = fgetln(stream, &len))) ! if ('\n' == *line) ! break; /* ! * Assume the first line that is not indented ! * is the first section header. Skip to it. */ ! while (NULL != (line = fgetln(stream, &len))) ! if ('\n' != *line && ' ' != *line) ! break; ! ! /* ! * If no page content can be found, or the input line ! * is already the next section header, or there is no ! * trailing newline, reuse the page title as the page ! * description. ! */ ! ! line = fgetln(stream, &len); ! if (NULL == line || ' ' != *line || '\n' != line[(int)len - 1]) { buf_appendb(dbuf, buf->cp, buf->size); hash_put(hash, buf, TYPE_Nd); fclose(stream); return; } + line[(int)--len] = '\0'; + /* ! * Skip to the first dash. ! * Use the remaining line as the description (no more than 70 ! * bytes). */ ! if (NULL != (p = strstr(line, "- "))) { ! for (p += 2; ' ' == *p || '\b' == *p; p++) ! /* Skip to next word. */ ; ! } else p = line; ! ! if ((plen = strlen(p)) > 70) { ! plen = 70; ! p[plen] = '\0'; } ! /* Strip backspace-encoding from line. */ ! while (NULL != (line = memchr(p, '\b', plen))) { ! len = line - p; ! if (0 == len) { ! memmove(line, line + 1, plen--); ! continue; ! } ! memmove(line - 1, line + 1, plen - len); ! plen -= 2; ! } ! ! buf_appendb(dbuf, p, plen + 1); buf->len = 0; ! buf_appendb(buf, p, plen + 1); hash_put(hash, buf, TYPE_Nd); + fclose(stream); } static void