=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.240 retrieving revision 1.241 diff -u -p -r1.240 -r1.241 --- mandoc/mandocdb.c 2017/01/27 01:09:14 1.240 +++ mandoc/mandocdb.c 2017/01/27 01:14:47 1.241 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.240 2017/01/27 01:09:14 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.241 2017/01/27 01:14:47 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2017 Ingo Schwarze @@ -1254,31 +1254,50 @@ 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; + /* * Assume the first line that is not indented * is the first section header. Skip to it. @@ -1322,8 +1341,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; @@ -1342,8 +1360,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; }