[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Check for man page with 'man -w'
From: |
Gavin D. Smith |
Subject: |
branch master updated: Check for man page with 'man -w' |
Date: |
Sun, 16 Oct 2022 09:21:41 -0400 |
This is an automated email from the git hooks/post-receive script.
gavin pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new 8520d2b4d8 Check for man page with 'man -w'
8520d2b4d8 is described below
commit 8520d2b4d80eebe49ed44f11c47901f87d35c29f
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Oct 16 14:21:32 2022 +0100
Check for man page with 'man -w'
* info/man.c (check_manpage_node): New function, to check if
man page exists with 'man -w'. This is much faster for large
man pages.
(find_man_formatter): Cache return value.
* info/info.c (get_initial_file): Use check_manpage_node instead
of get_manpage_node.
'info -w ffmpeg-all' was reported to be slow by Hilmar Preusse.
'ffmpeg-all' is an especially long man page, so takes a longer time
for nroff to format.
---
ChangeLog | 15 ++++++++++++++
info/info.c | 7 +++----
info/man.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
info/man.h | 1 +
4 files changed, 82 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 18079094d8..6591ca269b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2022-10-16 Gavin Smith <gavinsmith0123@gmail.com>
+
+ Check for man page with 'man -w'
+
+ * info/man.c (check_manpage_node): New function, to check if
+ man page exists with 'man -w'. This is much faster for large
+ man pages.
+ (find_man_formatter): Cache return value.
+ * info/info.c (get_initial_file): Use check_manpage_node instead
+ of get_manpage_node.
+
+ 'info -w ffmpeg-all' was reported to be slow by Hilmar Preusse.
+ 'ffmpeg-all' is an especially long man page, so takes a longer time
+ for nroff to format.
+
2022-10-16 Gavin Smith <gavinsmith0123@gmail.com>
* info/info.c (main) <--output>: Exit with status of 1, not 0,
diff --git a/info/info.c b/info/info.c
index 23f849d46e..989be3676a 100644
--- a/info/info.c
+++ b/info/info.c
@@ -281,19 +281,18 @@ get_initial_file (int *argc, char ***argv, char **error)
/* Fall back to loading man page. */
{
- NODE *man_node;
+ int man_exists;
debug (3, ("falling back to manpage node"));
- man_node = get_manpage_node ((*argv)[0]);
- if (man_node)
+ man_exists = check_manpage_node ((*argv)[0]);
+ if (man_exists)
{
add_pointer_to_array
(info_new_reference (MANPAGE_FILE_BUFFER_NAME, (*argv)[0]),
ref_index, ref_list, ref_slots, 2);
initial_file = MANPAGE_FILE_BUFFER_NAME;
- free (man_node);
return;
}
}
diff --git a/info/man.c b/info/man.c
index 32019d4695..351cd3e972 100644
--- a/info/man.c
+++ b/info/man.c
@@ -56,12 +56,64 @@ static char const * const exec_extensions[] = { "", NULL };
static REFERENCE **xrefs_of_manpage (NODE *node);
static char *read_from_fd (int fd);
static char *get_manpage_contents (char *pagename);
+static char *find_man_formatter (void);
/* We store the contents of retrieved man pages in here. */
static NODE **manpage_nodes = 0;
size_t manpage_node_index = 0;
size_t manpage_node_slots = 0;
+#if PIPE_USE_FORK
+
+/* Check if a man page exists. Use "man -w" for this rather than getting
+ the contents of the man page. This is faster if we are running
+ "info --where" and we don't need the contents. */
+int
+check_manpage_node (char *pagename)
+{
+ char *cmd;
+ pid_t child;
+ int pid_status;
+
+ child = fork ();
+ if (child == -1)
+ return 0; /* couldn't fork */
+
+ if (!child)
+ {
+ int ret;
+ freopen (NULL_DEVICE, "w", stdout);
+ freopen (NULL_DEVICE, "w", stderr);
+ char *formatter = find_man_formatter();
+ if (!formatter)
+ exit (1);
+ ret = execl (formatter, formatter, "-w", pagename, (void *) 0);
+ exit (1); /* exec failed */
+ }
+ else
+ {
+ wait (&pid_status);
+ }
+
+ return !pid_status;
+}
+
+#else /* !PIPE_USE_FORK */
+
+int
+check_manpage_node (char *pagename)
+{
+ NODE *man_node = get_manpage_node (pagename);
+ if (man_node)
+ {
+ free (man_node);
+ return 1;
+ }
+ return 0;
+}
+
+#endif /* !PIPE_USE_FORK */
+
NODE *
get_manpage_node (char *pagename)
{
@@ -170,9 +222,17 @@ executable_file_in_path (char *filename, char *path)
static char *
find_man_formatter (void)
{
- char *man_command = getenv ("INFO_MAN_COMMAND");
- return man_command ? man_command :
- executable_file_in_path ("man", getenv ("PATH"));
+ static char *man_formatter;
+ char *man_command;
+
+ if (man_formatter)
+ return man_formatter;
+
+ man_command = getenv ("INFO_MAN_COMMAND");
+ man_formatter = man_command ? man_command
+ : executable_file_in_path ("man", getenv ("PATH"));
+
+ return man_formatter;
}
static char *manpage_pagename = NULL;
diff --git a/info/man.h b/info/man.h
index 536e41a397..034c2e77aa 100644
--- a/info/man.h
+++ b/info/man.h
@@ -22,6 +22,7 @@
#define MANPAGE_FILE_BUFFER_NAME "*manpages*"
+int check_manpage_node (char *pagename);
extern NODE *get_manpage_node (char *pagename);
#endif /* INFO_MAN_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Check for man page with 'man -w',
Gavin D. Smith <=