From: Eli Zaretskii <eliz@gnu.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] TUI: Expand TABs into spaces
Date: Sat, 03 Jan 2015 11:30:00 -0000 [thread overview]
Message-ID: <83k3149k5b.fsf@gnu.org> (raw)
"gdb -tui" relies on the curses library and the underlying terminal
driver to expand TAB characters into spaces. But ncurses on Windows
doesn't do that, and instead displays an IBM graphics character.
The patches below fix that in the command window and in displaying the
registers.
OK to commit?
2015-01-03 Eli Zaretskii <eliz@gnu.org>
* tui/tui-regs.c (tui_register_format): Expand TABs into the
appropriate number of spaces.
* tui/tui-io.c (tui_puts, tui_redisplay_readline): Expand TABs
into the appropriate number of spaces.
--- gdb/tui/tui-io.c~0 2014-10-29 21:45:50.000000000 +0200
+++ gdb/tui/tui-io.c 2015-01-03 11:12:52.187500000 +0200
@@ -179,7 +179,19 @@ tui_puts (const char *string)
else if (tui_skip_line != 1)
{
tui_skip_line = -1;
- waddch (w, c);
+ if (c == '\t')
+ {
+ int line, col;
+
+ getyx (w, line, col);
+ do
+ {
+ waddch (w, ' ');
+ col++;
+ } while ((col % 8) != 0);
+ }
+ else
+ waddch (w, c);
}
else if (c == '\n')
tui_skip_line = -1;
@@ -254,6 +266,15 @@ tui_redisplay_readline (void)
waddch (w, '^');
waddch (w, CTRL_CHAR (c) ? UNCTRL (c) : '?');
}
+ else if (c == '\t')
+ {
+ getyx (w, line, col);
+ do
+ {
+ waddch (w, ' ');
+ col++;
+ } while ((col % 8) != 0);
+ }
else
{
waddch (w, c);
--- gdb/tui/tui-regs.c~0 2014-10-29 21:45:50.000000000 +0200
+++ gdb/tui/tui-regs.c 2015-01-03 12:52:42.062500000 +0200
@@ -676,8 +676,9 @@ tui_register_format (struct frame_info *
struct ui_file *stream;
struct ui_file *old_stdout;
struct cleanup *cleanups;
- char *p, *s;
+ char *p, *s, *q;
char *ret;
+ int n_adjust, col;
pagination_enabled = 0;
old_stdout = gdb_stdout;
@@ -694,7 +695,47 @@ tui_register_format (struct frame_info *
if (s && s[1] == 0)
*s = 0;
- ret = xstrdup (p);
+ /* Expand tabs into spaces. */
+ /* 1. How many additional characters do we need? */
+ for (col = n_adjust = 0, s = p; s; )
+ {
+ s = strpbrk (s, "\t");
+ if (s)
+ {
+ col = (s - p) + n_adjust;
+ /* Adjustment for the next tab stop, minus one for the TAB
+ we replace with spaces. */
+ n_adjust += 8 - (col % 8) - 1;
+ s++;
+ }
+ }
+
+ /* Allocate the copy. */
+ ret = q = xmalloc (strlen (p) + n_adjust + 1);
+
+ /* 2. Copy the original string while replacing TABs with spaces. */
+ for (col = 0, s = p; s; )
+ {
+ char *s1 = strpbrk (s, "\t");
+ if (s1)
+ {
+ if (s1 > s)
+ {
+ strncpy (q, s, s1 - s);
+ q += s1 - s;
+ col += s1 - s;
+ }
+ do {
+ *q++ = ' ';
+ col++;
+ } while ((col % 8) != 0);
+ s1++;
+ }
+ else
+ strcpy (q, s);
+ s = s1;
+ }
+
do_cleanups (cleanups);
return ret;
next reply other threads:[~2015-01-03 11:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-03 11:30 Eli Zaretskii [this message]
2015-01-16 11:17 ` Eli Zaretskii
2015-01-16 16:32 ` Doug Evans
2015-01-16 16:43 ` Eli Zaretskii
2015-01-16 17:30 ` Doug Evans
2015-01-16 17:53 ` Eli Zaretskii
2015-01-16 18:25 ` Doug Evans
2015-01-16 20:11 ` Eli Zaretskii
2015-01-17 1:02 ` Doug Evans
2015-01-17 7:56 ` Eli Zaretskii
2015-01-24 14:15 ` Eli Zaretskii
2015-01-25 11:31 ` Doug Evans
2015-01-26 11:42 ` Eli Zaretskii
2015-01-27 11:17 ` Doug Evans
2015-01-31 21:08 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83k3149k5b.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox