]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Clean up tui_layout_command
authorTom Tromey <tom@tromey.com>
Mon, 1 Jul 2019 02:43:32 +0000 (20:43 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 17 Jul 2019 18:19:15 +0000 (12:19 -0600)
tui_layout_command is a simple wrapper for tui_set_layout_by_name.
This removes the extra layer and cleans up the resulting function a
bit -- changing it to call error rather than return a result.  This
necessitated a small change to tui-regs.c, to avoid calling the
function that is being removed.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

* tui/tui.h (tui_set_layout_by_name): Don't declare.
* tui/tui-regs.c (tui_reg_layout): New function.
(tui_show_registers, tui_reg_command): Use it.
* tui/tui-layout.c (LAYOUT_USAGE): Remove.
(tui_layout_command): Rename from tui_set_layout_by_name.  Change
parameters.
(tui_layout_command): Remove.

gdb/ChangeLog
gdb/tui/tui-layout.c
gdb/tui/tui-regs.c
gdb/tui/tui.h

index 4dce3ac6aff1e8c5e3a2221914048df418c4f6b4..d9645201a1abf44fe6e339505ef1722f805704d8 100644 (file)
@@ -1,3 +1,13 @@
+2019-07-17  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui.h (tui_set_layout_by_name): Don't declare.
+       * tui/tui-regs.c (tui_reg_layout): New function.
+       (tui_show_registers, tui_reg_command): Use it.
+       * tui/tui-layout.c (LAYOUT_USAGE): Remove.
+       (tui_layout_command): Rename from tui_set_layout_by_name.  Change
+       parameters.
+       (tui_layout_command): Remove.
+
 2019-07-17  Tom Tromey  <tom@tromey.com>
 
        * tui/tui-layout.h (tui/tui-layout): Return void.
index 7feadd71ece266fe17021c8ce7c4d97fad610e5a..0ed7b29ce4b2560caeedadf665351f37672b22a8 100644 (file)
@@ -61,8 +61,6 @@ static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
 ** DEFINITIONS
 ***************************************/
 
-#define LAYOUT_USAGE     "Usage: layout prev | next | <layout_name> \n"
-
 /* Show the screen layout defined.  */
 static void
 show_layout (enum tui_layout_type layout)
@@ -361,63 +359,49 @@ Layout names are:\n\
 
 /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or
    REGS. */
-enum tui_status
-tui_set_layout_by_name (const char *layout_name)
+static void
+tui_layout_command (const char *layout_name, int from_tty)
 {
-  enum tui_status status = TUI_SUCCESS;
+  int i;
+  enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
+  enum tui_layout_type cur_layout = tui_current_layout ();
 
-  if (layout_name != NULL)
-    {
-      int i;
-      enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
-      enum tui_layout_type cur_layout = tui_current_layout ();
+  if (layout_name == NULL)
+    error (_("Usage: layout prev | next | LAYOUT-NAME"));
 
-      std::string copy = layout_name;
-      for (i = 0; i < copy.size (); i++)
-       copy[i] = toupper (copy[i]);
-      const char *buf_ptr = copy.c_str ();
+  std::string copy = layout_name;
+  for (i = 0; i < copy.size (); i++)
+    copy[i] = toupper (copy[i]);
+  const char *buf_ptr = copy.c_str ();
 
-      /* First check for ambiguous input.  */
-      if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
-       {
-         warning (_("Ambiguous command input."));
-         status = TUI_FAILURE;
-       }
-      else
-       {
-         if (subset_compare (buf_ptr, "SRC"))
-           new_layout = SRC_COMMAND;
-         else if (subset_compare (buf_ptr, "ASM"))
-           new_layout = DISASSEM_COMMAND;
-         else if (subset_compare (buf_ptr, "SPLIT"))
-           new_layout = SRC_DISASSEM_COMMAND;
-         else if (subset_compare (buf_ptr, "REGS"))
-           {
-             if (cur_layout == SRC_COMMAND
-                 || cur_layout == SRC_DATA_COMMAND)
-               new_layout = SRC_DATA_COMMAND;
-             else
-               new_layout = DISASSEM_DATA_COMMAND;
-           }
-         else if (subset_compare (buf_ptr, "NEXT"))
-           new_layout = next_layout ();
-         else if (subset_compare (buf_ptr, "PREV"))
-           new_layout = prev_layout ();
-         else
-           status = TUI_FAILURE;
+  /* First check for ambiguous input.  */
+  if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
+    error (_("Ambiguous command input."));
 
-         if (status == TUI_SUCCESS)
-           {
-             /* Make sure the curses mode is enabled.  */
-             tui_enable ();
-             tui_set_layout (new_layout);
-           }
-       }
+  if (subset_compare (buf_ptr, "SRC"))
+    new_layout = SRC_COMMAND;
+  else if (subset_compare (buf_ptr, "ASM"))
+    new_layout = DISASSEM_COMMAND;
+  else if (subset_compare (buf_ptr, "SPLIT"))
+    new_layout = SRC_DISASSEM_COMMAND;
+  else if (subset_compare (buf_ptr, "REGS"))
+    {
+      if (cur_layout == SRC_COMMAND
+         || cur_layout == SRC_DATA_COMMAND)
+       new_layout = SRC_DATA_COMMAND;
+      else
+       new_layout = DISASSEM_DATA_COMMAND;
     }
+  else if (subset_compare (buf_ptr, "NEXT"))
+    new_layout = next_layout ();
+  else if (subset_compare (buf_ptr, "PREV"))
+    new_layout = prev_layout ();
   else
-    status = TUI_FAILURE;
+    error (_("Unrecognized layout: %s"), layout_name);
 
-  return status;
+  /* Make sure the curses mode is enabled.  */
+  tui_enable ();
+  tui_set_layout (new_layout);
 }
 
 
@@ -456,14 +440,6 @@ extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
 }
 
 
-static void
-tui_layout_command (const char *arg, int from_tty)
-{
-  /* Switch to the selected layout.  */
-  if (tui_set_layout_by_name (arg) != TUI_SUCCESS)
-    warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
-}
-
 /* Answer the previous layout to cycle to.  */
 static enum tui_layout_type
 next_layout (void)
index 70e7763951218c2e7e750f2a8d215efa9fd891f3..382a44126d37fda2f45c15c42627777bd78dea63 100644 (file)
@@ -115,6 +115,20 @@ tui_data_window::first_reg_element_no_inline (int line_no) const
     return (-1);
 }
 
+/* A helper function to display the register window in the appropriate
+   way.  */
+
+static void
+tui_reg_layout ()
+{
+  enum tui_layout_type cur_layout = tui_current_layout ();
+  enum tui_layout_type new_layout;
+  if (cur_layout == SRC_COMMAND || cur_layout == SRC_DATA_COMMAND)
+    new_layout = SRC_DATA_COMMAND;
+  else
+    new_layout = DISASSEM_DATA_COMMAND;
+  tui_set_layout (new_layout);
+}
 
 /* Show the registers of the given group in the data window
    and refresh the window.  */
@@ -127,7 +141,7 @@ tui_show_registers (struct reggroup *group)
   /* Make sure the register window is visible.  If not, select an
      appropriate layout.  */
   if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible)
-    tui_set_layout_by_name (DATA_NAME);
+    tui_reg_layout ();
 
   if (group == 0)
     group = general_reggroup;
@@ -512,7 +526,7 @@ tui_reg_command (const char *args, int from_tty)
         appropriate layout.  We need to do this before trying to run the
         'next' or 'prev' commands.  */
       if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible)
-       tui_set_layout_by_name (DATA_NAME);
+       tui_reg_layout ();
 
       struct reggroup *current_group = NULL;
       if (TUI_DATA_WIN != NULL)
index 69ad60c98bf5140bdd803ac41612cd45408be0a2..76ab01443b70825fd33d8cce646d1d70837ff0b8 100644 (file)
@@ -90,7 +90,4 @@ extern int tui_active;
 
 extern void tui_show_source (const char *fullname, int line);
 
-/* tui-layout.c */
-extern enum tui_status tui_set_layout_by_name (const char *);
-
 #endif /* TUI_TUI_H */