From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14361 invoked by alias); 3 Jan 2015 11:30:16 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 14347 invoked by uid 89); 3 Jan 2015 11:30:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: mtaout29.012.net.il Received: from mtaout29.012.net.il (HELO mtaout29.012.net.il) (80.179.55.185) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 03 Jan 2015 11:30:13 +0000 Received: from conversion-daemon.mtaout29.012.net.il by mtaout29.012.net.il (HyperSendmail v2007.08) id <0NHL00I00LVER600@mtaout29.012.net.il> for gdb-patches@sourceware.org; Sat, 03 Jan 2015 13:27:12 +0200 (IST) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout29.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NHL00KXRMHC8F40@mtaout29.012.net.il> for gdb-patches@sourceware.org; Sat, 03 Jan 2015 13:27:12 +0200 (IST) Date: Sat, 03 Jan 2015 11:30:00 -0000 From: Eli Zaretskii Subject: [PATCH] TUI: Expand TABs into spaces To: gdb-patches@sourceware.org Reply-to: Eli Zaretskii Message-id: <83k3149k5b.fsf@gnu.org> X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00021.txt.bz2 "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 * 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;