texinfo-commits
[Top][All Lists]
Advanced

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

[5675] section_to_vars merged into compile


From: Gavin D. Smith
Subject: [5675] section_to_vars merged into compile
Date: Fri, 20 Jun 2014 08:57:41 +0000

Revision: 5675
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5675
Author:   gavin
Date:     2014-06-20 08:57:39 +0000 (Fri, 20 Jun 2014)
Log Message:
-----------
section_to_vars merged into compile

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/infokey.c
    trunk/info/infomap.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-06-19 20:05:33 UTC (rev 5674)
+++ trunk/ChangeLog     2014-06-20 08:57:39 UTC (rev 5675)
@@ -1,3 +1,15 @@
+2014-06-20  Gavin Smith  <address@hidden>
+
+       * info/infokey.c (compile): Set Info variables as was done in
+       section_to_vars.
+       * info/infomap.c (section_to_vars): Removed.
+       (user_vars, user_vars_len): Removed.
+       (read_init_file): Don't call section_to_vars.
+       (fetch_user_maps): Don't set user_vars.
+       (filesize, getint): Remove unused.
+
+       * info/infokey.c (error_message): Merged into calling code.
+
 2014-06-19  Gavin Smith  <address@hidden>
 
        * info/infokey.c (lookup_action): Use function_doc_array instead of

Modified: trunk/info/infokey.c
===================================================================
--- trunk/info/infokey.c        2014-06-19 20:05:33 UTC (rev 5674)
+++ trunk/info/infokey.c        2014-06-20 08:57:39 UTC (rev 5675)
@@ -24,6 +24,7 @@
 #include "infokey.h"
 #include "doc.h"
 #include "getopt.h"
+#include "variables.h"
 
 extern char *program_name;  /* in info.c */
 
@@ -38,8 +39,6 @@
 int compile (FILE *fp, const char *filename, struct sect *sections);
 static void syntax_error (const char *filename, unsigned int linenum,
                          const char *fmt, ...) TEXINFO_PRINTFLIKE(3,4);
-void error_message (int error_code, const char *fmt, ...)
-  TEXINFO_PRINTFLIKE(2,3);
 
 /* Compilation - the real work.
 
@@ -507,7 +506,7 @@
                            _("missing `=' immediately after variable name"));
              error = 1;
            }
-         else if (varlen < sizeof varn)
+         else if (varlen < sizeof varn - 1)
            varn[varlen++] = c;
          else
            {
@@ -519,17 +518,19 @@
        case get_value:
          if (c == '\n')
            {
-             state = start_of_line;
-             if (!(add_to_section (&sections[section], varn, varlen)
-                   && add_to_section (&sections[section], "", 1)
-                   && add_to_section (&sections[section], val, vallen)
-                   && add_to_section (&sections[section], "", 1)))
-               {
-                 syntax_error (filename, lnum, _("section too long"));
-                 error = 1;
-               }
+              VARIABLE_ALIST *v;
+
+              state = start_of_line;
+              varn[varlen] = '\0';
+              val[vallen] = '\0';
+              v = variable_by_name (varn);
+              if (!v)
+                info_error (_("%s: no such variable"), varn);
+              else if (!set_variable_to_value (v, val, SET_IN_CONFIG_FILE))
+                info_error (_("value %s is not valid for variable %s"),
+                              val, var);
            }
-         else if (vallen < sizeof val)
+         else if (vallen < sizeof val - 1)
            val[vallen++] = c;
          else
            {
@@ -582,23 +583,6 @@
 
 /* Error handling. */
 
-/* Give the user a "syntax error" message in the form
-       progname: "filename", line N: message
- */
-void
-error_message (int error_code, const char *fmt, ...)
-{
-  va_list ap;
-
-  fprintf (stderr, "%s: ", program_name);
-  va_start(ap, fmt);
-  vfprintf (stderr, fmt, ap);
-  va_end(ap);
-  if (error_code)
-    fprintf (stderr, " - %s", strerror (error_code));
-  fprintf (stderr, "\n");
-}
-
 /* Give the user a generic error message in the form
        progname: message
  */

Modified: trunk/info/infomap.c
===================================================================
--- trunk/info/infomap.c        2014-06-19 20:05:33 UTC (rev 5674)
+++ trunk/info/infomap.c        2014-06-20 08:57:39 UTC (rev 5675)
@@ -832,46 +832,13 @@
 
 
 /* Used to hold output data from compile(). */
-struct sect sections[3];
+struct sect sections[2];
 
 static unsigned char *user_info_keys;
 static unsigned int user_info_keys_len;
 static unsigned char *user_ea_keys;
 static unsigned int user_ea_keys_len;
-static unsigned char *user_vars;
-static unsigned int user_vars_len;
 
-/*
- * Return the size of a file, or 0 if the size can't be determined.
- */
-static unsigned long
-filesize (int f)
-{
-  long pos = lseek (f, 0L, SEEK_CUR);
-  long sz = -1L;
-  if (pos != -1L)
-    {
-      sz = lseek (f, 0L, SEEK_END);
-      lseek (f, pos, SEEK_SET);
-    }
-  return sz == -1L ? 0L : sz;
-}
-
-/* Get an integer from a infokey file.
-   Integers are stored as two bytes, low order first, in radix INFOKEY_RADIX.
- */
-static int
-getint (unsigned char **sp)
-{
-  int n;
-  
-  if ( !((*sp)[0] < INFOKEY_RADIX && (*sp)[1] < INFOKEY_RADIX) )
-    return -1;
-  n = (*sp)[0] + (*sp)[1] * INFOKEY_RADIX;
-  *sp += 2;
-  return n;
-}
-
 /* Fetch the contents of the init file at INIT_FILE, or the standard
    infokey file "$HOME/.info".  Return non-zero on success. */
 static int
@@ -907,7 +874,11 @@
   inf = fopen (filename, "r");
   if (!inf)
     {
-      error_message (errno, _("cannot open input file `%s'"), filename);
+      if (errno)
+        info_error (_("cannot open input file `%s' - %s"),
+            filename, strerror (errno));
+      else
+        info_error (_("cannot open input file `%s'"), filename);
       return 0;
     }
 
@@ -916,8 +887,6 @@
   user_info_keys_len = sections[0].cur;
   user_ea_keys = sections[1].data;
   user_ea_keys_len = sections[1].cur;
-  user_vars = sections[2].data;
-  user_vars_len = sections[2].cur;
 
   free (filename);
   return 1;
@@ -1047,63 +1016,6 @@
   return !stop;
 }
 
-/* Convert an infokey file section to variable settings.
- */
-static void
-section_to_vars (unsigned char *table, unsigned int len)
-{
-  enum { getvar, gotvar, getval, gotval } state = getvar;
-  unsigned char *var = NULL;
-  unsigned char *val = NULL;
-  unsigned char *p;
-  
-  for (p = table; (unsigned int) (p - table) < len; p++)
-    {
-      switch (state)
-       {
-       case getvar:
-         if (*p)
-           {
-             var = p;
-             state = gotvar;
-           }
-         break;
-         
-       case gotvar:
-         if (!*p)
-           state = getval;
-         break;
-         
-       case getval:
-         if (*p)
-           {
-             val = p;
-             state = gotval;
-           }
-         break;
-         
-       case gotval:
-         if (!*p)
-           {
-              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;
-       }
-    }
-  if (state != getvar)
-    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
@@ -1162,10 +1074,6 @@
     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);
 }
 
 /* vim: set sw=2 cino={1s>2sn-s^-se-s: */




reply via email to

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