record-full: Remove unused function netorder16
[deliverable/binutils-gdb.git] / gdb / tui / tui-win.c
index 683097717646ef05636c1a2da842d57cdfd0bbaf..f49d7d5b87e0d090be54ce42bbf4622b19da8a76 100644 (file)
@@ -1,6 +1,6 @@
 /* TUI window generic functions.
 
-   Copyright (C) 1998-2015 Free Software Foundation, Inc.
+   Copyright (C) 1998-2017 Free Software Foundation, Inc.
 
    Contributed by Hewlett-Packard Company.
 
@@ -354,6 +354,85 @@ tui_set_var_cmd (char *null_args, int from_tty, struct cmd_list_element *c)
     tui_rehighlight_all ();
 }
 
+/* Generic window name completion function.  Complete window name pointed
+   to by TEXT and WORD.  If INCLUDE_NEXT_PREV_P is true then the special
+   window names 'next' and 'prev' will also be considered as possible
+   completions of the window name.  */
+
+static VEC (char_ptr) *
+window_name_completer (int include_next_prev_p,
+                      const char *text, const char *word)
+{
+  VEC (const_char_ptr) *completion_name_vec = NULL;
+  VEC (char_ptr) *matches_vec;
+  int win_type;
+
+  for (win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++)
+    {
+      const char *completion_name = NULL;
+
+      /* We can't focus on an invisible window.  */
+      if (tui_win_list[win_type] == NULL
+         || !tui_win_list[win_type]->generic.is_visible)
+       continue;
+
+      completion_name = tui_win_name (&tui_win_list [win_type]->generic);
+      gdb_assert (completion_name != NULL);
+      VEC_safe_push (const_char_ptr, completion_name_vec, completion_name);
+    }
+
+  /* If no windows are considered visible then the TUI has not yet been
+     initialized.  But still "focus src" and "focus cmd" will work because
+     invoking the focus command will entail initializing the TUI which sets the
+     default layout to SRC_COMMAND.  */
+  if (VEC_length (const_char_ptr, completion_name_vec) == 0)
+    {
+      VEC_safe_push (const_char_ptr, completion_name_vec, SRC_NAME);
+      VEC_safe_push (const_char_ptr, completion_name_vec, CMD_NAME);
+    }
+
+  if (include_next_prev_p)
+    {
+      VEC_safe_push (const_char_ptr, completion_name_vec, "next");
+      VEC_safe_push (const_char_ptr, completion_name_vec, "prev");
+    }
+
+  VEC_safe_push (const_char_ptr, completion_name_vec, NULL);
+  matches_vec
+    = complete_on_enum (VEC_address (const_char_ptr, completion_name_vec),
+                       text, word);
+
+  VEC_free (const_char_ptr, completion_name_vec);
+
+  return matches_vec;
+}
+
+/* Complete possible window names to focus on.  TEXT is the complete text
+   entered so far, WORD is the word currently being completed.  */
+
+static VEC (char_ptr) *
+focus_completer (struct cmd_list_element *ignore,
+                 const char *text, const char *word)
+{
+  return window_name_completer (1, text, word);
+}
+
+/* Complete possible window names for winheight command.  TEXT is the
+   complete text entered so far, WORD is the word currently being
+   completed.  */
+
+static VEC (char_ptr) *
+winheight_completer (struct cmd_list_element *ignore,
+                    const char *text, const char *word)
+{
+  /* The first word is the window name.  That we can complete.  Subsequent
+     words can't be completed.  */
+  if (word != text)
+    return NULL;
+
+  return window_name_completer (0, text, word);
+}
+
 /* Function to initialize gdb commands, for tui window
    manipulation.  */
 
@@ -365,6 +444,7 @@ _initialize_tui_win (void)
 {
   static struct cmd_list_element *tui_setlist;
   static struct cmd_list_element *tui_showlist;
+  struct cmd_list_element *cmd;
 
   /* Define the classes of commands.
      They will appear in the help list in the reverse of this order.  */
@@ -382,8 +462,8 @@ _initialize_tui_win (void)
   add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
 Set the width (in characters) of tab stops.\n\
 Usage: tabset <n>\n"));
-  add_com ("winheight", class_tui, tui_set_win_height_command, _("\
-Set the height of a specified window.\n\
+  cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
+Set or modify the height of a specified window.\n\
 Usage: winheight <win_name> [+ | -] <#lines>\n\
 Window names are:\n\
 src  : the source window\n\
@@ -391,9 +471,10 @@ cmd  : the command window\n\
 asm  : the disassembly window\n\
 regs : the register display\n"));
   add_com_alias ("wh", "winheight", class_tui, 0);
+  set_cmd_completer (cmd, winheight_completer);
   add_info ("win", tui_all_windows_info,
            _("List of all displayed windows.\n"));
-  add_com ("focus", class_tui, tui_set_focus_command, _("\
+  cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
 Set focus to named window or next/prev window.\n\
 Usage: focus {<win> | next | prev}\n\
 Valid Window names are:\n\
@@ -402,6 +483,7 @@ asm  : the disassembly window\n\
 regs : the register display\n\
 cmd  : the command window\n"));
   add_com_alias ("fs", "focus", class_tui, 0);
+  set_cmd_completer (cmd, focus_completer);
   add_com ("+", class_tui, tui_scroll_forward_command, _("\
 Scroll window forward.\n\
 Usage: + [win] [n]\n"));
@@ -818,7 +900,7 @@ tui_resize_all (void)
              && !tui_win_list[win_type]->generic.is_visible)
            {
              tui_free_window (tui_win_list[win_type]);
-             tui_win_list[win_type] = (struct tui_win_info *) NULL;
+             tui_win_list[win_type] = NULL;
            }
        }
       /* Turn keypad back on, unless focus is in the command
@@ -836,12 +918,6 @@ static struct async_signal_handler *tui_sigwinch_token;
 static void
 tui_sigwinch_handler (int signal)
 {
-  /* Set win_resized to TRUE and asynchronously invoke our resize callback.  If
-     the callback is invoked while TUI is active then it ought to successfully
-     resize the screen, resetting win_resized to FALSE.  Of course, if the
-     callback is invoked while TUI is inactive then it will do nothing; in that
-     case, win_resized will remain TRUE until we get a chance to synchronously
-     resize the screen from tui_enable().  */
   mark_async_signal_handler (tui_sigwinch_token);
   tui_set_win_resized_to (TRUE);
 }
@@ -850,15 +926,26 @@ tui_sigwinch_handler (int signal)
 static void
 tui_async_resize_screen (gdb_client_data arg)
 {
+  rl_resize_terminal ();
+
   if (!tui_active)
-    return;
+    {
+      int screen_height, screen_width;
 
-  rl_resize_terminal ();
-  tui_resize_all ();
-  tui_refresh_all_win ();
-  tui_update_gdb_sizes ();
-  tui_set_win_resized_to (FALSE);
-  tui_redisplay_readline ();
+      rl_get_screen_size (&screen_height, &screen_width);
+      set_screen_width_and_height (screen_width, screen_height);
+
+      /* win_resized is left set so that the next call to tui_enable()
+        resizes the TUI windows.  */
+    }
+  else
+    {
+      tui_set_win_resized_to (FALSE);
+      tui_resize_all ();
+      tui_refresh_all_win ();
+      tui_update_gdb_sizes ();
+      tui_redisplay_readline ();
+    }
 }
 #endif
 
@@ -961,14 +1048,14 @@ tui_set_focus (char *arg, int from_tty)
     {
       char *buf_ptr = (char *) xstrdup (arg);
       int i;
-      struct tui_win_info *win_info = (struct tui_win_info *) NULL;
+      struct tui_win_info *win_info = NULL;
 
       for (i = 0; (i < strlen (buf_ptr)); i++)
-       buf_ptr[i] = toupper (arg[i]);
+       buf_ptr[i] = tolower (arg[i]);
 
-      if (subset_compare (buf_ptr, "NEXT"))
+      if (subset_compare (buf_ptr, "next"))
        win_info = tui_next_win (tui_win_with_focus ());
-      else if (subset_compare (buf_ptr, "PREV"))
+      else if (subset_compare (buf_ptr, "prev"))
        win_info = tui_prev_win (tui_win_with_focus ());
       else
        win_info = tui_partial_win_by_name (buf_ptr);
@@ -987,8 +1074,7 @@ The window name specified must be valid and visible.\n"));
        tui_refresh_data_win ();
       xfree (buf_ptr);
       printf_filtered (_("Focus set to %s window.\n"),
-                      tui_win_name ((struct tui_gen_win_info *)
-                                    tui_win_with_focus ()));
+                      tui_win_name (&tui_win_with_focus ()->generic));
     }
   else
     warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
@@ -1084,10 +1170,12 @@ tui_set_win_height (char *arg, int from_tty)
     {
       char *buf = xstrdup (arg);
       char *buf_ptr = buf;
-      char *wname = (char *) NULL;
+      char *wname = NULL;
       int new_height, i;
       struct tui_win_info *win_info;
+      struct cleanup *old_chain;
 
+      old_chain = make_cleanup (xfree, buf);
       wname = buf_ptr;
       buf_ptr = strchr (buf_ptr, ' ');
       if (buf_ptr != (char *) NULL)
@@ -1096,7 +1184,7 @@ tui_set_win_height (char *arg, int from_tty)
 
          /* Validate the window name.  */
          for (i = 0; i < strlen (wname); i++)
-           wname[i] = toupper (wname[i]);
+           wname[i] = tolower (wname[i]);
          win_info = tui_partial_win_by_name (wname);
 
          if (win_info == (struct tui_win_info *) NULL
@@ -1150,8 +1238,7 @@ The window name specified must be valid and visible.\n"));
       else
        printf_filtered (WIN_HEIGHT_USAGE);
 
-      if (buf != (char *) NULL)
-       xfree (buf);
+      do_cleanups (old_chain);
     }
   else
     printf_filtered (WIN_HEIGHT_USAGE);
@@ -1370,7 +1457,7 @@ make_invisible_and_set_new_height (struct tui_win_info *win_info,
            &((struct tui_win_element *)
              win_info->generic.content[i])->which_element.data_window;
          tui_delete_win (gen_win_info->handle);
-         gen_win_info->handle = (WINDOW *) NULL;
+         gen_win_info->handle = NULL;
        }
       break;
     default:
@@ -1438,8 +1525,6 @@ make_visible_with_new_height (struct tui_win_info *win_info)
       tui_display_all_data ();
       break;
     case CMD_WIN:
-      win_info->detail.command_info.cur_line = 0;
-      win_info->detail.command_info.curch = 0;
 #ifdef HAVE_WRESIZE
       wresize (TUI_CMD_WIN->generic.handle,
               TUI_CMD_WIN->generic.height,
@@ -1448,9 +1533,7 @@ make_visible_with_new_height (struct tui_win_info *win_info)
       mvwin (TUI_CMD_WIN->generic.handle,
             TUI_CMD_WIN->generic.origin.y,
             TUI_CMD_WIN->generic.origin.x);
-      wmove (win_info->generic.handle,
-            win_info->detail.command_info.cur_line,
-            win_info->detail.command_info.curch);
+      wmove (win_info->generic.handle, 0, 0);
       break;
     default:
       break;
@@ -1582,9 +1665,11 @@ parse_scrolling_args (char *arg,
   if (arg != (char *) NULL)
     {
       char *buf, *buf_ptr;
+      struct cleanup *old_chain;
 
       /* Process the number of lines to scroll.  */
       buf = buf_ptr = xstrdup (arg);
+      old_chain = make_cleanup (xfree, buf);
       if (isdigit (*buf_ptr))
        {
          char *num_str;
@@ -1605,8 +1690,7 @@ parse_scrolling_args (char *arg,
       /* Process the window name if one is specified.  */
       if (buf_ptr != (char *) NULL)
        {
-         char *wname;
-         int i;
+         const char *wname;
 
          if (*buf_ptr == ' ')
            while (*(++buf_ptr) == ' ')
@@ -1614,11 +1698,11 @@ parse_scrolling_args (char *arg,
 
          if (*buf_ptr != (char) 0)
            {
-             wname = buf_ptr;
-
              /* Validate the window name.  */
-             for (i = 0; i < strlen (wname); i++)
-               wname[i] = toupper (wname[i]);
+             for (char *p = buf_ptr; *p != '\0'; p++)
+               *p = tolower (*p);
+
+             wname = buf_ptr;
            }
          else
            wname = "?";
@@ -1632,6 +1716,6 @@ The window name specified must be valid and visible.\n"));
          else if (*win_to_scroll == TUI_CMD_WIN)
            *win_to_scroll = (tui_source_windows ())->list[0];
        }
-      xfree (buf);
+      do_cleanups (old_chain);
     }
 }
This page took 0.028023 seconds and 4 git commands to generate.