public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] TUI: Expand TABs into spaces
@ 2015-01-03 11:30 Eli Zaretskii
  2015-01-16 11:17 ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2015-01-03 11:30 UTC (permalink / raw)
  To: gdb-patches

"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;

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-01-31  8:57 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-03 11:30 [PATCH] TUI: Expand TABs into spaces Eli Zaretskii
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).