@@ -30,21 +30,32 @@ static int chartab_initialized = FALSE;
3030#define RESET_CHARTAB (buf , c ) (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7))
3131#define GET_CHARTAB (buf , c ) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7)))
3232
33+ /* table used below, see init_chartab() for an explanation */
34+ static char_u g_chartab [256 ];
35+
36+ /*
37+ * Flags for g_chartab[].
38+ */
39+ #define CT_CELL_MASK 0x07 /* mask: nr of display cells (1, 2 or 4) */
40+ #define CT_PRINT_CHAR 0x10 /* flag: set for printable chars */
41+ #define CT_ID_CHAR 0x20 /* flag: set for ID chars */
42+ #define CT_FNAME_CHAR 0x40 /* flag: set for file name chars */
43+
3344/*
34- * Fill chartab []. Also fills curbuf->b_chartab[] with flags for keyword
45+ * Fill g_chartab []. Also fills curbuf->b_chartab[] with flags for keyword
3546 * characters for current buffer.
3647 *
3748 * Depends on the option settings 'iskeyword', 'isident', 'isfname',
3849 * 'isprint' and 'encoding'.
3950 *
40- * The index in chartab [] depends on 'encoding':
51+ * The index in g_chartab [] depends on 'encoding':
4152 * - For non-multi-byte index with the byte (same as the character).
4253 * - For DBCS index with the first byte.
4354 * - For UTF-8 index with the character (when first byte is up to 0x80 it is
4455 * the same as the character, if the first byte is 0x80 and above it depends
4556 * on further bytes).
4657 *
47- * The contents of chartab []:
58+ * The contents of g_chartab []:
4859 * - The lower two bits, masked by CT_CELL_MASK, give the number of display
4960 * cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80.
5061 * - CT_PRINT_CHAR bit is set when the character is printable (no need to
@@ -86,36 +97,36 @@ buf_init_chartab(buf, global)
8697 */
8798 c = 0 ;
8899 while (c < ' ' )
89- chartab [c ++ ] = (dy_flags & DY_UHEX ) ? 4 : 2 ;
100+ g_chartab [c ++ ] = (dy_flags & DY_UHEX ) ? 4 : 2 ;
90101#ifdef EBCDIC
91102 while (c < 255 )
92103#else
93104 while (c <= '~' )
94105#endif
95- chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
106+ g_chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
96107#ifdef FEAT_FKMAP
97108 if (p_altkeymap )
98109 {
99110 while (c < YE )
100- chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
111+ g_chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
101112 }
102113#endif
103114 while (c < 256 )
104115 {
105116#ifdef FEAT_MBYTE
106117 /* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */
107118 if (enc_utf8 && c >= 0xa0 )
108- chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
119+ g_chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
109120 /* euc-jp characters starting with 0x8e are single width */
110121 else if (enc_dbcs == DBCS_JPNU && c == 0x8e )
111- chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
122+ g_chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
112123 /* other double-byte chars can be printable AND double-width */
113124 else if (enc_dbcs != 0 && MB_BYTE2LEN (c ) == 2 )
114- chartab [c ++ ] = CT_PRINT_CHAR + 2 ;
125+ g_chartab [c ++ ] = CT_PRINT_CHAR + 2 ;
115126 else
116127#endif
117128 /* the rest is unprintable by default */
118- chartab [c ++ ] = (dy_flags & DY_UHEX ) ? 4 : 2 ;
129+ g_chartab [c ++ ] = (dy_flags & DY_UHEX ) ? 4 : 2 ;
119130 }
120131
121132#ifdef FEAT_MBYTE
@@ -124,7 +135,7 @@ buf_init_chartab(buf, global)
124135 if ((enc_dbcs != 0 && MB_BYTE2LEN (c ) > 1 )
125136 || (enc_dbcs == DBCS_JPNU && c == 0x8e )
126137 || (enc_utf8 && c >= 0xa0 ))
127- chartab [c ] |= CT_FNAME_CHAR ;
138+ g_chartab [c ] |= CT_FNAME_CHAR ;
128139#endif
129140 }
130141
@@ -232,9 +243,9 @@ buf_init_chartab(buf, global)
232243 if (i == 0 ) /* (re)set ID flag */
233244 {
234245 if (tilde )
235- chartab [c ] &= ~CT_ID_CHAR ;
246+ g_chartab [c ] &= ~CT_ID_CHAR ;
236247 else
237- chartab [c ] |= CT_ID_CHAR ;
248+ g_chartab [c ] |= CT_ID_CHAR ;
238249 }
239250 else if (i == 1 ) /* (re)set printable */
240251 {
@@ -256,23 +267,23 @@ buf_init_chartab(buf, global)
256267 {
257268 if (tilde )
258269 {
259- chartab [c ] = (chartab [c ] & ~CT_CELL_MASK )
270+ g_chartab [c ] = (g_chartab [c ] & ~CT_CELL_MASK )
260271 + ((dy_flags & DY_UHEX ) ? 4 : 2 );
261- chartab [c ] &= ~CT_PRINT_CHAR ;
272+ g_chartab [c ] &= ~CT_PRINT_CHAR ;
262273 }
263274 else
264275 {
265- chartab [c ] = (chartab [c ] & ~CT_CELL_MASK ) + 1 ;
266- chartab [c ] |= CT_PRINT_CHAR ;
276+ g_chartab [c ] = (g_chartab [c ] & ~CT_CELL_MASK ) + 1 ;
277+ g_chartab [c ] |= CT_PRINT_CHAR ;
267278 }
268279 }
269280 }
270281 else if (i == 2 ) /* (re)set fname flag */
271282 {
272283 if (tilde )
273- chartab [c ] &= ~CT_FNAME_CHAR ;
284+ g_chartab [c ] &= ~CT_FNAME_CHAR ;
274285 else
275- chartab [c ] |= CT_FNAME_CHAR ;
286+ g_chartab [c ] |= CT_FNAME_CHAR ;
276287 }
277288 else /* i == 3 */ /* (re)set keyword flag */
278289 {
@@ -531,9 +542,9 @@ str_foldcase(str, orglen, buf, buflen)
531542#endif
532543
533544/*
534- * Catch 22: chartab [] can't be initialized before the options are
545+ * Catch 22: g_chartab [] can't be initialized before the options are
535546 * initialized, and initializing options may cause transchar() to be called!
536- * When chartab_initialized == FALSE don't use chartab [].
547+ * When chartab_initialized == FALSE don't use g_chartab [].
537548 * Does NOT work for multi-byte characters, c must be <= 255.
538549 * Also doesn't work for the first byte of a multi-byte, "c" must be a
539550 * character!
@@ -718,7 +729,7 @@ byte2cells(b)
718729 if (enc_utf8 && b >= 0x80 )
719730 return 0 ;
720731#endif
721- return (chartab [b ] & CT_CELL_MASK );
732+ return (g_chartab [b ] & CT_CELL_MASK );
722733}
723734
724735/*
@@ -748,7 +759,7 @@ char2cells(c)
748759 }
749760 }
750761#endif
751- return (chartab [c & 0xff ] & CT_CELL_MASK );
762+ return (g_chartab [c & 0xff ] & CT_CELL_MASK );
752763}
753764
754765/*
@@ -765,7 +776,7 @@ ptr2cells(p)
765776 return utf_ptr2cells (p );
766777 /* For DBCS we can tell the cell count from the first byte. */
767778#endif
768- return (chartab [* p ] & CT_CELL_MASK );
779+ return (g_chartab [* p ] & CT_CELL_MASK );
769780}
770781
771782/*
@@ -900,7 +911,7 @@ win_linetabsize(wp, line, len)
900911vim_isIDc (c )
901912 int c ;
902913{
903- return (c > 0 && c < 0x100 && (chartab [c ] & CT_ID_CHAR ));
914+ return (c > 0 && c < 0x100 && (g_chartab [c ] & CT_ID_CHAR ));
904915}
905916
906917/*
@@ -966,7 +977,7 @@ vim_iswordp_buf(p, buf)
966977vim_isfilec (c )
967978 int c ;
968979{
969- return (c >= 0x100 || (c > 0 && (chartab [c ] & CT_FNAME_CHAR )));
980+ return (c >= 0x100 || (c > 0 && (g_chartab [c ] & CT_FNAME_CHAR )));
970981}
971982
972983/*
@@ -999,7 +1010,7 @@ vim_isprintc(c)
9991010 if (enc_utf8 && c >= 0x100 )
10001011 return utf_printable (c );
10011012#endif
1002- return (c >= 0x100 || (c > 0 && (chartab [c ] & CT_PRINT_CHAR )));
1013+ return (c >= 0x100 || (c > 0 && (g_chartab [c ] & CT_PRINT_CHAR )));
10031014}
10041015
10051016/*
@@ -1016,7 +1027,7 @@ vim_isprintc_strict(c)
10161027 if (enc_utf8 && c >= 0x100 )
10171028 return utf_printable (c );
10181029#endif
1019- return (c >= 0x100 || (c > 0 && (chartab [c ] & CT_PRINT_CHAR )));
1030+ return (c >= 0x100 || (c > 0 && (g_chartab [c ] & CT_PRINT_CHAR )));
10201031}
10211032
10221033/*
@@ -1368,7 +1379,7 @@ getvcol(wp, pos, start, cursor, end)
13681379 if (enc_utf8 && c >= 0x80 )
13691380 incr = utf_ptr2cells (ptr );
13701381 else
1371- incr = CHARSIZE ( c ) ;
1382+ incr = g_chartab [ c ] & CT_CELL_MASK ;
13721383
13731384 /* If a double-cell char doesn't fit at the end of a line
13741385 * it wraps to the next line, it's like this char is three
@@ -1382,7 +1393,7 @@ getvcol(wp, pos, start, cursor, end)
13821393 }
13831394 else
13841395#endif
1385- incr = CHARSIZE ( c ) ;
1396+ incr = g_chartab [ c ] & CT_CELL_MASK ;
13861397 }
13871398
13881399 if (posptr != NULL && ptr >= posptr ) /* character at pos->col */
0 commit comments