[yelp] Copy the info program for dealing with INFOPATH.



commit c302f289d165fd997c65afe7718d3e1f59973bc6
Author: Rupert Swarbrick <rswarbrick gmail com>
Date:   Sat Jun 12 17:51:47 2010 +0100

    Copy the info program for dealing with INFOPATH.
    
    The info program uses the following logic to deal with INFOPATH[1]:
      - If there is no such environment variable, use a default list.
      - If INFOPATH is specified and ends with ':', prepend it to the
        default list
      - Otherwise, use INFOPATH rather than the default.
    
    [1] http://www.gnu.org/software/texinfo/manual/info-stnd/html_node/Invoking-Info.html

 libyelp/yelp-uri.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c
index a58e288..02d1841 100644
--- a/libyelp/yelp-uri.c
+++ b/libyelp/yelp-uri.c
@@ -114,6 +114,9 @@ static const gchar *infosuffix[] = {
     NULL
 };
 
+static const gchar default_info_path[] =
+    "/usr/info:/usr/share/info:/usr/local/info:/usr/local/share/info";
+
 /******************************************************************************/
 
 static void
@@ -1029,7 +1032,6 @@ resolve_info_uri (YelpUri *uri)
      * info:(name)
      */
     static gchar **infopath = NULL;
-    const gchar * const * langs = g_get_language_names ();
     gchar *name = NULL;
     gchar *sect = NULL;
     gchar *fullpath = NULL;
@@ -1049,10 +1051,24 @@ resolve_info_uri (YelpUri *uri)
 
     if (!infopath) {
         /* Initialize infopath only once */
+
+        /* Use the same logic as the info program. If INFOPATH is not
+           specified, use the default. If it is specified, just use it
+           unless it ends with a colon, in which case we add the
+           default as a suffix.
+        */
         const gchar *env = g_getenv ("INFOPATH");
+        gchar *paths;
         if (!env || env[0] == '\0')
-            env = "/usr/info:/usr/share/info:/usr/local/info:/usr/local/share/info";
-        infopath = g_strsplit (env, ":", 0);
+            paths = g_strdup (default_info_path);
+        else if (env[strlen (env)-1] == ':')
+            paths = g_strconcat (env, default_info_path, NULL);
+        else
+            paths = g_strdup (env);
+
+        infopath = g_strsplit (paths, ":", 0);
+
+        g_free (paths);
     }
 
     colon = strchr (priv->res_arg, ':');



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]