discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Simon Branch <simonmbranch@gmail.com>
To: discuss@mandoc.bsd.lv
Subject: Gzip'ed manpages other than the first argument
Date: Sat, 3 Sep 2022 14:25:48 -0700	[thread overview]
Message-ID: <20220903212548.yefzvlxm56cegeiw@pine.sigxcpu.com> (raw)

Hello!  A current build of mandoc(1) only automatically unzips on the
first call to process_onefile().  This is because detection happens in
mparse_open(), which is called by process_onefile() *before* parse():

	if (resp->file != NULL)
		if ((fd = mparse_open(mp, resp->file)) == -1)
			...
	...
	if (resp->form == FORM_SRC)
		parse(mp, fd, resp->file, outst, conf);

Unfortunately parse() is where we reset the struct mparse

	if (previous)
		mparse_reset(mp);
	else
		previous = 1;

... which is where the gzip flag is stored.  In other words,
process_onefile() calls mparse_open(), which populates mp->gzip, and
then calls parse(), which overwrites mp->gzip (after the first run).

My fix here is to hoist the mparse_reset() call all the way out to
main(), where it is within view of the initial mparse_alloc().
Thoughts?

Index: main.c
===================================================================
RCS file: /cvs/mandoc/main.c,v
retrieving revision 1.361
diff -u -r1.361 main.c
--- main.c	14 Apr 2022 16:43:43 -0000	1.361
+++ main.c	3 Sep 2022 20:34:10 -0000
@@ -626,6 +626,8 @@
 	 */
 	startdir = open(".", O_RDONLY | O_DIRECTORY);
 	for (i = 0; i < ressz; i++) {
+		if (i)
+			mparse_reset(mp);
 		process_onefile(mp, res + i, startdir, &outst, &conf);
 		if (outst.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK)
 			break;
@@ -952,17 +954,11 @@
     struct outstate *outst, struct manconf *conf)
 {
 	static struct manpaths	 basepaths;
-	static int		 previous;
 	struct roff_meta	*meta;
 
 	assert(fd >= 0);
 	if (file == NULL)
 		file = "<stdin>";
-
-	if (previous)
-		mparse_reset(mp);
-	else
-		previous = 1;
 
 	mparse_readfd(mp, fd, file);
 	if (fd != STDIN_FILENO)
--
 To unsubscribe send an email to discuss+unsubscribe@mandoc.bsd.lv


                 reply	other threads:[~2022-09-03 21:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220903212548.yefzvlxm56cegeiw@pine.sigxcpu.com \
    --to=simonmbranch@gmail.com \
    --cc=discuss@mandoc.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).