tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Allow gzipped .so and search .so in manpath
@ 2014-11-24 14:36 Baptiste Daroussin
  2014-11-26 20:10 ` Ingo Schwarze
  0 siblings, 1 reply; 7+ messages in thread
From: Baptiste Daroussin @ 2014-11-24 14:36 UTC (permalink / raw)
  To: tech


[-- 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 --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-11-29 18:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-24 14:36 Allow gzipped .so and search .so in manpath Baptiste Daroussin
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

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).