texinfo-commits
[Top][All Lists]
Advanced

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

[5433] --init-file.


From: Gavin D. Smith
Subject: [5433] --init-file.
Date: Mon, 07 Apr 2014 17:18:19 +0000

Revision: 5433
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5433
Author:   gavin
Date:     2014-04-07 17:18:18 +0000 (Mon, 07 Apr 2014)
Log Message:
-----------
--init-file. Allow overriding init file variables on command line. Fix file 
paths in recent change log entries.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/info.c
    trunk/info/info.h
    trunk/info/infomap.c
    trunk/info/infomap.h
    trunk/info/session.c
    trunk/info/session.h
    trunk/info/variables.c
    trunk/info/variables.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/ChangeLog     2014-04-07 17:18:18 UTC (rev 5433)
@@ -1,3 +1,19 @@
+2014-04-07  Gavin Smith  <address@hidden>
+
+       * info/info.c (long_options, main): New option --init-file.
+       * info/infomap.c (initialize_info_keymaps, read_init_file): Function
+       renamed and given new argument init_file.
+       (fetch_user_maps): New argument.
+       * info/session.c (initialize_terminal_and_keymaps): New argument.
+       All callers changed.
+
+       * info/variables.h (VARIABLE_ALIST): New field where_set.
+       * info/variables.c (variable_by_name): Split out from
+       read_variable_name.
+       (set_variable_to_value): Check if variables were set already
+       with a higher priority.  Arguments changed.  All callers updated.
+       (set_variable): Call set_variable_to_value with SET_IN_SESSION.
+
 2014-04-05  Gavin Smith  <address@hidden>
 
        * doc/info-stnd.texi: Document infopath-no-defaults.
@@ -4,22 +20,22 @@
 
 2014-04-05  Gavin Smith  <address@hidden>
 
-       * Makefile.am: Condense AM_CPPFLAGS definition slightly.
-       * info.c (main): Make --directory options build up infopath
+       * info/Makefile.am: Condense AM_CPPFLAGS definition slightly.
+       * info/info.c (main): Make --directory options build up infopath
        in the order they were specified.  Call infopath_init after
        options are read instead of before.
        
-       * infopath.c, variables.c (info_variables, infopath_no_defaults_p):
-       New variable for user, info-no-defaults.
+       * info/infopath.c, info/variables.c (info_variables)
+       (infopath_no_defaults_p): New variable for user, info-no-defaults.
        
-       * infopath.c (infopath_init): Do not include $infodir and
+       * info/infopath.c (infopath_init): Do not include $infodir and
        $datadir/info in search path if info-no-defaults=On.
 
 2014-04-05  Gavin Smith  <address@hidden>
 
-        * session.c (initialize_terminal_and_keymaps, initialize_info_session):
-        Function split out.
-        * info.c (main): Call initialize_terminal_and_keymaps before
+        * info/session.c (initialize_terminal_and_keymaps)
+       (initialize_info_session): Function split out.
+        * info/info.c (main): Call initialize_terminal_and_keymaps before
         loading file.  This is needed in case a variable in .infokey affects
         the loading of the file.
 

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/info.c   2014-04-07 17:18:18 UTC (rev 5433)
@@ -24,6 +24,7 @@
 #include "indices.h"
 #include "dribble.h"
 #include "getopt.h"
+#include "variables.h"
 #if defined (HANDLE_MAN_PAGES)
 #  include "man.h"
 #endif /* HANDLE_MAN_PAGES */
@@ -107,6 +108,8 @@
 #define DRIBBLE_OPTION 2
 #define RESTORE_OPTION 3
 #define IDXSRCH_OPTION 4
+#define INITFLE_OPTION 5
+
 static struct option long_options[] = {
   { "all", 0, 0, 'a' },
   { "apropos", 1, 0, 'k' },
@@ -116,6 +119,7 @@
   { "file", 1, 0, 'f' },
   { "help", 0, &print_help_p, 1 },
   { "index-search", 1, 0, IDXSRCH_OPTION },
+  { "init-file", 1, 0, INITFLE_OPTION },
   { "location", 0, &print_where_p, 1 },
   { "node", 1, 0, 'n' },
   { "output", 1, 0, 'o' },
@@ -507,6 +511,7 @@
 main (int argc, char *argv[])
 {
   int getopt_long_index;        /* Index returned by getopt_long (). */
+  char *init_file = 0;          /* Name of init file specified. */
 
 #ifdef HAVE_SETLOCALE
   /* Set locale via LC_ALL.  */
@@ -631,8 +636,14 @@
           index_search_string = xstrdup (optarg);
           break;
 
+          /* User has specified a file to use as the init file. */
+        case INITFLE_OPTION:
+          init_file = optarg;
+          break;
+
        case 'v':
          {
+            VARIABLE_ALIST *var;
            char *p;
            p = strchr (optarg, '=');
            if (!p)
@@ -641,22 +652,17 @@
                exit (EXIT_FAILURE);
              }
            *p++ = 0;
-           if (set_variable_to_value (optarg, p))
+
+            if (!(var = variable_by_name (optarg)))
+              {
+                info_error (_("%s: no such variable"), optarg);
+                exit (EXIT_FAILURE);
+              }
+
+           if (!set_variable_to_value (var, p, SET_ON_COMMAND_LINE))
              {
-               switch (errno)
-                 {
-                 case ENOENT:
-                   info_error (_("%s: no such variable"), optarg);
-                   break;
-                           
-                 case EINVAL:
-                   info_error (_("value %s is not valid for variable %s"),
-                               p, optarg);
-                   break;
-                   
-                 default:
-                   abort ();
-                 }
+                info_error (_("value %s is not valid for variable %s"),
+                            p, optarg);
                exit (EXIT_FAILURE);
              } 
          }
@@ -721,7 +727,7 @@
   argv += optind;
   
   /* Load custom key mappings and variable settings */
-  initialize_terminal_and_keymaps ();
+  initialize_terminal_and_keymaps (init_file);
 
   /* Add extra search directories to any already specified with
      --directory. */

Modified: trunk/info/info.h
===================================================================
--- trunk/info/info.h   2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/info.h   2014-04-07 17:18:18 UTC (rev 5433)
@@ -174,9 +174,6 @@
 extern const char *msg_cant_make_help;
 
 
-/* Found in variables.c. */
-extern int set_variable_to_value (char *name, char *value);
-
 /* Found in m-x.c.  */
 extern char *read_function_name (const char *prompt, WINDOW *window);
 

Modified: trunk/info/infomap.c
===================================================================
--- trunk/info/infomap.c        2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/infomap.c        2014-04-07 17:18:18 UTC (rev 5433)
@@ -910,10 +910,10 @@
 }
 
 
-/* Fetch the contents of the standard infokey file "$HOME/.info".  Return
-   true if ok, false if not.  */
+/* Fetch the contents of the init file at INIT_FILE, or the standard
+   infokey file "$HOME/.info".  Return non-zero on success. */
 static int
-fetch_user_maps (void)
+fetch_user_maps (char *init_file)
 {
   char *filename = NULL;
   char *homedir;
@@ -925,8 +925,8 @@
   int n;
   
   /* Find and open file. */
-  if ((filename = getenv ("INFOKEY")) != NULL)
-    filename = xstrdup (filename);
+  if (init_file)
+    filename = xstrdup (init_file);
   else if ((homedir = getenv ("HOME")) != NULL)
     {
       filename = xmalloc (strlen (homedir) + 2 + strlen (INFOKEY_FILE));
@@ -1211,23 +1211,16 @@
        case gotval:
          if (!*p)
            {
-             if (set_variable_to_value ((char *) var, (char *) val))
-               {
-                 switch (errno)
-                   {
-                   case ENOENT:
-                     info_error (_("%s: no such variable"), var);
-                     break;
-                     
-                   case EINVAL:
-                     info_error (_("value %s is not valid for variable %s"),
-                                 val, var);
-                     break;
-                     
-                   default:
-                     abort ();
-                   }
-               }       
+              VARIABLE_ALIST *v;
+              if (!(v = variable_by_name (var)))
+                {
+                  info_error (_("%s: no such variable"), var);
+                }
+              else if (!set_variable_to_value (v, val, SET_IN_CONFIG_FILE))
+                {
+                  info_error (_("value %s is not valid for variable %s"),
+                              val, var);
+                }      
              state = getvar;
            }
          break;
@@ -1237,12 +1230,15 @@
     info_error ("%s", _("Bad data in infokey file -- some var settings 
ignored"));
 }
 
+/* Read key bindings and variable settings from INIT_FILE.  If INIT_FILE
+   is null, look for the init file in the default location. */
 void
-initialize_info_keymaps (void)
+read_init_file (char *init_file)
 {
+  static unsigned char *info_keys, *ea_keys; /* Pointers to keymap tables. */
+  long info_keys_len, ea_keys_len; /* Sizes of keymap tables. */
+
   int i;
-  int suppress_info_default_bindings = 0;
-  int suppress_ea_default_bindings = 0;
 
   if (!info_keymap)
     {
@@ -1255,44 +1251,45 @@
     if (isprint (i))
       echo_area_keymap[i].function = InfoCmd (ea_insert);
 
+  if (!vi_keys_p)
+    {
+      info_keys = default_emacs_like_info_keys;
+      info_keys_len = sizeof (default_emacs_like_info_keys);
+      ea_keys = default_emacs_like_ea_keys;
+      ea_keys_len = sizeof (default_emacs_like_ea_keys);
+    }
+  else
+    {
+      info_keys = default_vi_like_info_keys;
+      info_keys_len = sizeof (default_vi_like_info_keys);
+      ea_keys = default_vi_like_ea_keys;
+      ea_keys_len = sizeof (default_vi_like_ea_keys);
+    }
+
   /* Get user-defined keys and variables.  */
-  if (fetch_user_maps ())
+  if (fetch_user_maps (init_file))
     {
       if (user_info_keys_len && user_info_keys[0])
-        suppress_info_default_bindings = 1;
+        info_keys = 0; /* Suppress default bindings. */
       if (user_ea_keys_len && user_ea_keys[0])
-        suppress_ea_default_bindings = 1;
+        ea_keys = 0;
     }
 
   /* Apply the default bindings, unless the user says to suppress
      them.  */
-  if (vi_keys_p)
-    {
-      if (!suppress_info_default_bindings)
-        section_to_keymaps (info_keymap, default_vi_like_info_keys,
-                           sizeof (default_vi_like_info_keys));
-      if (!suppress_ea_default_bindings)
-          section_to_keymaps (echo_area_keymap, default_vi_like_ea_keys,
-                             sizeof (default_vi_like_ea_keys));
-    }
-  else
-    {
-      if (!suppress_info_default_bindings)
-        section_to_keymaps (info_keymap, default_emacs_like_info_keys,
-                           sizeof (default_emacs_like_info_keys));
-      if (!suppress_ea_default_bindings)
-          section_to_keymaps (echo_area_keymap, default_emacs_like_ea_keys,
-                             sizeof (default_emacs_like_ea_keys));
-    }
+  if (info_keys)
+    section_to_keymaps (info_keymap, info_keys, info_keys_len);
+  if (ea_keys)
+    section_to_keymaps (echo_area_keymap, ea_keys, ea_keys_len);
 
   /* If the user specified custom bindings, apply them on top of the
      default ones.  */
   if (user_info_keys_len)
     section_to_keymaps (info_keymap, user_info_keys, user_info_keys_len);
-
   if (user_ea_keys_len)
     section_to_keymaps (echo_area_keymap, user_ea_keys, user_ea_keys_len);
 
+  /* Set Info variables from init file. */
   if (user_vars_len)
     section_to_vars (user_vars, user_vars_len);
 }

Modified: trunk/info/infomap.h
===================================================================
--- trunk/info/infomap.h        2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/infomap.h        2014-04-07 17:18:18 UTC (rev 5433)
@@ -75,7 +75,7 @@
 /* Free MAP and it's descendents. */
 extern void keymap_discard_keymap (Keymap map, Keymap rootmap);
 
-/* Initialize the info keymaps. */
-extern void initialize_info_keymaps (void);
+/* Read init file and initialize the info keymaps. */
+extern void read_init_file (char *init_file);
 
 #endif /* not INFOMAP_H */

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/session.c        2014-04-07 17:18:18 UTC (rev 5433)
@@ -246,9 +246,9 @@
 /* Found in signals.c */
 extern void initialize_info_signal_handler (void );
 
-/* Initialize terminal, read configuration file .info and set key bindings. */
+/* Initialize terminal, read configuration file and set key bindings. */
 void
-initialize_terminal_and_keymaps (void)
+initialize_terminal_and_keymaps (char *init_file)
 {
   char *term_name = getenv ("TERM");
   terminal_initialize_terminal (term_name);
@@ -262,7 +262,7 @@
       exit (EXIT_FAILURE);
     }
 
-  initialize_info_keymaps ();
+  read_init_file (init_file);
 }
 
 /* Initialize the first info session by starting the terminal, window,

Modified: trunk/info/session.h
===================================================================
--- trunk/info/session.h        2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/session.h        2014-04-07 17:18:18 UTC (rev 5433)
@@ -127,7 +127,7 @@
     char **nodenames);
 extern void begin_info_session (NODE *initial_node);
 extern void info_session (void);
-extern void initialize_terminal_and_keymaps (void);
+extern void initialize_terminal_and_keymaps (char *init_file);
 extern void initialize_info_session (NODE *node, int clear_screen);
 extern void info_read_and_dispatch (void);
 extern void info_intuit_options_node (WINDOW *window,

Modified: trunk/info/variables.c
===================================================================
--- trunk/info/variables.c      2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/variables.c      2014-04-07 17:18:18 UTC (rev 5433)
@@ -32,6 +32,8 @@
    a variable. */
 static char *on_off_choices[] = { "Off", "On", NULL };
 
+/* Note that the 'where_set' field of each element in the array is
+   not given and defaults to 0. */
 VARIABLE_ALIST info_variables[] = {
   { "automatic-footnotes",
       N_("When \"On\", footnotes appear and disappear automatically"),
@@ -126,6 +128,7 @@
 {
   VARIABLE_ALIST *var;
   char *line;
+  char prompt[100];
 
   /* Get the variable's name and value. */
   var = read_variable_name (_("Set variable: "), window);
@@ -134,101 +137,105 @@
     return;
 
   /* Read a new value for this variable. */
-  {
-    char prompt[100];
 
-    if (!var->choices)
-      {
-        int potential_value;
+  if (!var->choices)
+    {
+      int potential_value;
 
-        if (info_explicit_arg || count != 1)
-          potential_value = count;
-        else
-          potential_value = *(var->value);
+      if (info_explicit_arg || count != 1)
+        potential_value = count;
+      else
+        potential_value = *(var->value);
 
-        sprintf (prompt, _("Set %s to value (%d): "),
-                 var->name, potential_value);
-        line = info_read_in_echo_area (active_window, prompt);
+      sprintf (prompt, _("Set %s to value (%d): "),
+               var->name, potential_value);
+      line = info_read_in_echo_area (active_window, prompt);
 
-        /* If no error was printed, clear the echo area. */
-        if (!info_error_was_printed)
-          window_clear_echo_area ();
+      /* If no error was printed, clear the echo area. */
+      if (!info_error_was_printed)
+        window_clear_echo_area ();
 
-        /* User aborted? */
-        if (!line)
-          return;
+      /* User aborted? */
+      if (!line)
+        return;
 
-        /* If the user specified a value, get that, otherwise, we are done. */
-        canonicalize_whitespace (line);
-        if (*line)
-          *(var->value) = atoi (line);
-        else
-          *(var->value) = potential_value;
+      /* If the user specified a value, get that, otherwise, we are done. */
+      canonicalize_whitespace (line);
 
-        free (line);
-      }
-    else
-      {
-        register int i;
-        REFERENCE **array = NULL;
-        size_t array_index = 0;
-        size_t array_slots = 0;
+      set_variable_to_value (var, line, SET_IN_SESSION);
 
-        for (i = 0; var->choices[i]; i++)
-          {
-            REFERENCE *entry;
+      free (line);
+    }
+  else
+    {
+      register int i;
+      REFERENCE **array = NULL;
+      size_t array_index = 0;
+      size_t array_slots = 0;
 
-            entry = xmalloc (sizeof (REFERENCE));
-            entry->label = xstrdup (var->choices[i]);
-            entry->nodename = NULL;
-            entry->filename = NULL;
+      for (i = 0; var->choices[i]; i++)
+        {
+          REFERENCE *entry;
 
-            add_pointer_to_array (entry, array_index, array, array_slots, 10);
-          }
+          entry = xmalloc (sizeof (REFERENCE));
+          entry->label = xstrdup (var->choices[i]);
+          entry->nodename = NULL;
+          entry->filename = NULL;
 
-        sprintf (prompt, _("Set %s to value (%s): "),
-                 var->name, var->choices[*(var->value)]);
+          add_pointer_to_array (entry, array_index, array, array_slots, 10);
+        }
 
-        /* Ask the completer to read a variable value for us. */
-        line = info_read_completing_in_echo_area (window, prompt, array);
+      sprintf (prompt, _("Set %s to value (%s): "),
+               var->name, var->choices[*(var->value)]);
 
-        info_free_references (array);
+      /* Ask the completer to read a variable value for us. */
+      line = info_read_completing_in_echo_area (window, prompt, array);
 
-        if (!echo_area_is_active)
-          window_clear_echo_area ();
+      info_free_references (array);
 
-        /* User aborted? */
-        if (!line)
-          {
-            info_abort_key (active_window, 0, 0);
-            return;
-          }
+      if (!echo_area_is_active)
+        window_clear_echo_area ();
 
-        /* User accepted default choice?  If so, no change. */
-        if (!*line)
-          {
-            free (line);
-            return;
-          }
+      /* User aborted? */
+      if (!line)
+        {
+          info_abort_key (active_window, 0, 0);
+          return;
+        }
 
-        /* Find the choice in our list of choices. */
-        for (i = 0; var->choices[i]; i++)
-          if (strcmp (var->choices[i], line) == 0)
-            break;
+      /* User accepted default choice?  If so, no change. */
+      if (!*line)
+        {
+          free (line);
+          return;
+        }
 
-        if (var->choices[i])
-          *(var->value) = i;
-      }
-  }
+      set_variable_to_value (var, line, SET_IN_SESSION);
+    }
 }
 
+VARIABLE_ALIST *
+variable_by_name (char *name)
+{
+  int i;
+
+  /* Find the variable in our list of variables. */
+  for (i = 0; info_variables[i].name; i++)
+    if (strcmp (info_variables[i].name, name) == 0)
+      break;
+
+  if (!info_variables[i].name)
+    return NULL;
+  else
+    return &info_variables[i];
+}
+
 /* Read the name of an Info variable in the echo area and return the
    address of a VARIABLE_ALIST member.  A return value of NULL indicates
    that no variable could be read. */
 VARIABLE_ALIST *
 read_variable_name (const char *prompt, WINDOW *window)
 {
-  register int i;
   char *line;
   REFERENCE **variables;
 
@@ -258,15 +265,7 @@
       return NULL;
     }
 
-  /* Find the variable in our list of variables. */
-  for (i = 0; info_variables[i].name; i++)
-    if (strcmp (info_variables[i].name, line) == 0)
-      break;
-
-  if (!info_variables[i].name)
-    return NULL;
-  else
-    return &info_variables[i];
+  return variable_by_name (line);
 }
 
 /* Make an array of REFERENCE which actually contains the names of the
@@ -294,31 +293,24 @@
 }
 
 int
-set_variable_to_value(char *name, char *value)
+set_variable_to_value (VARIABLE_ALIST *var, char *value, int where)
 {
-  register int i;
+  /* If variable was set elsewhere with a higher priority, don't do
+     anything, but don't indicate an error. */
+  if (var->where_set > where)
+    return 1;
 
-  /* Find the variable in our list of variables. */
-  for (i = 0; info_variables[i].name; i++)
-    if (strcmp(info_variables[i].name, name) == 0)
-      break;
-
-  if (!info_variables[i].name)
+  if (var->choices)
     {
-      errno = ENOENT;
-      return -1;
-    }
-  
-  if (info_variables[i].choices)
-    {
       register int j;
       
       /* Find the choice in our list of choices. */
-      for (j = 0; info_variables[i].choices[j]; j++)
-       if (strcmp (info_variables[i].choices[j], value) == 0)
+      for (j = 0; var->choices[j]; j++)
+       if (strcmp (var->choices[j], value) == 0)
          {
-           *info_variables[i].value = j;
-           return 0;
+           *var->value = j;
+            var->where_set = where;
+           return 1;
          }
     }
   else
@@ -327,12 +319,11 @@
       long n = strtol (value, &p, 10);
       if (*p == 0 && INT_MIN <= n && n <= INT_MAX)
        {
-         *info_variables[i].value = n;
-         return 0;
+         *var->value = n;
+         return 1;
        }
     }
 
-  errno = EINVAL;
-  return -1;
+  return 0;
 }
 

Modified: trunk/info/variables.h
===================================================================
--- trunk/info/variables.h      2014-04-05 18:22:30 UTC (rev 5432)
+++ trunk/info/variables.h      2014-04-07 17:18:18 UTC (rev 5433)
@@ -34,19 +34,30 @@
   char *doc;                    /* Documentation string. */
   int *value;                   /* Address of value. */
   char **choices;               /* Array of strings or NULL if numeric only. */
+  int where_set;                /* Where this variable was set. */
 } VARIABLE_ALIST;
 
+/* Values for VARIABLE_ALIST.where_set, in order of increasing priority. */
+#define SET_BY_DEFAULT 0
+#define SET_IN_CONFIG_FILE 1
+#define SET_ON_COMMAND_LINE 2
+#define SET_IN_SESSION 4
+
 /* Read the name of an Info variable in the echo area and return the
    address of a VARIABLE_ALIST member.  A return value of NULL indicates
    that no variable could be read. */
 extern VARIABLE_ALIST *read_variable_name (const char *prompt, WINDOW *window);
 
+extern VARIABLE_ALIST *variable_by_name (char *name);
+
 /* Make an array of REFERENCE which actually contains the names of the
    variables available in Info. */
 extern REFERENCE **make_variable_completions_array (void);
 
 /* Set the value of an info variable. */
 extern void set_variable (WINDOW *window, int count, unsigned char key);
+extern int set_variable_to_value (VARIABLE_ALIST *var, char *value, int where);
+
 extern void describe_variable (WINDOW *window, int count, unsigned char key);
 
 /* The list of user-visible variables. */




reply via email to

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