[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Gavin D. Smith |
Date: |
Sun, 20 Mar 2022 04:55:28 -0400 (EDT) |
branch: master
commit 75dbeb1f4717d101b80cf344ce1eb8709d7e54ba
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Thu Oct 31 14:45:53 2019 +0000
implement search path
---
js/infog/infopath.c | 99 +++++++++++++++++++++++++++++++++--------------------
js/infog/main.c | 6 ----
2 files changed, 62 insertions(+), 43 deletions(-)
diff --git a/js/infog/infopath.c b/js/infog/infopath.c
index 63402d0abd..4d6744c540 100644
--- a/js/infog/infopath.c
+++ b/js/infog/infopath.c
@@ -4,57 +4,82 @@
#include <dirent.h>
#include <sys/stat.h>
+#include <gmodule.h>
+
#include "infopath.h"
-static char *datadir;
-long datadir_len;
+char *default_path[] = { "/usr/share/info/html",
+ "/usr/local/share/info/html",
+ NULL };
-/* Return pathname of the main index.html file for a HTML manual.*/
-char *
-locate_manual (const char *manual)
+static GArray *dirs;
+
+static int initialized = 0;
+
+void
+init_infopath (void)
{
- if (!datadir)
- {
- datadir = getenv ("INFO_HTML_DIR");
- if (!datadir)
- return 0;
- datadir_len = strlen (datadir);
- g_print ("datadir is %s\n", datadir);
- }
+ initialized = 1;
- /* Check if datadir exists. */
- DIR *d = opendir (datadir);
- if (!d)
+ dirs = g_array_new (TRUE, TRUE, sizeof (char *));
+
+ char **p;
+ for (p = default_path; (*p); p++)
{
- fprintf (stderr, "Could not open %s\n", datadir);
- return 0;
+ g_array_append_val (dirs, *p);
}
- closedir (d);
-
- char *s = malloc (datadir_len + strlen ("/") + strlen (manual) + 1);
- sprintf (s, "%s/%s", datadir, manual);
- d = opendir (s);
- if (!d)
+ char *datadir = getenv ("INFO_HTML_DIR");
+ if (datadir)
{
- fprintf (stderr, "Could not open %s\n", s);
- free (s);
- return 0;
+ g_array_append_val (dirs, datadir);
}
- closedir (d);
+}
+
+/* Return pathname of the idirectory containing an HTML manual.*/
+char *
+locate_manual (const char *manual)
+{
+ if (!initialized)
+ init_infopath ();
- char *s2 = malloc (datadir_len + strlen ("/")
- + strlen (manual) + strlen ("/index.html") + 1);
- sprintf (s2, "%s/%s/index.html", datadir, manual);
+ int i;
+ char *datadir;
- struct stat dummy;
- if (stat (s2, &dummy) == -1)
+ for (i = 0; (datadir = g_array_index (dirs, char *, i)); i++)
{
- fprintf (stderr, "no file %s\n", s2);
- return 0;
+ /* Check if datadir exists. */
+ DIR *d = opendir (datadir);
+ if (!d)
+ continue;
+ closedir (d);
+
+ char *s = malloc (strlen (datadir) + strlen ("/") + strlen (manual) + 1);
+ sprintf (s, "%s/%s", datadir, manual);
+
+ d = opendir (s);
+ if (!d)
+ {
+ free (s);
+ continue;
+ }
+ closedir (d);
+
+ char *s2 = malloc (strlen (datadir) + strlen ("/")
+ + strlen (manual) + strlen ("/index.html") + 1);
+ sprintf (s2, "%s/%s/index.html", datadir, manual);
+
+ struct stat dummy;
+ if (stat (s2, &dummy) == -1)
+ {
+ free (s); free (s2);
+ continue;
+ }
+
+ free (s2);
+ return s;
}
-
- return s;
+ return 0;
}
/* Extract the manual and node from a URL like "file:/.../MANUAL/NODE.html".
*/
diff --git a/js/infog/main.c b/js/infog/main.c
index 085879f286..541d319abc 100644
--- a/js/infog/main.c
+++ b/js/infog/main.c
@@ -919,12 +919,6 @@ main (int argc, char *argv[])
gtk_init (&argc, &argv);
find_extensions_directory (argc, argv);
- if (!getenv ("INFO_HTML_DIR"))
- {
- g_print ("Please set INFO_HTML_DIR\n");
- return 0;
- }
-
if (signal (SIGINT, termination_handler) == SIG_IGN)
signal (SIGINT, SIG_IGN);
if (signal (SIGHUP, termination_handler) == SIG_IGN)
- [no subject], (continued)
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject],
Gavin D. Smith <=
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20