aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-12-31 18:47:52 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-12-31 18:47:52 +0000
commitcc7022e86b7687d16be389f19a69f75a82e5123c (patch)
treef7603a75124811e615420137eada3cdbc4e0ac0a
parent35e4fb6045ddb0ecb07ca1cd746258735b8b124e (diff)
downloadmandoc-cc7022e86b7687d16be389f19a69f75a82e5123c.tar.gz
mandoc-cc7022e86b7687d16be389f19a69f75a82e5123c.tar.zst
mandoc-cc7022e86b7687d16be389f19a69f75a82e5123c.zip
When parsing catpages, read from the first section (NAME, we hope) until
the next section. Also, remove the limit of 72 characters and enforce this, instead in the apropos frontend.
-rw-r--r--apropos.c4
-rw-r--r--mandocdb.c60
2 files changed, 46 insertions, 18 deletions
diff --git a/apropos.c b/apropos.c
index 15faf977..9ef25f5e 100644
--- a/apropos.c
+++ b/apropos.c
@@ -1,4 +1,4 @@
-/* $Id: apropos.c,v 1.24 2011/12/12 02:00:49 schwarze Exp $ */
+/* $Id: apropos.c,v 1.25 2011/12/31 18:47:52 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -127,7 +127,7 @@ list(struct res *res, size_t sz, void *arg)
qsort(res, sz, sizeof(struct res), cmp);
for (i = 0; i < (int)sz; i++)
- printf("%s(%s%s%s) - %s\n", res[i].title,
+ printf("%s(%s%s%s) - %.70s\n", res[i].title,
res[i].cat,
*res[i].arch ? "/" : "",
*res[i].arch ? res[i].arch : "",
diff --git a/mandocdb.c b/mandocdb.c
index 6b25b4e9..64a7e4e4 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.42 2011/12/28 00:32:13 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.43 2011/12/31 18:47:52 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -23,6 +23,7 @@
#include <sys/types.h>
#include <assert.h>
+#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <getopt.h>
@@ -129,8 +130,8 @@ static void ofile_argbuild(int, char *[], struct of **);
static void ofile_dirbuild(const char *, const char *,
const char *, int, struct of **);
static void ofile_free(struct of *);
-static void pformatted(DB *, struct buf *, struct buf *,
- const struct of *);
+static void pformatted(DB *, struct buf *,
+ struct buf *, const struct of *);
static int pman_node(MAN_ARGS);
static void pmdoc_node(MDOC_ARGS);
static int pmdoc_head(MDOC_ARGS);
@@ -1334,6 +1335,8 @@ pman_node(MAN_ARGS)
if (0 == strncmp(start, "-", 1))
start += 1;
+ else if (0 == strncmp(start, "\\-\\-", 4))
+ start += 4;
else if (0 == strncmp(start, "\\-", 2))
start += 2;
else if (0 == strncmp(start, "\\(en", 4))
@@ -1364,12 +1367,12 @@ pman_node(MAN_ARGS)
* By necessity, this involves rather crude guesswork.
*/
static void
-pformatted(DB *hash, struct buf *buf, struct buf *dbuf,
- const struct of *of)
+pformatted(DB *hash, struct buf *buf,
+ struct buf *dbuf, const struct of *of)
{
FILE *stream;
- char *line, *p;
- size_t len, plen;
+ char *line, *p, *title;
+ size_t len, plen, titlesz;
if (NULL == (stream = fopen(of->fname, "r"))) {
if (warnings)
@@ -1402,6 +1405,32 @@ pformatted(DB *hash, struct buf *buf, struct buf *dbuf,
while (NULL != (line = fgetln(stream, &len)))
if ('\n' != *line && ' ' != *line)
break;
+
+ /*
+ * Read up until the next section into a buffer.
+ * Strip the leading and trailing newline from each read line,
+ * appending a trailing space.
+ * Ignore empty (whitespace-only) lines.
+ */
+
+ titlesz = 0;
+ title = NULL;
+
+ while (NULL != (line = fgetln(stream, &len))) {
+ if (' ' != *line || '\n' != line[(int)len - 1])
+ break;
+ while (len > 0 && isspace((unsigned char)*line)) {
+ line++;
+ len--;
+ }
+ if (1 == len)
+ continue;
+ title = mandoc_realloc(title, titlesz + len);
+ memcpy(title + titlesz, line, len);
+ titlesz += len;
+ title[(int)titlesz - 1] = ' ';
+ }
+
/*
* If no page content can be found, or the input line
@@ -1410,18 +1439,19 @@ pformatted(DB *hash, struct buf *buf, struct buf *dbuf,
* description.
*/
- line = fgetln(stream, &len);
- if (NULL == line || ' ' != *line || '\n' != line[(int)len - 1]) {
+ if (NULL == title || '\0' == *title) {
if (warnings)
fprintf(stderr, "%s: cannot find NAME section\n",
of->fname);
buf_appendb(dbuf, buf->cp, buf->size);
hash_put(hash, buf, TYPE_Nd);
fclose(stream);
+ free(title);
return;
}
- line[(int)--len] = '\0';
+ title = mandoc_realloc(title, titlesz + 1);
+ title[(int)titlesz] = '\0';
/*
* Skip to the first dash.
@@ -1429,20 +1459,17 @@ pformatted(DB *hash, struct buf *buf, struct buf *dbuf,
* bytes).
*/
- if (NULL != (p = strstr(line, "- "))) {
+ if (NULL != (p = strstr(title, "- "))) {
for (p += 2; ' ' == *p || '\b' == *p; p++)
/* Skip to next word. */ ;
} else {
if (warnings)
fprintf(stderr, "%s: no dash in title line\n",
of->fname);
- p = line;
+ p = title;
}
- if ((plen = strlen(p)) > 70) {
- plen = 70;
- p[plen] = '\0';
- }
+ plen = strlen(p);
/* Strip backspace-encoding from line. */
@@ -1461,6 +1488,7 @@ pformatted(DB *hash, struct buf *buf, struct buf *dbuf,
buf_appendb(buf, p, plen + 1);
hash_put(hash, buf, TYPE_Nd);
fclose(stream);
+ free(title);
}
static void