Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Patch: completion -vs- duplicates
@ 2002-01-04 15:55 Tom Tromey
  2002-01-05  0:25 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2002-01-04 15:55 UTC (permalink / raw)
  To: gdb-patches

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;
 	}
     }


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-01-05 20:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-04 15:55 Patch: completion -vs- duplicates Tom Tromey
2002-01-05  0:25 ` Eli Zaretskii
2002-01-05  7:44   ` Daniel Berlin
2002-01-05 10:20     ` Tom Tromey
2002-01-05 10:34       ` Andrew Cagney
2002-01-05 12:37         ` Tom Tromey
2002-01-05 10:30     ` Daniel Jacobowitz
2002-01-05 10:37       ` Daniel Berlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox