This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: completion -vs- duplicates


Right now the `complete' command can print duplicates.  readline seems
to filter these, so you don't see this using Tab in the CLI, but you
can see it in Insight or by using the complete command.

E.g., run gdb on itself and type "complete b captured_ma".
I see `b captured_main' and `b captured_main_args' repeated many
times.

This patch fixes completion to uniquify the result list.

Ok to commit?

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* completer.c (compare_strings): New function.
	(line_completion_function): Make result list have unique
	elements.

Index: completer.c
===================================================================
RCS file: /cvs/src/src/gdb/completer.c,v
retrieving revision 1.8
diff -u -r1.8 completer.c
--- completer.c 2001/07/15 18:57:06 1.8
+++ completer.c 2002/01/04 23:52:18
@@ -339,6 +339,15 @@
   return list;
 }
 
+/* String compare function for qsort.  */
+static int
+compare_strings (const void *arg1, const void *arg2)
+{
+  const char **s1 = (const char **) arg1;
+  const char **s2 = (const char **) arg2;
+  return strcmp (*s1, *s2);
+}
+
 /* Here are some useful test cases for completion.  FIXME: These should
    be put in the test suite.  They should be tested with both M-? and TAB.
 
@@ -620,6 +629,30 @@
 		  list = (*c->completer) (p, word);
 		}
 	    }
+	}
+
+      /* Make sure each item in the list is unique.  */
+      if (list)
+	{
+	  int src, dest, size;
+
+	  for (size = 0; list[size]; ++size)
+	    ;
+	  qsort (list, size, sizeof (char *), compare_strings);
+
+	  src = 0;
+	  dest = 0;
+	  while (src < size)
+	    {
+	      list[dest] = list[src++];
+	      while (src < size && ! strcmp (list[dest], list[src]))
+		{
+		  xfree (list[src]);
+		  ++src;
+		}
+	      ++dest;
+	    }
+	  list[dest] = NULL;
 	}
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]