Révision | 312809f8838911dabff84d7ad3ccf341307d2b19 (tree) |
---|---|
l'heure | 2015-01-31 17:47:14 |
Auteur | Eli Zaretskii <eliz@gnu....> |
Commiter | Eli Zaretskii |
Make sure TABs are expanded in TUI windows on MS-Windows.
gdb/
2015-01-31 Eli Zaretskii <eliz@gnu.org>
* tui/tui-io.c (tui_expand_tabs): New function.
(tui_puts, tui_redisplay_readline): Expand TABs into the
appropriate number of spaces.
* tui/tui-regs.c: Include tui-io.h.
(tui_register_format): Call tui_expand_tabs to expand TABs into
the appropriate number of spaces.
* tui/tui-io.h: Add prototype for tui_expand_tabs.
@@ -1,3 +1,13 @@ | ||
1 | +2015-01-31 Eli Zaretskii <eliz@gnu.org> | |
2 | + | |
3 | + * tui/tui-io.c (tui_expand_tabs): New function. | |
4 | + (tui_puts, tui_redisplay_readline): Expand TABs into the | |
5 | + appropriate number of spaces. | |
6 | + * tui/tui-regs.c: Include tui-io.h. | |
7 | + (tui_register_format): Call tui_expand_tabs to expand TABs into | |
8 | + the appropriate number of spaces. | |
9 | + * tui/tui-io.h: Add prototype for tui_expand_tabs. | |
10 | + | |
1 | 11 | 2015-01-30 Doug Evans <dje@google.com> |
2 | 12 | |
3 | 13 | * NEWS: "info source" command now display producer string if present. |
@@ -178,7 +178,20 @@ tui_puts (const char *string) | ||
178 | 178 | else if (tui_skip_line != 1) |
179 | 179 | { |
180 | 180 | tui_skip_line = -1; |
181 | - waddch (w, c); | |
181 | + /* Expand TABs, since ncurses on MS-Windows doesn't. */ | |
182 | + if (c == '\t') | |
183 | + { | |
184 | + int line, col; | |
185 | + | |
186 | + getyx (w, line, col); | |
187 | + do | |
188 | + { | |
189 | + waddch (w, ' '); | |
190 | + col++; | |
191 | + } while ((col % 8) != 0); | |
192 | + } | |
193 | + else | |
194 | + waddch (w, c); | |
182 | 195 | } |
183 | 196 | else if (c == '\n') |
184 | 197 | tui_skip_line = -1; |
@@ -256,6 +269,16 @@ tui_redisplay_readline (void) | ||
256 | 269 | waddch (w, '^'); |
257 | 270 | waddch (w, CTRL_CHAR (c) ? UNCTRL (c) : '?'); |
258 | 271 | } |
272 | + else if (c == '\t') | |
273 | + { | |
274 | + /* Expand TABs, since ncurses on MS-Windows doesn't. */ | |
275 | + getyx (w, line, col); | |
276 | + do | |
277 | + { | |
278 | + waddch (w, ' '); | |
279 | + col++; | |
280 | + } while ((col % 8) != 0); | |
281 | + } | |
259 | 282 | else |
260 | 283 | { |
261 | 284 | waddch (w, c); |
@@ -724,6 +747,59 @@ tui_getc (FILE *fp) | ||
724 | 747 | return ch; |
725 | 748 | } |
726 | 749 | |
750 | +/* Utility function to expand TABs in a STRING into spaces. STRING | |
751 | + will be displayed starting at column COL, and is assumed to include | |
752 | + no newlines. The returned expanded string is malloc'ed. */ | |
753 | + | |
754 | +char * | |
755 | +tui_expand_tabs (const char *string, int col) | |
756 | +{ | |
757 | + int n_adjust; | |
758 | + const char *s; | |
759 | + char *ret, *q; | |
760 | + | |
761 | + /* 1. How many additional characters do we need? */ | |
762 | + for (n_adjust = 0, s = string; s; ) | |
763 | + { | |
764 | + s = strpbrk (s, "\t"); | |
765 | + if (s) | |
766 | + { | |
767 | + col += (s - string) + n_adjust; | |
768 | + /* Adjustment for the next tab stop, minus one for the TAB | |
769 | + we replace with spaces. */ | |
770 | + n_adjust += 8 - (col % 8) - 1; | |
771 | + s++; | |
772 | + } | |
773 | + } | |
774 | + | |
775 | + /* Allocate the copy. */ | |
776 | + ret = q = xmalloc (strlen (string) + n_adjust + 1); | |
777 | + | |
778 | + /* 2. Copy the original string while replacing TABs with spaces. */ | |
779 | + for (s = string; s; ) | |
780 | + { | |
781 | + char *s1 = strpbrk (s, "\t"); | |
782 | + if (s1) | |
783 | + { | |
784 | + if (s1 > s) | |
785 | + { | |
786 | + strncpy (q, s, s1 - s); | |
787 | + q += s1 - s; | |
788 | + col += s1 - s; | |
789 | + } | |
790 | + do { | |
791 | + *q++ = ' '; | |
792 | + col++; | |
793 | + } while ((col % 8) != 0); | |
794 | + s1++; | |
795 | + } | |
796 | + else | |
797 | + strcpy (q, s); | |
798 | + s = s1; | |
799 | + } | |
800 | + | |
801 | + return ret; | |
802 | +} | |
727 | 803 | |
728 | 804 | /* Cleanup when a resize has occured. |
729 | 805 | Returns the character that must be processed. */ |
@@ -41,6 +41,9 @@ extern int tui_getc (FILE *); | ||
41 | 41 | changed the edited text. */ |
42 | 42 | extern void tui_redisplay_readline (void); |
43 | 43 | |
44 | +/* Expand TABs into spaces. */ | |
45 | +extern char *tui_expand_tabs (const char *, int); | |
46 | + | |
44 | 47 | extern struct ui_out *tui_out; |
45 | 48 | extern struct ui_out *tui_old_uiout; |
46 | 49 |
@@ -36,6 +36,7 @@ | ||
36 | 36 | #include "tui/tui-wingeneral.h" |
37 | 37 | #include "tui/tui-file.h" |
38 | 38 | #include "tui/tui-regs.h" |
39 | +#include "tui/tui-io.h" | |
39 | 40 | #include "reggroups.h" |
40 | 41 | #include "valprint.h" |
41 | 42 |
@@ -693,7 +694,9 @@ tui_register_format (struct frame_info *frame, int regnum) | ||
693 | 694 | if (s && s[1] == 0) |
694 | 695 | *s = 0; |
695 | 696 | |
696 | - ret = xstrdup (p); | |
697 | + /* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */ | |
698 | + ret = tui_expand_tabs (p, 0); | |
699 | + | |
697 | 700 | do_cleanups (cleanups); |
698 | 701 | |
699 | 702 | return ret; |