texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Sun, 29 Oct 2023 12:14:01 -0400 (EDT)

branch: master
commit 412e62fa586b47a86d3a56789a28894c69fd967b
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Oct 29 15:38:00 2023 +0000

    XDG directory for infokey
    
    * info/infomap.c (locate_init_file): New function, split
    from fetch_user_maps.  Check for init file under $XDG_CONFIG_HOME
    or .config before checking for $HOME/.infokey.
    (fetch_user_maps): Call locate_init_file.
    * info/infomap.h, info/infomap.c (INFOKEY_FILE): Move to infomap.c
    and define without leading period.
    * info/infomap.c (DOT_INFOKEY_FILE): Provide definition with
    leading period.
---
 ChangeLog      | 13 ++++++++
 info/infokey.c |  2 +-
 info/infomap.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 info/infomap.h |  8 -----
 info/session.c |  2 +-
 5 files changed, 98 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f830f768a4..2a8adb825a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-10-29  Gavin Smith <gavinsmith0123@gmail.com>
+
+       XDG directory for infokey
+
+       * info/infomap.c (locate_init_file): New function, split
+       from fetch_user_maps.  Check for init file under $XDG_CONFIG_HOME
+       or .config before checking for $HOME/.infokey.
+       (fetch_user_maps): Call locate_init_file.
+       * info/infomap.h, info/infomap.c (INFOKEY_FILE): Move to infomap.c
+       and define without leading period.
+       * info/infomap.c (DOT_INFOKEY_FILE): Provide definition with
+       leading period.
+
 2023-10-29  Patrice Dumas  <pertusus@free.fr>
 
        Regular tree structure for @value with flag not found
diff --git a/info/infokey.c b/info/infokey.c
index 7202344568..b23fd906c2 100644
--- a/info/infokey.c
+++ b/info/infokey.c
@@ -1,4 +1,4 @@
-/* infokey.c -- read ~/.infokey
+/* infokey.c -- read ~/.config/texinfo/infokey
 
    Copyright 1999-2023 Free Software Foundation, Inc.
 
diff --git a/info/infomap.c b/info/infomap.c
index 71ed4098b8..30d66a6bf8 100644
--- a/info/infomap.c
+++ b/info/infomap.c
@@ -546,6 +546,87 @@ static int default_vi_like_ea_keys[] =
 /* Whether to suppress the default key bindings. */
 static int sup_info, sup_ea;
 
+
+/* To find "infokey file", where user defs are kept and read by Info.  */
+#define PACKAGE      "texinfo"
+#define INFOKEY_FILE "infokey"
+
+/* MS-DOS doesn't allow leading dots in file names.  */
+#ifdef __MSDOS__
+#define DOT_INFOKEY_FILE               "_infokey"
+#else
+#define DOT_INFOKEY_FILE               ".infokey"
+#endif
+
+
+
+/* Locate init file.  Return value to be freed by caller.  */
+char *
+locate_init_file (void)
+{
+  struct stat finfo;
+  char *xdg_config_home, *homedir;
+  char *filename;
+
+  /* First, check for init file under XDG_CONFIG_HOME. */
+
+  xdg_config_home = getenv ("XDG_CONFIG_HOME");
+  if (xdg_config_home)
+    {
+      xdg_config_home = strdup (xdg_config_home);
+    }
+  else
+    {
+      homedir = getenv ("HOME");
+#ifdef __MINGW32__
+      if (!homedir)
+        homedir = getenv ("USERPROFILE")
+#endif
+      if (homedir)
+        {
+          xdg_config_home = xmalloc (strlen (homedir)
+                                     + strlen ("/.config") + 1);
+          sprintf (xdg_config_home, "%s/%s", homedir, ".config");
+        }
+    }
+
+  if (xdg_config_home)
+    {
+      filename = xmalloc (strlen (xdg_config_home) + 1
+                          + strlen (PACKAGE) + 1
+                          + strlen (INFOKEY_FILE) + 1);
+      sprintf (filename, "%s/%s/%s",
+               xdg_config_home, PACKAGE, INFOKEY_FILE);
+      free (xdg_config_home);
+
+      int status = stat (filename, &finfo);
+      if (status == 0)
+        return filename;
+      free (filename);
+    }
+
+  /* Otherwise, use .infokey under home directory. */
+    homedir = getenv ("HOME");
+#ifdef __MINGW32__
+    if (!homedir)
+      homedir = getenv ("USERPROFILE")
+#endif
+
+  if (homedir)
+    {
+      filename = xmalloc (strlen (homedir) + 2 + strlen (DOT_INFOKEY_FILE));
+      sprintf (filename, "%s/%s", homedir, DOT_INFOKEY_FILE);
+    }
+#if defined(__MSDOS__) || defined(__MINGW32__)
+  /* Poor baby, she doesn't have a HOME...  */
+  else
+    filename = xstrdup (DOT_INFOKEY_FILE); /* try current directory */
+#endif
+
+  return filename;
+}
+
+
 /* Fetch the contents of the init file at INIT_FILE, or the standard
    infokey file "$HOME/.infokey".  Return non-zero if an init file was
    loaded and read. */
@@ -553,7 +634,6 @@ static int
 fetch_user_maps (char *init_file)
 {
   char *filename = NULL;
-  char *homedir;
   FILE *inf;
 
   /* In infokey.c */
@@ -562,22 +642,9 @@ fetch_user_maps (char *init_file)
   /* Find and open file. */
   if (init_file)
     filename = xstrdup (init_file);
-  else if ((homedir = getenv ("HOME")) != NULL
-#ifdef __MINGW32__
-           || (homedir = getenv ("USERPROFILE")) != NULL
-#endif
-         )
-    {
-      filename = xmalloc (strlen (homedir) + 2 + strlen (INFOKEY_FILE));
-      strcpy (filename, homedir);
-      strcat (filename, "/");
-      strcat (filename, INFOKEY_FILE);
-    }
-#if defined(__MSDOS__) || defined(__MINGW32__)
-  /* Poor baby, she doesn't have a HOME...  */
   else
-    filename = xstrdup (INFOKEY_FILE); /* try current directory */
-#endif
+    filename = locate_init_file ();
+
   inf = fopen (filename, "r");
   if (!inf)
     {
diff --git a/info/infomap.h b/info/infomap.h
index 61f01e8793..6fcb258c6c 100644
--- a/info/infomap.h
+++ b/info/infomap.h
@@ -104,14 +104,6 @@ extern Keymap echo_area_keymap;
 
 #define KEYMAP_META(k) ((k) < KEYMAP_META_BASE ? (k) + KEYMAP_META_BASE : (k))
 
-/* Default "infokey file", where user defs are kept and read by
-   Info.  MS-DOS doesn't allow leading dots in file names.  */
-#ifdef __MSDOS__
-#define INFOKEY_FILE           "_infokey"
-#else
-#define INFOKEY_FILE           ".infokey"
-#endif
-
 #define        A_MAX_COMMAND           120
 #define        A_INVALID               121
 
diff --git a/info/session.c b/info/session.c
index 7c1a9d30a9..1621b2123b 100644
--- a/info/session.c
+++ b/info/session.c
@@ -677,7 +677,7 @@ get_input_key_internal (void)
       /* If the sequence was incomplete, return the first byte.
              Also return the first byte for sequences with ESC that are at
          least three bytes long if 'key_time' is 0, to give some support for 
-         specifying byte sequences in .infokey for those sent by unrecognized
+         specifying byte sequences in infokey for those sent by unrecognized
          special keys (which would otherwise be skipped below). */
       pop_index = pop_start;
       get_byte_from_input_buffer (&c);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]