texinfo-commits
[Top][All Lists]
Advanced

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

[5848] don' t call index_entry_exists and do_info_index_search for --ind


From: Gavin D. Smith
Subject: [5848] don' t call index_entry_exists and do_info_index_search for --index-search
Date: Mon, 29 Sep 2014 13:33:17 +0000

Revision: 5848
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5848
Author:   gavin
Date:     2014-09-29 13:33:16 +0000 (Mon, 29 Sep 2014)
Log Message:
-----------
don't call index_entry_exists and do_info_index_search for --index-search

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-09-29 11:46:47 UTC (rev 5847)
+++ trunk/ChangeLog     2014-09-29 13:33:16 UTC (rev 5848)
@@ -16,6 +16,14 @@
        * info/indices.c (report_index_match): Split out from 
        info_next_index_match.
 
+       * info/indices.c (next_index_match): Don't take index argument; 
+       always operate on index_index.  Take FILE_BUFFER argument.  
+       Update index_offset.  Call to info_indices_of_file_buffer to 
+       update index_index moved from do_info_index_search.  All callers 
+       updated.
+       * info/info.c (main) <--index-search>: Call next_index_match and 
+       report_index_match.
+
 2014-09-28  Gavin Smith  <address@hidden>
 
        * info/indices.c (info_index_apropos): Strip any suffix like 

Modified: trunk/info/indices.c
===================================================================
--- trunk/info/indices.c        2014-09-29 11:46:47 UTC (rev 5847)
+++ trunk/info/indices.c        2014-09-29 13:33:16 UTC (rev 5848)
@@ -226,22 +226,6 @@
   free (index_search);
   index_search = NULL;
 
-  /* If the file is not the same as the one that we last built an
-     index for, build and remember an index now. */
-  if (!initial_index_filename ||
-      (FILENAME_CMP (initial_index_filename, fb->filename) != 0))
-    {
-      window_message_in_echo_area (_("Finding index entries..."));
-      info_indices_of_file_buffer (fb); /* Sets index_index. */
-    }
-
-  /* If there is no index, quit now. */
-  if (!index_index)
-    {
-      info_error (_("No indices found."));
-      return;
-    }
-
   /* The user typed either a completed index label, or a partial string.
      Find an exact match, or, failing that, the first index entry containing
      the partial string.  So, we just call info_next_index_match () with minor
@@ -345,60 +329,88 @@
   return 0;
 }
 
-/* Search for the next occurence of STRING in INDEX starting at OFFSET in 
-   direction DIR.  If *PARTIAL is 0, try to get an exact match first, 
otherwise 
-   only look for partial matches.  If a match is found, set *FOUND_OFFSET to 
-   its offset.  If we found a partial match, update *PARTIAL to 1. */
-static void
-next_index_match (REFERENCE **index, char *string, int offset, int dir,
-                  int *partial_inout, int *found_offset, int *match_offset)
+/* Search for the next occurence of STRING in FB's indices starting at OFFSET 
+   in direction DIR.  If INDEX_PARTIAL is 0, try to get an exact match first, 
+   otherwise only look for partial matches.  If a match is found, set *RESULT 
+   to the matching index entry, and *FOUND_OFFSET to its offset in 
+   INDEX_INDEX.  Otherwise set *RESULT to null.  If we found a partial match, 
+   update INDEX_PARTIAL to 1.  */
+void
+next_index_match (FILE_BUFFER *fb, char *string, int offset, int dir,
+                  REFERENCE **result, int *found_offset, int *match_offset)
 {
   int i;
   int partial_match;
-  int partial;
   size_t search_len;
 
-  partial = *partial_inout;
-
   partial_match = 0;
   search_len = strlen (string);
 
-  if (!partial)
+  /* If the file is not the same as the one that we last built an
+     index for, build and remember an index now. */
+  if (!initial_index_filename
+      || FILENAME_CMP (initial_index_filename, fb->filename) != 0)
     {
+      if (info_windows_initialized_p)
+        window_message_in_echo_area (_("Finding index entries..."));
+      info_indices_of_file_buffer (fb); /* Sets index_index. */
+    }
+
+  /* If there is no index, quit now. */
+  if (!index_index)
+    {
+      info_error (_("No indices found."));
+      return;
+    }
+
+  if (index_search != string)
+    {
+      free (index_search); index_search = string;
+    }
+
+  if (!index_partial)
+    {
       /* First try to find an exact match. */
-      for (i = offset + dir; i > -1 && index[i]; i += dir)
-        if (index_entry_matches (index[i], string, search_len))
+      for (i = offset + dir; i > -1 && index_index[i]; i += dir)
+        if (index_entry_matches (index_index[i], string, search_len))
          break;
 
       /* If that failed, look for the next substring match. */
-      if (i < 0 || !index[i])
+      if (i < 0 || !index_index[i])
        {
           offset = 0;
-          partial = 1;
+          index_partial = 1;
        }
     }
 
-  if (partial)
+  if (index_partial)
     {
       /* When looking for substrings, take care not to return previous exact
         matches. */
-      for (i = offset + dir; i > -1 && index[i]; i += dir)
-        if (!index_entry_matches (index[i], string, search_len))
+      for (i = offset + dir; i > -1 && index_index[i]; i += dir)
+        if (!index_entry_matches (index_index[i], string, search_len))
          {
-            partial_match = string_in_line (string, index[i]->label);
+            partial_match = string_in_line (string, index_index[i]->label);
             if (partial_match != -1)
              break;
          }
-      partial = partial_match > 0;
+      index_partial = partial_match > 0;
     }
 
-  *partial_inout = partial;
+  if (i < 0 || !index_index[i])
+    *result = 0;
+  else
+    {
+      index_offset = i;
+      *result = index_index[i];
+    }
+
   *found_offset = i;
   *match_offset = partial_match;
 }
 
 /* Display a message saying where the index match was found. */
-static void
+void
 report_index_match (int i, int match_offset)
 {
   register int j;
@@ -453,6 +465,7 @@
   int i;
   int match_offset;
   int dir;
+  REFERENCE *result;
   
   /* If there is no previous search string, the user hasn't built an index
      yet. */
@@ -462,13 +475,6 @@
       return;
     }
 
-  /* If there is no index, that is an error. */
-  if (!index_index)
-    {
-      info_error (_("No index entries."));
-      return;
-    }
-
   /* The direction of this search is controlled by the value of the
      numeric argument. */
   if (count < 0)
@@ -476,11 +482,11 @@
   else
     dir = 1;
 
-  next_index_match (index_index, index_search, index_offset,
-                    dir, &index_partial, &i, &match_offset);
+  next_index_match (file_buffer_of_window (window), index_search, index_offset,
+                    dir, &result, &i, &match_offset);
 
   /* If that failed, print an error. */
-  if ((i < 0) || (!index_index[i]))
+  if (!result)
     {
       info_error (index_offset > 0 ?
                  _("No more index entries containing '%s'.") :
@@ -490,13 +496,10 @@
       return;
     }
 
-  /* Okay, we found the next one.  Move the offset to the current entry. */
-  index_offset = i;
-
   /* Report to the user on what we have found. */
   report_index_match (i, match_offset);
 
-  info_select_reference (window, index_index[i]);
+  info_select_reference (window, result);
 }
 
 /* Look for the best match of STRING in the indices of FB.  Return null if no 

Modified: trunk/info/indices.h
===================================================================
--- trunk/info/indices.h        2014-09-29 11:46:47 UTC (rev 5847)
+++ trunk/info/indices.h        2014-09-29 13:33:16 UTC (rev 5848)
@@ -33,6 +33,9 @@
 extern void info_next_index_match (WINDOW *window, int count, int key);
 extern void info_index_apropos (WINDOW *window, int count, int key);
 extern void do_info_index_search (WINDOW *window, FILE_BUFFER *fb, int count, 
char *search_string);
+void next_index_match (FILE_BUFFER *fb, char *string, int offset, int dir,
+                  REFERENCE **result, int *found_offset, int *match_offset);
+void report_index_match (int i, int match_offset);
 extern int index_entry_exists (FILE_BUFFER *fb, char *string);
 REFERENCE *look_in_indices (FILE_BUFFER *fb, char *string);
 

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-09-29 11:46:47 UTC (rev 5847)
+++ trunk/info/info.c   2014-09-29 13:33:16 UTC (rev 5848)
@@ -835,23 +835,29 @@
       if (index_search_p && initial_file && !user_output_filename)
         {
           initial_fb = info_find_file (initial_file);
-          if (initial_fb && index_entry_exists (initial_fb,
-                                                index_search_string))
+          if (initial_fb)
             {
-              initialize_info_session ();
-              do_info_index_search (windows, initial_fb, 0,
-                                    index_search_string);
-              info_read_and_dispatch ();
-              close_info_session ();
-              exit (0);
+              REFERENCE *result;
+              int i, match_offset;
+
+              next_index_match (initial_fb, index_search_string, 0, 1,
+                                  &result, &i, &match_offset);
+
+              if (result)
+                {
+                  initialize_info_session ();
+                  report_index_match (i, match_offset);
+                  info_select_reference (active_window, result);
+                  info_read_and_dispatch ();
+                  close_info_session ();
+                  exit (0);
+                }
             }
-          else
-            {
-              fprintf (stderr, _("no index entries found for '%s'\n"),
-                       index_search_string);
-              close_dribble_file ();
-              exit (1);
-            }
+
+          fprintf (stderr, _("no index entries found for '%s'\n"),
+                   index_search_string);
+          close_dribble_file ();
+          exit (1);
         }
 
       /* Add nodes to start with (unless we fell back to the man page). */




reply via email to

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