texinfo-commits
[Top][All Lists]
Advanced

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

[5522] go to right line for index entry given in program invocation


From: Gavin D. Smith
Subject: [5522] go to right line for index entry given in program invocation
Date: Wed, 07 May 2014 00:03:07 +0000

Revision: 5522
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5522
Author:   gavin
Date:     2014-05-07 00:03:06 +0000 (Wed, 07 May 2014)
Log Message:
-----------
go to right line for index entry given in program invocation

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/indices.c
    trunk/info/info-utils.c
    trunk/info/info.c
    trunk/info/session.c
    trunk/info/session.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-06 19:54:49 UTC (rev 5521)
+++ trunk/ChangeLog     2014-05-07 00:03:06 UTC (rev 5522)
@@ -1,3 +1,26 @@
+2014-05-04  Gavin Smith  <address@hidden>
+
+       * info/session.c (begin_multiple_window_info_session): Take
+       array of REFERENCE * arguments.  Caller in info.c:main updated.
+       (info_select_reference): Go to line number given by reference.
+       All callers updated.
+       (info_intuit_options_node): Return REFERENCE * instead of char *.
+       Callers updated.
+
+       * info/session.c (dump_nodes_to_file): Take reference array as
+       a parameter.  Callers updated.
+
+       * info/info.c (ref_list, ref_slots, ref_index): New file-level
+       variables.
+       (get_initial_file): Add reference to man page to ref_list if
+       we fell back to it.
+       (add_initial_nodes): Add nodes to ref_list instead of user_nodenames.
+
+       * info/session.c (info_follow_menus): Work for split files.
+
+       * info/indices.c (info_indices_of_file_buffer): Comment
+       added about whether return value should be freed.
+
 2014-05-06  Patrice Dumas  <address@hidden>
 
        * tp/Makefile.am (install-exec-hook): use $(transform) for

Modified: trunk/info/indices.c
===================================================================
--- trunk/info/indices.c        2014-05-06 19:54:49 UTC (rev 5521)
+++ trunk/info/indices.c        2014-05-07 00:03:06 UTC (rev 5522)
@@ -90,7 +90,8 @@
 /* Find and return the indices of FILE_BUFFER.  The indices are defined
    as the first node in the file containing the word "Index" and any
    immediately following nodes whose names also contain "Index".  All such
-   indices are concatenated and the result returned. */
+   indices are concatenated and the result returned.  Neither the returned
+   array nor its elements should be freed by the caller. */
 REFERENCE **
 info_indices_of_file_buffer (FILE_BUFFER *file_buffer)
 {

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2014-05-06 19:54:49 UTC (rev 5521)
+++ trunk/info/info-utils.c     2014-05-07 00:03:06 UTC (rev 5522)
@@ -218,7 +218,8 @@
 /* **************************************************************** */
 
 /* Get the entry associated with LABEL in the menu of NODE.  Return a
-   pointer to the ENTRY if found, or null. */
+   pointer to the ENTRY if found, or null.  Return value should not
+   be freed by caller. */
 REFERENCE *
 info_get_menu_entry_by_label (NODE *node, char *label) 
 {
@@ -293,7 +294,7 @@
   dest->nodename = src->nodename ? xstrdup (src->nodename) : NULL;
   dest->start = src->start;
   dest->end = src->end;
-  dest->line_number = 0;
+  dest->line_number = src->line_number;
   dest->type = src->type;
   
   return dest;

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-05-06 19:54:49 UTC (rev 5521)
+++ trunk/info/info.c   2014-05-07 00:03:06 UTC (rev 5522)
@@ -60,6 +60,11 @@
 static size_t user_nodenames_index = 0;
 static size_t user_nodenames_slots = 0;
 
+/* References to the nodes to start the session with. */
+static REFERENCE **ref_list = NULL;
+static size_t ref_slots = 0;
+static size_t ref_index = 0;
+
 /* String specifying the first file to load.  This string can only be set
    by the user specifying "--file" on the command line. */
 static char *user_filename = NULL;
@@ -231,10 +236,16 @@
 
       if (man_node)
         {
+          REFERENCE *new_ref;
+
           free (man_node);
+
+          new_ref = xzalloc (sizeof (REFERENCE));
+          new_ref->filename = MANPAGE_FILE_BUFFER_NAME;
+          new_ref->nodename = filename;
+          add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+
           initial_file = MANPAGE_FILE_BUFFER_NAME;
-          add_pointer_to_array (filename, user_nodenames_index,
-                                user_nodenames, user_nodenames_slots, 10);
           return initial_file;
         }
     }
@@ -243,17 +254,31 @@
 }
 
 /* Expand list of nodes to be loaded. */
-static void
+static REFERENCE **
 add_initial_nodes (FILE_BUFFER *initial_file, int argc, char **argv,
                    char **error)
 {
   NODE *initial_node;
   char *node_via_menus;
+  int i;
 
+  REFERENCE *new_ref;
+
+  /* Add nodes specified with --node. */
+  if (user_nodenames)
+    for (i = 0; user_nodenames[i]; i++)
+      {
+        new_ref = xzalloc (sizeof (REFERENCE));
+        new_ref->filename = initial_file->filename;
+        new_ref->nodename = user_nodenames[i];
+
+        add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+      }
+
   if (goto_invocation_p)
     {
       NODE *top_node;
-      char *invoc_node;
+      REFERENCE *invoc_ref = 0;
 
       char **p = argv;
       char *program;
@@ -283,10 +308,12 @@
         program = xstrdup ("");
       
       top_node = info_get_node_of_file_buffer (initial_file, "Top");
-      invoc_node = info_intuit_options_node (top_node, program);
-      if (invoc_node)
-        add_pointer_to_array (invoc_node, user_nodenames_index,
-                              user_nodenames, user_nodenames_slots, 10);
+      invoc_ref = info_intuit_options_node (top_node, program);
+      if (invoc_ref)
+        {
+          new_ref = info_copy_reference (invoc_ref);
+          add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+        }
     }
 
   /* If there are arguments remaining, they are the names of menu items
@@ -299,20 +326,23 @@
       initial_node = info_get_node_of_file_buffer (initial_file, "Top");
       node_via_menus = info_follow_menus (initial_node, argv, error, 1);
       if (node_via_menus)
-        add_pointer_to_array (node_via_menus, user_nodenames_index,
-                              user_nodenames, user_nodenames_slots, 10);
+        {
+          new_ref = xzalloc (sizeof (REFERENCE));
+          new_ref->filename = initial_file->filename;
+          new_ref->nodename = node_via_menus;
+
+          add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+        }
     }
 
   /* If no nodes found, and there is exactly one argument, check for
      it as an index entry. */
-  /* FIXME: This works, but doesn't go to the right position in the
-     node.  Maybe we could do it along with --index-search somehow? */
-  if (user_nodenames_index == 0 && argc == 1 && argv[0])
+  if (ref_index == 0 && argc == 1 && argv[0])
     {
       REFERENCE **index;
       REFERENCE **index_ptr;
 
-      //debug (3. "looking in indices);
+      debug (3, ("looking in indices"));
       index = info_indices_of_file_buffer (initial_file);
 
       for (index_ptr = index; index && *index_ptr; index_ptr++)
@@ -321,32 +351,43 @@
             {
               free (*error); *error = 0;
 
-              add_pointer_to_array ((*index_ptr)->nodename,
-                user_nodenames_index, user_nodenames,
-                user_nodenames_slots, 10);
+              add_pointer_to_array (info_copy_reference (*index_ptr),
+                                    ref_index, ref_list, ref_slots, 2);
               break;
             }
         }
+      free (index);
     }
 
   /* If still no nodes and there are arguments remaining, follow menus
      inexactly. */
-  if (user_nodenames_index == 0 && *argv)
+  if (ref_index == 0 && *argv)
     {
       NODE *initial_node;
 
       initial_node = info_get_node_of_file_buffer (initial_file, "Top");
       node_via_menus = info_follow_menus (initial_node, argv, error, 0);
       if (node_via_menus)
-        add_pointer_to_array (node_via_menus, user_nodenames_index,
-                              user_nodenames, user_nodenames_slots, 10);
+        {
+          new_ref = xzalloc (sizeof (REFERENCE));
+          new_ref->filename = initial_file->filename;
+          new_ref->nodename = node_via_menus;
+
+          add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+        }
     }
 
-  /* Default in case there were no other nodes. */
-  if (user_nodenames_index == 0)
-    add_pointer_to_array ("Top", user_nodenames_index,
-                          user_nodenames, user_nodenames_slots, 10);
+  /* Default is "Top" if there were no other nodes. */
+  if (ref_index == 0)
+    {
+      new_ref = xzalloc (sizeof (REFERENCE));
+      new_ref->filename = initial_file->filename;
+      new_ref->nodename = "Top";
 
+      add_pointer_to_array (new_ref, ref_index, ref_list, ref_slots, 2);
+    }
+
+  return ref_list;
 }
 
 
@@ -407,17 +448,10 @@
 static REFERENCE **
 info_find_matching_files (char *filename)
 {
-  REFERENCE **ref_list = NULL;
-  size_t ref_slots = 0;
-  size_t ref_index = 0;
   REFERENCE *new_ref;
   NODE *man_node;
 
   int i = 0;
-  
-  /* Initialize empty list. */
-  add_pointer_to_array (0, ref_index, ref_list, ref_slots, 2);
-  ref_index--;
 
   while (1)
     {
@@ -784,6 +818,10 @@
   if (all_matches_p)
     return all_files (user_filename, argc, argv);
 
+  /* Initialize empty list of nodes to load. */
+  add_pointer_to_array (0, ref_index, ref_list, ref_slots, 2);
+  ref_index--;
+
   initial_file = get_initial_file (user_filename, &argc, &argv, &error);
 
   /* --where */
@@ -835,11 +873,10 @@
     {
       if (error)
         info_error (error);
-      if (!initial_fb) return 0;
+
       /* FIXME: Was two separate functions, dump_node_to_file as well.
          Check behaviour is the same. */
-      dump_nodes_to_file (initial_fb, user_nodenames,
-                          user_output_filename, dump_subnodes);
+      dump_nodes_to_file (ref_list, user_output_filename, dump_subnodes);
       return 0;
     }
 
@@ -850,8 +887,7 @@
     }
     
   /* Initialize the Info session. */
-  begin_multiple_window_info_session (initial_file, user_nodenames,
-                                      error);
+  begin_multiple_window_info_session (ref_list, error);
   info_session ();
   return 0;
 }

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-05-06 19:54:49 UTC (rev 5521)
+++ trunk/info/session.c        2014-05-07 00:03:06 UTC (rev 5522)
@@ -86,12 +86,11 @@
 void forget_window_and_nodes (WINDOW *window);
 void display_startup_message (void);
 
-/* Begin an info session finding the nodes specified by FILENAME and NODENAMES.
-   For each loaded node, create a new window.  Always split the largest of the
+/* Begin an info session finding the nodes specified by REFERENCES.  For
+   each loaded node, create a new window.  Always split the largest of the
    available windows.  Display ERROR in echo area if non-null. */
 void
-begin_multiple_window_info_session (char *filename, char **nodenames,
-                                    char *error)
+begin_multiple_window_info_session (REFERENCE **references, char *error)
 {
   register int i;
   WINDOW *window = 0;
@@ -105,7 +104,7 @@
     show_error_node (error);
 
   /* Load dir node as a back-up. */
-  if (!filename || !nodenames || !nodenames[0])
+  if (!references || !references[0])
     {
       /* Used to build `dir' menu from `localdir' files found in INFOPATH. */
       extern NODE *dir_node (void);
@@ -117,30 +116,14 @@
       return;
     }
   
-  if (!strcmp (MANPAGE_FILE_BUFFER_NAME, filename))
+  for (i = 0; references[i]; i++)
     {
-      NODE *node;   
-
-      node = get_manpage_node (nodenames[0]);
-      if (node)
-        info_set_node_of_window (active_window, node);
-      return;
-    }
-
-  fb = info_find_file (filename);
-  for (i = 0; nodenames[i]; i++)
-    {
       NODE *node;
 
-      node = info_get_node_of_file_buffer (fb, nodenames[i]);
-
-      if (!node)
-        break;
-
       if (!window)
         {
           window = active_window;
-          info_set_node_of_window (window, node);
+          info_select_reference (window, references[i]);
         }
       else
         {
@@ -166,7 +149,8 @@
             }
 
           active_window = largest;
-          window = window_make_window (node);
+          window = window_make_window (0);
+          info_select_reference (window, references[i]);
           if (window)
             {
               window_tile_windows (TILE_INTERNALS);
@@ -1801,7 +1785,13 @@
   free (file_system_error);
 
   if (node)
-    info_set_node_of_window (window, node);
+    {
+      info_set_node_of_window (window, node);
+
+      if (entry->line_number > 0)
+        /* Third argument doesn't matter. */
+        internal_next_line (window, entry->line_number - 1, '1');
+    }
 }
 
 /* Parse the node specification in LINE using WINDOW to default the filename.
@@ -2036,8 +2026,6 @@
           if (entry = select_menu_digit (window, '1'))
             {
               info_select_reference (window, entry);
-              if (entry->line_number > 0)
-                internal_next_line (window, entry->line_number - 1, '1');
               return 0;
             }
         }
@@ -2190,8 +2178,6 @@
                   if (entry = select_menu_digit (window, '0'))
                     {
                       info_select_reference (window, entry);
-                      if (entry->line_number > 0)
-                        internal_next_line (window, entry->line_number - 1, 
'0');
                     }
                   else
                     break;
@@ -2312,8 +2298,6 @@
   if (entry = select_menu_digit (window, key))
     {
       info_select_reference (window, entry);
-      if (entry->line_number > 0)
-        internal_next_line (window, entry->line_number - 1, key);
     }
   else if (key == '0')
     {
@@ -2528,12 +2512,6 @@
         {
           NODE *orig = window->node;
           info_select_reference (window, entry);
-
-          if (entry->line_number > 0)
-            /* next_line starts at line 1?  Anyway, the -1 makes it
-               move to the right line.  */
-            internal_next_line (window, entry->line_number - 1, key);
-
         }
 
       free (line);
@@ -2866,8 +2844,12 @@
       debug (3, ("entry: %s, %s", entry->filename, entry->nodename));
       
       /* Try to find this node.  */
-      node = info_get_node (initial_node->filename, entry->nodename,
-                            PARSE_NODE_DFLT);
+      if (initial_node->parent)
+        node = info_get_node (initial_node->parent, entry->nodename,
+                              PARSE_NODE_DFLT);
+      else
+        node = info_get_node (initial_node->filename, entry->nodename,
+                              PARSE_NODE_DFLT);
       if (!node)
         {
          debug (3, ("no matching node found"));
@@ -3021,8 +3003,9 @@
 
 /* Find the node that is the best candidate to list the PROGRAM's
    invocation info and its command-line options, by looking for menu
-   items and chains of menu items with characteristic names.  */
-char *
+   items and chains of menu items with characteristic names.  Return
+   value should not be freed by caller. */
+REFERENCE *
 info_intuit_options_node (NODE *initial_node, char *program)
 {
   /* The list of node names typical for GNU manuals where the program
@@ -3049,6 +3032,8 @@
     (const char *)0
   };
   NODE *node = NULL;
+  REFERENCE *entry = NULL;
+
   const char **try_node;
 
   /* We keep looking deeper and deeper in the menu structure until
@@ -3057,12 +3042,12 @@
      in the menu hierarchy...  */
   for (node = initial_node; node; initial_node = node)
     {
-      REFERENCE *entry = NULL;
+      REFERENCE *new_entry = NULL;
 
       /* If no menu in this node, stop here.  Perhaps this node
          is the one they need.  */
       if (!initial_node->references)
-        break;
+        return entry;
 
       /* Look for node names typical for usage nodes in this menu.  */
       for (try_node = invocation_nodes; *try_node; try_node++)
@@ -3073,16 +3058,20 @@
           sprintf (nodename, *try_node, program);
           /* The last resort "%s" is dangerous, so we restrict it
              to exact matches here.  */
-          entry = entry_in_menu (nodename, initial_node,
+          new_entry = entry_in_menu (nodename, initial_node,
                                  strcmp (*try_node, "%s") == 0);
           free (nodename);
-          if (entry)
+          if (new_entry)
             break;
         }
 
-      if (!entry)
+      if (!new_entry)
         break;
+      else
+        entry = new_entry;
 
+      /* Go down into menu, and repeat. */ 
+
       if (!entry->filename)
         entry->filename = xstrdup (initial_node->parent ? initial_node->parent
                                    : initial_node->filename);
@@ -3093,7 +3082,7 @@
         break;
     }
 
-  return initial_node->nodename;
+  return entry;  
 }
 
 /* Given a name of an Info file, find the name of the package it
@@ -3126,7 +3115,7 @@
   char *program_name, *line;
   char *default_program_name, *prompt, *file_name;
   NODE *top_node;
-  char *invocation_node;
+  REFERENCE *invocation_ref;
 
   /* Intuit the name of the program they are likely to want.
      We use the file name of the current Info file as a hint.  */
@@ -3155,18 +3144,12 @@
   if (!top_node)
     info_error (msg_cant_find_node, "Top");
 
-  invocation_node = info_intuit_options_node (top_node, program_name);
+  invocation_ref = info_intuit_options_node (top_node, program_name);
 
   /* We've got our best shot at the invocation node.  Now select it.  */
-  if (invocation_node)
-    {
-      NODE *node;
+  if (invocation_ref)
+    info_select_reference (window, invocation_ref);
 
-      node = info_get_node_with_defaults (0, invocation_node,
-                                                  PARSE_NODE_DFLT, window);
-      info_set_node_of_window (window, node);
-    }
-
   if (!info_error_was_printed)
     window_clear_echo_area ();
   free (line);
@@ -3426,23 +3409,20 @@
                                FILE *stream, int dump_subnodes);
 static void initialize_dumping (void);
 
-/* Dump the nodes in FILE_BUFFER called NODENAMES to the file named
+/* Dump the nodes specified with REFERENCES to the file named
    in OUTPUT_FILENAME.  If DUMP_SUBNODES is set, recursively dump
    the nodes which appear in the menu of each node dumped. */
 void
-dump_nodes_to_file (FILE_BUFFER *file_buffer, char **nodenames,
+dump_nodes_to_file (REFERENCE **references,
                    char *output_filename, int flags)
 {
   int i;
   FILE *output_stream;
   char *filename;
   
-  if (!file_buffer)
+  if (!references)
     return;
 
-  filename = file_buffer->filename;
-  debug (1, (_("writing file %s"), filename));
-
   /* Get the stream to print the nodes to.  Special case of an output
      filename of "-" means to dump the nodes to stdout. */
   if (strcmp (output_filename, "-") == 0)
@@ -3461,9 +3441,11 @@
   /* Print each node to stream. */
   if (flags & DUMP_APPEND)
     fputc ('\f', output_stream);
-  for (i = 0; nodenames[i]; i++)
+  for (i = 0; references[i]; i++)
     {
-      if (dump_node_to_stream (filename, nodenames[i], output_stream,
+      if (dump_node_to_stream (references[i]->filename,
+                               references[i]->nodename,
+                               output_stream,
                               flags & DUMP_SUBNODES) == DUMP_SYS_ERROR)
        {
          info_error (_("error writing to %s: %s"), filename, strerror (errno));
@@ -3569,7 +3551,7 @@
   char *fullpath;
 
   debug (1, (_("writing file %s"), filename));
-  
+
   /* Get the stream to print this node to.  Special case of an output
      filename of "-" means to dump the nodes to stdout. */
   if (strcmp (filename, "-") == 0)

Modified: trunk/info/session.h
===================================================================
--- trunk/info/session.h        2014-05-06 19:54:49 UTC (rev 5521)
+++ trunk/info/session.h        2014-05-07 00:03:06 UTC (rev 5522)
@@ -100,7 +100,7 @@
 
 extern void dump_node_to_file (NODE *node, char *filename,
                               int flags);
-extern void dump_nodes_to_file (FILE_BUFFER *file_buffer, char **nodenames,
+extern void dump_nodes_to_file (REFERENCE **references,
                                char *output_filename, int flags);
 
 extern char *program_name_from_file_name (char *file_name);
@@ -122,13 +122,13 @@
 /* The names of the functions that run an info session. */
 
 /* Starting an info session. */
-extern void begin_multiple_window_info_session (char *filename,
-    char **nodenames, char *error_msg);
+extern void begin_multiple_window_info_session (REFERENCE **references,
+    char *error_msg);
 extern void info_session (void);
 extern void initialize_terminal_and_keymaps (char *init_file);
 extern void initialize_info_session (void);
 extern void info_read_and_dispatch (void);
-extern char *info_intuit_options_node (NODE *initial_node, char *program);
+extern REFERENCE *info_intuit_options_node (NODE *initial_node, char *program);
 
 /* Moving the point within a node. */
 extern void info_next_line (WINDOW *window, int count, unsigned char key);




reply via email to

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