bug-texinfo
[Top][All Lists]
Advanced

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

Re: info --index not finding all indexed entries


From: Sergey Poznyakoff
Subject: Re: info --index not finding all indexed entries
Date: Sun, 08 Aug 2010 20:02:37 +0300

Hello,

The index matcher did not take into account possible <[0-9]+> after
the search string in the index (which should be treated as an exact
match), and ignored any partial matches that might have occurred before
the first exact one.

I have installed the enclosed patch.

Regards,
Sergey

Index: info/indices.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/indices.c,v
retrieving revision 1.11
diff -p -u -r1.11 indices.c
--- info/indices.c      11 Jun 2008 09:55:42 -0000      1.11
+++ info/indices.c      8 Aug 2010 16:48:56 -0000
@@ -31,6 +31,8 @@ static REFERENCE **index_index = NULL;
 
 /* The offset of the most recently selected index element. */
 static int index_offset = 0;
+/* Whether we are doing partial index search */
+static int index_partial = 0;
 
 /* Variable which holds the last string searched for. */
 static char *index_search = NULL;
@@ -259,8 +261,11 @@ do_info_index_search (WINDOW *window, in
         index_offset = i;
       }
     else
-      index_offset = -1;
-
+      {
+       index_offset = -1;
+       index_partial = 0;
+      }
+    
     old_offset = index_offset;
 
     /* The "last" string searched for is this one. */
@@ -320,13 +325,39 @@ index_entry_exists (WINDOW *window, char
   return 1;
 }
 
+/* Return true if ENT->label matches "S( <[0-9]+>)?", where S stands
+   for the first LEN characters from STR. */
+static int
+index_entry_matches (REFERENCE *ent, const char *str, size_t len)
+{
+  char *p;
+  
+  if (strncmp (ent->label, str, len))
+    return 0;
+  p = ent->label + len;
+  if (!*p)
+    return 1;
+  if (p[0] == ' ' && p[1] == '<')
+    {
+      for (p += 2; *p; p++)
+       {
+         if (p[0] == '>' && p[1] == 0)
+           return 1;
+         else if (!isdigit (*p))
+           return 0;
+       }
+    }
+  return 0;
+}
+
 DECLARE_INFO_COMMAND (info_next_index_match,
  _("Go to the next matching index item from the last `\\[index-search]' 
command"))
 {
   register int i;
   int partial, dir;
   NODE *node;
-
+  size_t search_len;
+  
   /* If there is no previous search string, the user hasn't built an index
      yet. */
   if (!index_search)
@@ -349,28 +380,43 @@ DECLARE_INFO_COMMAND (info_next_index_ma
   else
     dir = 1;
 
-  /* Search for the next occurence of index_search.  First try to find
-     an exact match. */
+  /* Search for the next occurence of index_search. */
   partial = 0;
+  search_len = strlen (index_search);
 
-  for (i = index_offset + dir; (i > -1) && (index_index[i]); i += dir)
-    if (strcmp (index_search, index_index[i]->label) == 0)
-      break;
-
-  /* If that failed, look for the next substring match. */
-  if ((i < 0) || (!index_index[i]))
+  if (!index_partial)
     {
+      /* First try to find an exact match. */
       for (i = index_offset + dir; (i > -1) && (index_index[i]); i += dir)
-        if (string_in_line (index_search, index_index[i]->label) != -1)
-          break;
+       if (index_entry_matches (index_index[i], index_search, search_len))
+         break;
 
-      if ((i > -1) && (index_index[i]))
-        partial = string_in_line (index_search, index_index[i]->label);
+      /* If that failed, look for the next substring match. */
+      if ((i < 0) || (!index_index[i]))
+       {
+         index_offset = 0;
+         index_partial = 1;
+       }
     }
 
+  if (index_partial)
+    {
+      /* When looking for substrings, take care not to return previous exact
+        matches. */
+      for (i = index_offset + dir; (i > -1) && (index_index[i]); i += dir)
+        if (!index_entry_matches (index_index[i], index_search, search_len) &&
+           string_in_line (index_search, index_index[i]->label) != -1)
+         {
+           partial = 1;
+           break;
+         }
+    }
+  index_partial = partial;
+  
   /* If that failed, print an error. */
   if ((i < 0) || (!index_index[i]))
     {
+      index_offset = 0;
       info_error (_("No %sindex entries containing `%s'."),
                   index_offset > 0 ? (char *) _("more ") : "", index_search);
       return;



reply via email to

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