summaryrefslogtreecommitdiffstats
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-01-27 14:23:13 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-01-27 14:23:13 +0000
commit8c2a3574699d2153b3e22141794c6aff3bade748 (patch)
treee9d3d7f685f28e26fb2d9fb21abb389fae77f70a /mandocdb.c
parentd155d7384bbbd0eea4c28d0eba24a0ebcf9c6027 (diff)
downloadmandoc-8c2a3574699d2153b3e22141794c6aff3bade748.tar.gz
merge rev. 1.241: parse section number from the content of preformatted pages
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 601b2e22..6f327dd8 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1343,29 +1343,48 @@ static void
parse_cat(struct mpage *mpage, int fd)
{
FILE *stream;
- char *line, *p, *title;
+ struct mlink *mlink;
+ char *line, *p, *title, *sec;
size_t linesz, plen, titlesz;
ssize_t len;
int offs;
- stream = (-1 == fd) ?
- fopen(mpage->mlinks->file, "r") :
- fdopen(fd, "r");
- if (NULL == stream) {
- if (-1 != fd)
+ mlink = mpage->mlinks;
+ stream = fd == -1 ? fopen(mlink->file, "r") : fdopen(fd, "r");
+ if (stream == NULL) {
+ if (fd != -1)
close(fd);
if (warnings)
- say(mpage->mlinks->file, "&fopen");
+ say(mlink->file, "&fopen");
return;
}
line = NULL;
linesz = 0;
- /* Skip to first blank line. */
+ /* Parse the section number from the header line. */
- while (getline(&line, &linesz, stream) != -1)
+ while (getline(&line, &linesz, stream) != -1) {
if (*line == '\n')
+ continue;
+ if ((sec = strchr(line, '(')) == NULL)
+ break;
+ if ((p = strchr(++sec, ')')) == NULL)
+ break;
+ free(mpage->sec);
+ mpage->sec = mandoc_strndup(sec, p - sec);
+ if (warnings && *mlink->dsec != '\0' &&
+ strcasecmp(mpage->sec, mlink->dsec))
+ say(mlink->file,
+ "Section \"%s\" manual in %s directory",
+ mpage->sec, mlink->dsec);
+ break;
+ }
+
+ /* Skip to first blank line. */
+
+ while (line == NULL || *line != '\n')
+ if (getline(&line, &linesz, stream) == -1)
break;
/*
@@ -1411,8 +1430,7 @@ parse_cat(struct mpage *mpage, int fd)
if (NULL == title || '\0' == *title) {
if (warnings)
- say(mpage->mlinks->file,
- "Cannot find NAME section");
+ say(mlink->file, "Cannot find NAME section");
fclose(stream);
free(title);
return;
@@ -1431,8 +1449,7 @@ parse_cat(struct mpage *mpage, int fd)
/* Skip to next word. */ ;
} else {
if (warnings)
- say(mpage->mlinks->file,
- "No dash in title line");
+ say(mlink->file, "No dash in title line");
p = title;
}