texinfo-commits
[Top][All Lists]
Advanced

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

[5252] Implement new options for standalone info.


From: Sergey Poznyakoff
Subject: [5252] Implement new options for standalone info.
Date: Sat, 13 Apr 2013 15:19:12 +0000

Revision: 5252
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5252
Author:   gray
Date:     2013-04-13 15:19:11 +0000 (Sat, 13 Apr 2013)
Log Message:
-----------
Implement new options for standalone info.

* info/info.c (debug_level): New variable.
(long_options): New options: -x (--debug) and -v (--variable).
(short_options): Update accordingly.
(main): Handle the new options.
(vinfo_debug, info_debug): New functions.
* info/info.h (info/info.h): New exern.
(debug): New macros.
(vinfo_debug, info_debug): New prototypes.
(set_variable_to_value): Change the return type.
* info/variables.c (set_variable_to_value): Compile
unconditionally.  Return 0/-1 depending on the success/failure of
the operation.
* info/filesys.c: Print additional debugging info.
* info/infomap.c: Check the return from set_variable_to_value.
* doc/info-stnd.texi: Document new options.
* doc/version.texi: Update.
* doc/version-stnd.texi: Update.
* NEWS: Update.

Modified Paths:
--------------
    trunk/NEWS
    trunk/doc/info-stnd.texi
    trunk/doc/version-stnd.texi
    trunk/doc/version.texi
    trunk/info/filesys.c
    trunk/info/info.c
    trunk/info/info.h
    trunk/info/infomap.c
    trunk/info/variables.c

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS  2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/NEWS  2013-04-13 15:19:11 UTC (rev 5252)
@@ -22,6 +22,18 @@
   
http://www.gnu.org/software/texinfo/manual/texinfo/html_node/Document-Permissions.html
 
 -------------------------------------------------------------------------------
+5.1.90 (SVN)
+
+* info
+
+New option -x (--debug) enables additional debugging output.
+
+New option -v (--variable) assigns a value to an info variable.  The
+syntax is the same as for many other GNU utilities:
+
+  -v VARIABLE=VALUE
+  
+
 5.1 (12 March 2013)
 * texi2any:
   . irregular sectioning trees (see 5.0 news item) produce a warning

Modified: trunk/doc/info-stnd.texi
===================================================================
--- trunk/doc/info-stnd.texi    2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/doc/info-stnd.texi    2013-04-13 15:19:11 UTC (rev 5252)
@@ -158,6 +158,16 @@
 You can invoke the apropos command from inside Info; see
 @ref{Searching Commands}.
 
address@hidden debugging
address@hidden -x
address@hidden --debug
+Print additional debugging information.  Each subsequent occurrence of
+this option increases the debugging output verbosity.
+
+Unless the window system is initialized, debugging output goes to the
+standard error.  When it is initialized, it is diverted to the file
address@hidden in the current working directory.
+
 @cindex directory path
 @item --directory @var{directory-path}
 @itemx -d @var{directory-path}
@@ -339,6 +349,13 @@
 external Info files are not output, and neither are menu items which are
 members of an index.  Each node is only output once.
 
address@hidden
address@hidden variable assignment
address@hidden -v @address@hidden
address@hidden address@hidden@var{value}
+Assign @var{value} to the @command{info} variable @var{name}.
address@hidden, for a detailed description of this feature.
+
 @item --version
 @cindex version information
 Prints the version information of Info and exits.
@@ -1870,10 +1887,19 @@
 and thus change the behavior of Info to more closely match your
 environment and Info file reading manner.
 
-There are two ways to set the value of a variable: interactively, using
-the @code{set-variable} command described below, or in the @code{#var}
-section of the @code{.infokey} file.  @xref{Custom Key Bindings}.
+There are three ways to set the value of a variable:
 
address@hidden 1
address@hidden
+in the command line, using the @option{-v} (@option{--variable})
+command line option (@pxref{variable-assignment});
address@hidden
+interactively, using the @code{set-variable} command described below;
address@hidden
+in the @code{#var} section of the @code{.infokey} file.  @xref{Custom
+Key Bindings}.
address@hidden enumerate
+
 @table @asis
 @item @kbd{M-x set-variable}
 @cindex variables, setting

Modified: trunk/doc/version-stnd.texi
===================================================================
--- trunk/doc/version-stnd.texi 2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/doc/version-stnd.texi 2013-04-13 15:19:11 UTC (rev 5252)
@@ -1,4 +1,4 @@
address@hidden UPDATED 22 February 2013
address@hidden UPDATED-MONTH February 2013
address@hidden UPDATED 13 April 2013
address@hidden UPDATED-MONTH April 2013
 @set EDITION 5.1
 @set VERSION 5.1

Modified: trunk/doc/version.texi
===================================================================
--- trunk/doc/version.texi      2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/doc/version.texi      2013-04-13 15:19:11 UTC (rev 5252)
@@ -1,4 +1,4 @@
address@hidden UPDATED 14 March 2013
address@hidden UPDATED 22 March 2013
 @set UPDATED-MONTH March 2013
 @set EDITION 5.1
 @set VERSION 5.1

Modified: trunk/info/filesys.c
===================================================================
--- trunk/info/filesys.c        2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/info/filesys.c        2013-04-13 15:19:11 UTC (rev 5252)
@@ -94,6 +94,8 @@
   int initial_character;
   char *temp;
 
+  debug(1, (_("looking for file \"%s\""), partial));
+
   filesys_error_number = 0;
 
   maybe_initialize_infopath ();
@@ -186,6 +188,7 @@
       register int i, pre_suffix_length;
       char *temp;
 
+      debug(1, (_("looking for file %s in %s"), filename, temp_dirname));
       /* Expand a leading tilde if one is present. */
       if (*temp_dirname == '~')
         {
@@ -218,6 +221,7 @@
             {
               if (S_ISREG (finfo.st_mode))
                 {
+                 debug(1, (_("found %s"), temp));
                   return temp;
                 }
               else if (S_ISDIR (finfo.st_mode))
@@ -232,6 +236,7 @@
                   if (newtemp)
                     {
                       free (temp);
+                     debug(1, (_("found %s"), newtemp));
                       return newtemp;
                     }
                 }
@@ -251,7 +256,10 @@
 
                   statable = (stat (temp, &finfo) == 0);
                   if (statable && (S_ISREG (finfo.st_mode)))
-                    return temp;
+                   {
+                     debug(1, (_("found %s"), temp));
+                     return temp;
+                   }
                 }
             }
         }
@@ -368,7 +376,7 @@
     {
       infopath = (char *)
         xmalloc (infopath_size = (1 + strlen (DEFAULT_INFOPATH)));
-
+      debug(2, ("INFOPATH=%s", DEFAULT_INFOPATH));
       strcpy (infopath, DEFAULT_INFOPATH);
     }
 }
@@ -543,7 +551,7 @@
       strcat (infopath, temp);
       free (temp);
     }
-
+  debug(2, ("INFOPATH=%s", infopath));
   if (found)
     free (path);
 }
@@ -554,9 +562,10 @@
 {
   if (infopath)
     free (infopath);
-
+  
   infopath = NULL;
   infopath_size = 0;
+  debug(2, ("INFOPATH cleared"));
 }
 
 /* Given a chunk of text and its length, convert all CRLF pairs at every

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/info/info.c   2013-04-13 15:19:11 UTC (rev 5252)
@@ -83,6 +83,9 @@
 /* Non-zero means print the absolute location of the file to be loaded.  */
 static int print_where_p = 0;
 
+/* Debugging level */
+int debug_level;
+
 /* Non-zero means don't try to be smart when searching for nodes.  */
 int strict_node_location_p = 0;
 
@@ -103,6 +106,7 @@
 #define IDXSRCH_OPTION 4
 static struct option long_options[] = {
   { "apropos", 1, 0, 'k' },
+  { "debug", 0, 0, 'x' },
   { "directory", 1, 0, 'd' },
   { "dribble", 1, 0, DRIBBLE_OPTION },
   { "file", 1, 0, 'f' },
@@ -120,6 +124,7 @@
   { "strict-node-location", 0, &strict_node_location_p, 1 },
   { "subnodes", 0, &dump_subnodes, 1 },
   { "usage", 0, 0, 'O' },
+  { "variable", 0, 0, 'v' },
   { "version", 0, &print_version_p, 1 },
   { "vi-keys", 0, &vi_keys_p, 1 },
   { "where", 0, &print_where_p, 1 },
@@ -131,9 +136,9 @@
 
 /* String describing the shorthand versions of the long options found above. */
 #if defined(__MSDOS__) || defined(__MINGW32__)
-static char *short_options = "k:d:n:f:ho:ORswb";
+static char *short_options = "k:d:n:f:ho:ORsv:wbx";
 #else
-static char *short_options = "k:d:n:f:ho:ORws";
+static char *short_options = "k:d:n:f:ho:ORv:wsx";
 #endif
 
 /* When non-zero, the Info window system has been initialized. */
@@ -276,6 +281,41 @@
           index_search_string = xstrdup (optarg);
           break;
 
+       case 'v':
+         {
+           char *p;
+           p = strchr (optarg, '=');
+           if (!p)
+             {
+               info_error (_("malformed variable assignment: %s"), optarg);
+               exit (EXIT_FAILURE);
+             }
+           *p++ = 0;
+           if (set_variable_to_value (optarg, p))
+             {
+               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 ();
+                 }
+               exit (EXIT_FAILURE);
+             } 
+         }
+         break;
+         
+       case 'x':
+         debug_level++;
+         break;
+         
         default:
           fprintf (stderr, _("Try --help for more information.\n"));
           exit (EXIT_FAILURE);
@@ -559,6 +599,58 @@
 /* Non-zero means ring terminal bell on errors. */
 int info_error_rings_bell_p = 1;
 
+static FILE *debug_file;
+
+static void
+close_debugfile (void)
+{
+  fclose (debug_file);
+}
+
+#define INFODEBUG_FILE "infodebug"
+
+void
+vinfo_debug (const char *format, va_list ap)
+{
+  FILE *fp;
+
+  if (!debug_file)
+    {
+      if (!info_windows_initialized_p || display_inhibited)
+       fp = stderr;
+      else
+       {
+         debug_file = fopen (INFODEBUG_FILE, "w");
+         if (!debug_file)
+           {
+             info_error (_("can't open %s: %s"), INFODEBUG_FILE,
+                         strerror (errno));
+             exit (EXIT_FAILURE);
+           }
+         atexit (close_debugfile);
+         fp = debug_file;
+         info_error (_("debugging output diverted to \"%s\""),
+                     INFODEBUG_FILE);
+       }
+    }
+  else
+    fp = debug_file;
+  
+  fprintf (fp, "%s: ", program_name);
+  vfprintf (fp, format, ap);
+  fprintf (fp, "\n");
+  fflush (stderr);
+}
+
+void
+info_debug (const char *format, ...)
+{
+  va_list ap;
+  va_start (ap, format);
+  vinfo_debug (format, ap);
+  va_end (ap);
+}
+
 /* Print AP according to FORMAT.  If the window system was initialized,
    then the message is printed in the echo area.  Otherwise, a message is
    output to stderr. */

Modified: trunk/info/info.h
===================================================================
--- trunk/info/info.h   2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/info/info.h   2013-04-13 15:19:11 UTC (rev 5252)
@@ -129,6 +129,19 @@
 /* Non-zero means don't try to be smart when searching for nodes.  */
 extern int strict_node_location_p;
 
+extern int debug_level;
+
+#define debug(n,c)                                                     \
+  do                                                                   \
+    {                                                                  \
+      if (debug_level >= (n))                                          \
+       info_debug c;                                                   \
+    }                                                                  \
+  while (0)
+
+extern void vinfo_debug (const char *format, va_list ap);
+extern void info_debug (const char *format, ...) TEXINFO_PRINTFLIKE(1,2);
+
 /* Print args as per FORMAT.  If the window system was initialized,
    then the message is printed in the echo area.  Otherwise, a message is
    output to stderr. */
@@ -157,10 +170,8 @@
 extern const char *msg_cant_make_help;
 
 
-#if defined(INFOKEY)
 /* Found in variables.c. */
-extern void set_variable_to_value (char *name, char *value);
-#endif /* INFOKEY */
+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        2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/info/infomap.c        2013-04-13 15:19:11 UTC (rev 5252)
@@ -1211,7 +1211,23 @@
               case gotval:
                 if (!*p)
                   {
-                    set_variable_to_value((char *) var, (char *) val);
+                    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 ();
+                         }
+                     } 
                     state = getvar;
                   }
                 break;

Modified: trunk/info/variables.c
===================================================================
--- trunk/info/variables.c      2013-04-07 15:00:49 UTC (rev 5251)
+++ trunk/info/variables.c      2013-04-13 15:19:11 UTC (rev 5252)
@@ -287,37 +287,46 @@
   return array;
 }
 
-#if defined(INFOKEY)
-
-void
+int
 set_variable_to_value(char *name, char *value)
 {
-       register int i;
+  register 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;
+  /* 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;
-
-       if (info_variables[i].choices)
+  if (!info_variables[i].name)
+    {
+      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)
+         {
+           *info_variables[i].value = j;
+           return 0;
+         }
+    }
+  else
+    {
+      char *p;
+      long n = strtol (value, &p, 10);
+      if (*p == 0 && INT_MIN <= n && n <= INT_MAX)
        {
-               register int j;
+         *info_variables[i].value = n;
+         return 0;
+       }
+    }
 
-               /* 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)
-                               break;
-
-               if (info_variables[i].choices[j])
-                       *info_variables[i].value = j;
-       }
-       else
-       {
-               *info_variables[i].value = atoi(value);
-       }
+  errno = EINVAL;
+  return -1;
 }
 
-#endif /* INFOKEY */




reply via email to

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