History

vt: convert vc_tab_stop to bitmap

vc_tab_stop is used as a bitmap, but defined as an unsigned int array. Switch it to bitmap and convert all users to the bitmap interface. Note the difference in behavior! We no longer mask the top 24 bits away from x, hence we do not wrap tabs at 256th column. Instead, we silently drop attempts to set a tab behind 256 columns. And we will also seek by '\t' to the rightmost column, when behind that boundary. I do not think the original behavior was desired and that someone relies on that. If this turns out to be the case, we can change the added 'if's back to masks here and there instead... (Or we can increase the limit as fb consoles now have 240 chars here. And they could have more with higher than my resolution, of course.)

Jiri Slaby committed 6 years ago

Commit dbee4cf1 parent b70ec4d2 files · +20 −27Browse files

Unified · Split

2 files
  1. drivers/tty/vt/vt.c +18 −26
  2. include/linux/console_struct.h +2 −1
drivers/tty/vt/vt.c+18−26
@@ -2052,6 +2052,8 @@ enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, · 2051 unmodified lines
20522052 /* console_lock is held (except via vc_init()) */
20532053 static void reset_terminal(struct vc_data *vc, int do_clear)
20542054 {
2055+ unsigned int i;
2056+
20552057 vc->vc_top = 0;
20562058 vc->vc_bottom = vc->vc_rows;
20572059 vc->vc_state = ESnormal;
@@ -2082,14 +2084,9 @@ static void reset_terminal(struct vc_data *vc, int do_clear) · 24 unmodified lines
20822084 default_attr(vc);
20832085 update_attr(vc);
20842086
2085− vc->vc_tab_stop[0] =
2086− vc->vc_tab_stop[1] =
2087− vc->vc_tab_stop[2] =
2088− vc->vc_tab_stop[3] =
2089− vc->vc_tab_stop[4] =
2090− vc->vc_tab_stop[5] =
2091− vc->vc_tab_stop[6] =
2092− vc->vc_tab_stop[7] = 0x01010101;
2087+ bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2088+ for (i = 0; i < VC_TABSTOPS_COUNT; i += 8)
2089+ set_bit(i, vc->vc_tab_stop);
20932090
20942091 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
20952092 vc->vc_bell_duration = DEFAULT_BELL_DURATION;
@@ -2147,11 +2144,13 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 51 unmodified lines
21472144 return;
21482145 case 9:
21492146 vc->vc_pos -= (vc->state.x << 1);
2150− while (vc->state.x < vc->vc_cols - 1) {
2151− vc->state.x++;
2152− if (vc->vc_tab_stop[7 & (vc->state.x >> 5)] & (1 << (vc->state.x & 31)))
2153− break;
2154− }
2147+
2148+ vc->state.x = find_next_bit(vc->vc_tab_stop,
2149+ min(vc->vc_cols - 1, VC_TABSTOPS_COUNT),
2150+ vc->state.x + 1);
2151+ if (vc->state.x >= VC_TABSTOPS_COUNT)
2152+ vc->state.x = vc->vc_cols - 1;
2153+
21552154 vc->vc_pos += (vc->state.x << 1);
21562155 notify_write(vc, '\t');
21572156 return;
@@ -2210,7 +2209,8 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 52 unmodified lines
22102209 lf(vc);
22112210 return;
22122211 case 'H':
2213− vc->vc_tab_stop[7 & (vc->state.x >> 5)] |= (1 << (vc->state.x & 31));
2212+ if (vc->state.x < VC_TABSTOPS_COUNT)
2213+ set_bit(vc->state.x, vc->vc_tab_stop);
22142214 return;
22152215 case 'Z':
22162216 respond_ID(tty);
@@ -2421,18 +2421,10 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 204 unmodified lines
24212421 respond_ID(tty);
24222422 return;
24232423 case 'g':
2424− if (!vc->vc_par[0])
2425− vc->vc_tab_stop[7 & (vc->state.x >> 5)] &= ~(1 << (vc->state.x & 31));
2426− else if (vc->vc_par[0] == 3) {
2427− vc->vc_tab_stop[0] =
2428− vc->vc_tab_stop[1] =
2429− vc->vc_tab_stop[2] =
2430− vc->vc_tab_stop[3] =
2431− vc->vc_tab_stop[4] =
2432− vc->vc_tab_stop[5] =
2433− vc->vc_tab_stop[6] =
2434− vc->vc_tab_stop[7] = 0;
2435− }
2424+ if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT)
2425+ set_bit(vc->state.x, vc->vc_tab_stop);
2426+ else if (vc->vc_par[0] == 3)
2427+ bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
24362428 return;
24372429 case 'm':
24382430 csi_m(vc);
include/linux/console_struct.h+2−1
@@ -21,6 +21,7 @@ struct uni_pagedir; · 20 unmodified lines
2121 struct uni_screen;
2222
2323 #define NPAR 16
24+#define VC_TABSTOPS_COUNT 256U
2425
2526 enum vc_intensity {
2627 VCI_HALF_BRIGHT,
@@ -147,7 +148,7 @@ struct vc_data { · 120 unmodified lines
147148 unsigned char vc_utf : 1; /* Unicode UTF-8 encoding */
148149 unsigned char vc_utf_count;
149150 int vc_utf_char;
150− unsigned int vc_tab_stop[8]; /* Tab stops. 256 columns. */
151+ DECLARE_BITMAP(vc_tab_stop, VC_TABSTOPS_COUNT); /* Tab stops. 256 columns. */
151152 unsigned char vc_palette[16*3]; /* Colour palette for VGA+ */
152153 unsigned short * vc_translate;
153154 unsigned int vc_resize_user; /* resize request from user */