Remove tui_expand_tabs
tui_expand_tabs only has a single caller. This patch removes this function, in favor of a tab-expanding variant of string_file. This simplifies the code somewhat. gdb/ChangeLog 2020-07-01 Tom Tromey <tom@tromey.com> * tui/tui-regs.h (struct tui_data_item_window) <content>: Now a std::string. * tui/tui-regs.c (class tab_expansion_file): New. (tab_expansion_file::write): New method. (tui_register_format): Change return type. Use tab_expansion_file. (tui_get_register, tui_data_window::display_registers_from) (tui_data_item_window::rerender): Update. * tui/tui-io.h (tui_expand_tabs): Don't declare. * tui/tui-io.c (tui_expand_tabs): Remove.
This commit is contained in:
parent
ea68593bd2
commit
7a02bab704
@ -1,3 +1,16 @@
|
|||||||
|
2020-07-01 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* tui/tui-regs.h (struct tui_data_item_window) <content>: Now a
|
||||||
|
std::string.
|
||||||
|
* tui/tui-regs.c (class tab_expansion_file): New.
|
||||||
|
(tab_expansion_file::write): New method.
|
||||||
|
(tui_register_format): Change return type. Use
|
||||||
|
tab_expansion_file.
|
||||||
|
(tui_get_register, tui_data_window::display_registers_from)
|
||||||
|
(tui_data_item_window::rerender): Update.
|
||||||
|
* tui/tui-io.h (tui_expand_tabs): Don't declare.
|
||||||
|
* tui/tui-io.c (tui_expand_tabs): Remove.
|
||||||
|
|
||||||
2020-07-01 Tom Tromey <tom@tromey.com>
|
2020-07-01 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* tui/tui-regs.c (tui_reggroup_completer): Use complete_on_enum.
|
* tui/tui-regs.c (tui_reggroup_completer): Use complete_on_enum.
|
||||||
|
@ -1050,55 +1050,3 @@ tui_getc (FILE *fp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See tui-io.h. */
|
|
||||||
|
|
||||||
gdb::unique_xmalloc_ptr<char>
|
|
||||||
tui_expand_tabs (const char *string)
|
|
||||||
{
|
|
||||||
int n_adjust, ncol;
|
|
||||||
const char *s;
|
|
||||||
char *ret, *q;
|
|
||||||
|
|
||||||
/* 1. How many additional characters do we need? */
|
|
||||||
for (ncol = 0, n_adjust = 0, s = string; s; )
|
|
||||||
{
|
|
||||||
s = strpbrk (s, "\t");
|
|
||||||
if (s)
|
|
||||||
{
|
|
||||||
ncol += (s - string) + n_adjust;
|
|
||||||
/* Adjustment for the next tab stop, minus one for the TAB
|
|
||||||
we replace with spaces. */
|
|
||||||
n_adjust += 8 - (ncol % 8) - 1;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate the copy. */
|
|
||||||
ret = q = (char *) xmalloc (strlen (string) + n_adjust + 1);
|
|
||||||
|
|
||||||
/* 2. Copy the original string while replacing TABs with spaces. */
|
|
||||||
for (ncol = 0, s = string; s; )
|
|
||||||
{
|
|
||||||
const char *s1 = strpbrk (s, "\t");
|
|
||||||
if (s1)
|
|
||||||
{
|
|
||||||
if (s1 > s)
|
|
||||||
{
|
|
||||||
strncpy (q, s, s1 - s);
|
|
||||||
q += s1 - s;
|
|
||||||
ncol += s1 - s;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
*q++ = ' ';
|
|
||||||
ncol++;
|
|
||||||
} while ((ncol % 8) != 0);
|
|
||||||
s1++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy (q, s);
|
|
||||||
s = s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gdb::unique_xmalloc_ptr<char> (ret);
|
|
||||||
}
|
|
||||||
|
@ -45,9 +45,6 @@ extern void tui_initialize_io (void);
|
|||||||
changed the edited text. */
|
changed the edited text. */
|
||||||
extern void tui_redisplay_readline (void);
|
extern void tui_redisplay_readline (void);
|
||||||
|
|
||||||
/* Expand TABs into spaces. */
|
|
||||||
extern gdb::unique_xmalloc_ptr<char> tui_expand_tabs (const char *);
|
|
||||||
|
|
||||||
/* Enter/leave reverse video mode. */
|
/* Enter/leave reverse video mode. */
|
||||||
extern void tui_set_reverse_mode (WINDOW *w, bool reverse);
|
extern void tui_set_reverse_mode (WINDOW *w, bool reverse);
|
||||||
|
|
||||||
|
@ -42,15 +42,55 @@
|
|||||||
|
|
||||||
#include "gdb_curses.h"
|
#include "gdb_curses.h"
|
||||||
|
|
||||||
|
/* A subclass of string_file that expands tab characters. */
|
||||||
|
class tab_expansion_file : public string_file
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
tab_expansion_file () = default;
|
||||||
|
|
||||||
|
void write (const char *buf, long length_buf) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int m_column = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
tab_expansion_file::write (const char *buf, long length_buf)
|
||||||
|
{
|
||||||
|
for (long i = 0; i < length_buf; ++i)
|
||||||
|
{
|
||||||
|
if (buf[i] == '\t')
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
string_file::write (" ", 1);
|
||||||
|
++m_column;
|
||||||
|
}
|
||||||
|
while ((m_column % 8) != 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string_file::write (&buf[i], 1);
|
||||||
|
if (buf[i] == '\n')
|
||||||
|
m_column = 0;
|
||||||
|
else
|
||||||
|
++m_column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the register from the frame and return a printable
|
/* Get the register from the frame and return a printable
|
||||||
representation of it. */
|
representation of it. */
|
||||||
|
|
||||||
static gdb::unique_xmalloc_ptr<char>
|
static std::string
|
||||||
tui_register_format (struct frame_info *frame, int regnum)
|
tui_register_format (struct frame_info *frame, int regnum)
|
||||||
{
|
{
|
||||||
struct gdbarch *gdbarch = get_frame_arch (frame);
|
struct gdbarch *gdbarch = get_frame_arch (frame);
|
||||||
|
|
||||||
string_file stream;
|
/* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */
|
||||||
|
tab_expansion_file stream;
|
||||||
|
|
||||||
scoped_restore save_pagination
|
scoped_restore save_pagination
|
||||||
= make_scoped_restore (&pagination_enabled, 0);
|
= make_scoped_restore (&pagination_enabled, 0);
|
||||||
@ -64,8 +104,7 @@ tui_register_format (struct frame_info *frame, int regnum)
|
|||||||
if (!str.empty () && str.back () == '\n')
|
if (!str.empty () && str.back () == '\n')
|
||||||
str.resize (str.size () - 1);
|
str.resize (str.size () - 1);
|
||||||
|
|
||||||
/* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */
|
return str;
|
||||||
return tui_expand_tabs (str.c_str ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the register value from the given frame and format it for the
|
/* Get the register value from the given frame and format it for the
|
||||||
@ -80,11 +119,9 @@ tui_get_register (struct frame_info *frame,
|
|||||||
*changedp = false;
|
*changedp = false;
|
||||||
if (target_has_registers)
|
if (target_has_registers)
|
||||||
{
|
{
|
||||||
gdb::unique_xmalloc_ptr<char> new_content
|
std::string new_content = tui_register_format (frame, regnum);
|
||||||
= tui_register_format (frame, regnum);
|
|
||||||
|
|
||||||
if (changedp != NULL
|
if (changedp != NULL && data->content != new_content)
|
||||||
&& strcmp (data->content.get (), new_content.get ()) != 0)
|
|
||||||
*changedp = true;
|
*changedp = true;
|
||||||
|
|
||||||
data->content = std::move (new_content);
|
data->content = std::move (new_content);
|
||||||
@ -244,13 +281,7 @@ tui_data_window::display_registers_from (int start_element_no)
|
|||||||
int max_len = 0;
|
int max_len = 0;
|
||||||
for (auto &&data_item_win : m_regs_content)
|
for (auto &&data_item_win : m_regs_content)
|
||||||
{
|
{
|
||||||
const char *p;
|
int len = data_item_win.content.size ();
|
||||||
int len;
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
p = data_item_win.content.get ();
|
|
||||||
if (p != 0)
|
|
||||||
len = strlen (p);
|
|
||||||
|
|
||||||
if (len > max_len)
|
if (len > max_len)
|
||||||
max_len = len;
|
max_len = len;
|
||||||
@ -488,8 +519,7 @@ tui_data_item_window::rerender ()
|
|||||||
for (i = 1; i < width; i++)
|
for (i = 1; i < width; i++)
|
||||||
waddch (handle.get (), ' ');
|
waddch (handle.get (), ' ');
|
||||||
wmove (handle.get (), 0, 0);
|
wmove (handle.get (), 0, 0);
|
||||||
if (content)
|
waddstr (handle.get (), content.c_str ());
|
||||||
waddstr (handle.get (), content.get ());
|
|
||||||
|
|
||||||
if (highlight)
|
if (highlight)
|
||||||
/* We ignore the return value, casting it to void in order to avoid
|
/* We ignore the return value, casting it to void in order to avoid
|
||||||
|
@ -52,7 +52,7 @@ struct tui_data_item_window : public tui_gen_win_info
|
|||||||
/* The register number, or data display number. */
|
/* The register number, or data display number. */
|
||||||
int item_no = -1;
|
int item_no = -1;
|
||||||
bool highlight = false;
|
bool highlight = false;
|
||||||
gdb::unique_xmalloc_ptr<char> content;
|
std::string content;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The TUI registers window. */
|
/* The TUI registers window. */
|
||||||
|
Loading…
Reference in New Issue
Block a user