tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Baptiste Daroussin <bapt@FreeBSD.org>
To: tech@mdocml.bsd.lv
Subject: Allow gzipped .so and search .so in manpath
Date: Mon, 24 Nov 2014 15:36:29 +0100	[thread overview]
Message-ID: <20141124143629.GB11567@ivaldir.etoilebsd.net> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 307 bytes --]

Hi,

Here is a new patch that allows to open gzipped .so files as well as looking
inside mpath for the files requested.

This allows zshall manpage which contains: .so man1/zshmodules.1 to work with
mandoc, tested on freebsd this .so find as expected
/usr/local/man/man1/zshmodules.1.gz

Best regards,
Bapt

[-- Attachment #1.2: mandoc-so_gzipped.diff --]
[-- Type: text/x-diff, Size: 2936 bytes --]

Index: Makefile
===================================================================
RCS file: /cvs/mdocml/Makefile,v
retrieving revision 1.445
diff -u -r1.445 Makefile
--- Makefile	25 Oct 2014 01:03:52 -0000	1.445
+++ Makefile	24 Nov 2014 14:32:46 -0000
@@ -236,7 +236,7 @@
 
 MANPAGE_OBJS	 = manpage.o mansearch.o mansearch_const.o manpath.o
 
-DEMANDOC_OBJS	 = demandoc.o
+DEMANDOC_OBJS	 = demandoc.o manpath.o
 
 WWW_MANS	 = apropos.1.html \
 		   demandoc.1.html \
Index: read.c
===================================================================
RCS file: /cvs/mdocml/read.c,v
retrieving revision 1.96
diff -u -r1.96 read.c
--- read.c	1 Nov 2014 06:03:13 -0000	1.96
+++ read.c	24 Nov 2014 14:32:46 -0000
@@ -19,6 +19,7 @@
 #include "config.h"
 
 #include <sys/types.h>
+#include <sys/param.h>
 #if HAVE_MMAP
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -41,6 +42,7 @@
 #include "libmandoc.h"
 #include "mdoc.h"
 #include "man.h"
+#include "manpath.h"
 #include "main.h"
 
 #define	REPARSE_LIMIT	1000
@@ -783,10 +785,61 @@
 mparse_readfd(struct mparse *curp, int fd, const char *file)
 {
 	struct buf	 blk;
+	char		 buf[PATH_MAX];
 	int		 with_mmap;
 	int		 save_filenc;
+	size_t		 i;
+	struct manpaths	 paths;
+	struct stat	 st;
+	pid_t		 child_pid;
+
+	child_pid = 0;
+
+	if (-1 == fd && *file != '/') {
+		do {
+			/* First try locally */
+			if ((fd = open(file, O_RDONLY, 0)) != -1)
+				break;
+
+			/* Try the gzip version */
+			(void)snprintf(buf, sizeof(buf), "%s.gz", file);
+			if (stat(buf, &st) != -1)
+				(void)mparse_open(curp, &fd, buf, &child_pid);
+			if (-1 != fd) {
+				curp->file = buf;
+				break;
+			}
+
+			/* Lookup in the manpath */
+			manpath_parse(&paths, NULL, NULL, NULL);
+			for (i = 0; i < paths.sz; i++) {
+				(void)snprintf(buf, sizeof(buf), "%s/%s",
+				    paths.paths[i], file);
+				if (-1 != (fd = open(buf, O_RDONLY, 0))) {
+					curp->file = buf;
+					break;
+				}
+				(void)snprintf(buf, sizeof(buf), "%s/%s.gz",
+				    paths.paths[i], file);
+				if (stat(buf, &st) != -1)
+					(void)mparse_open(curp, &fd, buf, &child_pid);
+				if (-1 != fd) {
+					curp->file = buf;
+					break;
+				}
+			}
+			manpath_free(&paths);
+			if (-1 != fd)
+				break;
 
-	if (-1 == fd && -1 == (fd = open(file, O_RDONLY, 0))) {
+			curp->file_status = MANDOCLEVEL_SYSERR;
+			if (curp->mmsg)
+				(*curp->mmsg)(MANDOCERR_SYSOPEN,
+				    curp->file_status,
+				    file, 0, 0, strerror(errno));
+			return(curp->file_status);
+		} while (0);
+	} else if (-1 == fd && -1 == (fd = open(file, O_RDONLY, 0))) {
 		curp->file_status = MANDOCLEVEL_SYSERR;
 		if (curp->mmsg)
 			(*curp->mmsg)(MANDOCERR_SYSOPEN,
@@ -818,6 +871,8 @@
 
 	if (STDIN_FILENO != fd && -1 == close(fd))
 		perror(file);
+	if (child_pid)
+		mparse_wait(curp, child_pid);
 
 	return(curp->file_status);
 }

[-- Attachment #2: Type: application/pgp-signature, Size: 181 bytes --]

             reply	other threads:[~2014-11-24 14:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-24 14:36 Baptiste Daroussin [this message]
2014-11-26 20:10 ` Ingo Schwarze
2014-11-26 20:24   ` Baptiste Daroussin
2014-11-27  0:12     ` Ingo Schwarze
2014-11-27  2:03       ` Ingo Schwarze
2014-11-29 17:54       ` Baptiste Daroussin
2014-11-29 18:14         ` Ingo Schwarze

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=20141124143629.GB11567@ivaldir.etoilebsd.net \
    --to=bapt@freebsd.org \
    --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).