aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2011-12-09 11:16:34 +0000
committerIngo Schwarze <schwarze@openbsd.org>2011-12-09 11:16:34 +0000
commit9adaed882f55a44e620a0cea5e7980bdaf04dccb (patch)
treeed7231ed7d295477a73de11d9041971c1e6515fe /mandocdb.c
parent4e120eae8181c64f21d4e84a5110cf74abbe4131 (diff)
downloadmandoc-9adaed882f55a44e620a0cea5e7980bdaf04dccb.tar.gz
mandoc-9adaed882f55a44e620a0cea5e7980bdaf04dccb.tar.zst
mandoc-9adaed882f55a44e620a0cea5e7980bdaf04dccb.zip
Tweak pformatted():
* If the first section is empty, use the file name as .Nd. * No need to check (len > 0) after successful fgetln(3). * Improve some comments and strip trailing whitespace. ok kristaps@
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 09319489..34da9325 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.30 2011/12/09 01:21:10 kristaps Exp $ */
+/* $Id: mandocdb.c,v 1.31 2011/12/09 11:16:34 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -1288,29 +1288,30 @@ pformatted(DB *hash, struct buf *buf, struct buf *dbuf,
buf_append(buf, of->title);
hash_put(hash, buf, TYPE_Nm);
- /* Skip to first blank line. */
+ /* Skip to first blank line. */
while (NULL != (line = fgetln(stream, &len)))
- if (len && '\n' == *line)
+ if ('\n' == *line)
break;
- /*
- * Skip to first section header.
- * This happens when text is flush-left.
+ /*
+ * Assume the first line that is not indented
+ * is the first section header. Skip to it.
*/
while (NULL != (line = fgetln(stream, &len)))
- if (len && '\n' != *line && ' ' != *line)
+ if ('\n' != *line && ' ' != *line)
break;
/*
- * If no page content can be found or the input line is
- * malformed (zer-length or has no trailing newline), reuse the
- * page title as the page description.
+ * 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 || len == 0 || '\n' != line[(int)len - 1]) {
+ if (NULL == line || ' ' != *line || '\n' != line[(int)len - 1]) {
buf_appendb(dbuf, buf->cp, buf->size);
hash_put(hash, buf, TYPE_Nd);
fclose(stream);
@@ -1319,8 +1320,8 @@ pformatted(DB *hash, struct buf *buf, struct buf *dbuf,
line[(int)--len] = '\0';
- /*
- * Skip to the last dash.
+ /*
+ * Skip to the first dash.
* Use the remaining line as the description (no more than 70
* bytes).
*/