Handle ambiguity in tui_partial_win_by_name
authorTom Tromey <tom@tromey.com>
Sat, 22 Feb 2020 18:48:26 +0000 (11:48 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 22 Feb 2020 18:48:36 +0000 (11:48 -0700)
This changes tui_partial_win_by_name to correctly handle an ambiguous
name prefix.  This will be important once the user can register new
window types.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

* tui/tui-win.c (tui_partial_win_by_name): Handle ambiguity
correctly.

Change-Id: I59aaacd697eeab649164183457ef722dae58d60d

gdb/ChangeLog
gdb/tui/tui-win.c

index 16daac356c5859e4cc4782b264bb33f681de780c..feb58334b00c2f4ec4ab13befd226103700d7a41 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-22  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui-win.c (tui_partial_win_by_name): Handle ambiguity
+       correctly.
+
 2020-02-22  Tom Tromey  <tom@tromey.com>
 
        * tui/tui-data.c (tui_next_win, tui_prev_win): Reimplement.
index ef78e91b6fe2d9e63457d32bd08efc6c70fa0cce..ea202757c884917912cf846c03562d559aa1d85b 100644 (file)
@@ -694,18 +694,27 @@ tui_scroll_right_command (const char *arg, int from_tty)
 static struct tui_win_info *
 tui_partial_win_by_name (gdb::string_view name)
 {
+  struct tui_win_info *best = nullptr;
+
   if (name != NULL)
     {
       for (tui_win_info *item : all_tui_windows ())
        {
          const char *cur_name = item->name ();
 
-         if (startswith (cur_name, name))
+         if (name == cur_name)
            return item;
+         if (startswith (cur_name, name))
+           {
+             if (best != nullptr)
+               error (_("Window name \"%*s\" is ambiguous"),
+                      (int) name.size (), name.data ());
+             best = item;
+           }
        }
     }
 
-  return NULL;
+  return best;
 }
 
 /* Set focus to the window named by 'arg'.  */
This page took 0.027574 seconds and 4 git commands to generate.