tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: Considerably tidy mandocdb(8) catman descriptions...
Date: Fri, 9 Dec 2011 02:55:05 +0100	[thread overview]
Message-ID: <20111209015505.GA26581@iris.usta.de> (raw)
In-Reply-To: <201112090121.pB91LAiY016331@krisdoz.my.domain>

Hi Kristaps,

i have merged your latest improvements to pformatted() up to the
one i'm replying to with some tweaks:

* Remove trailing whitespace.
* No need to check (len > 0) after successful fgetln(3), see the manual.
* Make a few comments a bit clearer.
* If the first section is empty, use the file name as .Nd.
* Talk about the first dash in the comment, too, not only in the code.

OK?
  Ingo

--- /co/mdocml/mandocdb.c	Fri Dec  9 02:31:41 2011
+++ ./mandocdb.c	Fri Dec  9 02:47:11 2011
@@ -1288,29 +1276,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 +1308,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).
 	 */
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

       reply	other threads:[~2011-12-09  1:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <201112090121.pB91LAiY016331@krisdoz.my.domain>
2011-12-09  1:55 ` Ingo Schwarze [this message]
2011-12-09 11:10   ` Kristaps Dzonsons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111209015505.GA26581@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).