@@ -30,21 +30,32 @@ static int chartab_initialized = FALSE;
30
30
#define RESET_CHARTAB (buf , c ) (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7))
31
31
#define GET_CHARTAB (buf , c ) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7)))
32
32
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
+
33
44
/*
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
35
46
* characters for current buffer.
36
47
*
37
48
* Depends on the option settings 'iskeyword', 'isident', 'isfname',
38
49
* 'isprint' and 'encoding'.
39
50
*
40
- * The index in chartab [] depends on 'encoding':
51
+ * The index in g_chartab [] depends on 'encoding':
41
52
* - For non-multi-byte index with the byte (same as the character).
42
53
* - For DBCS index with the first byte.
43
54
* - For UTF-8 index with the character (when first byte is up to 0x80 it is
44
55
* the same as the character, if the first byte is 0x80 and above it depends
45
56
* on further bytes).
46
57
*
47
- * The contents of chartab []:
58
+ * The contents of g_chartab []:
48
59
* - The lower two bits, masked by CT_CELL_MASK, give the number of display
49
60
* cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80.
50
61
* - CT_PRINT_CHAR bit is set when the character is printable (no need to
@@ -86,36 +97,36 @@ buf_init_chartab(buf, global)
86
97
*/
87
98
c = 0 ;
88
99
while (c < ' ' )
89
- chartab [c ++ ] = (dy_flags & DY_UHEX ) ? 4 : 2 ;
100
+ g_chartab [c ++ ] = (dy_flags & DY_UHEX ) ? 4 : 2 ;
90
101
#ifdef EBCDIC
91
102
while (c < 255 )
92
103
#else
93
104
while (c <= '~' )
94
105
#endif
95
- chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
106
+ g_chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
96
107
#ifdef FEAT_FKMAP
97
108
if (p_altkeymap )
98
109
{
99
110
while (c < YE )
100
- chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
111
+ g_chartab [c ++ ] = 1 + CT_PRINT_CHAR ;
101
112
}
102
113
#endif
103
114
while (c < 256 )
104
115
{
105
116
#ifdef FEAT_MBYTE
106
117
/* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */
107
118
if (enc_utf8 && c >= 0xa0 )
108
- chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
119
+ g_chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
109
120
/* euc-jp characters starting with 0x8e are single width */
110
121
else if (enc_dbcs == DBCS_JPNU && c == 0x8e )
111
- chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
122
+ g_chartab [c ++ ] = CT_PRINT_CHAR + 1 ;
112
123
/* other double-byte chars can be printable AND double-width */
113
124
else if (enc_dbcs != 0 && MB_BYTE2LEN (c ) == 2 )
114
- chartab [c ++ ] = CT_PRINT_CHAR + 2 ;
125
+ g_chartab [c ++ ] = CT_PRINT_CHAR + 2 ;
115
126
else
116
127
#endif
117
128
/* 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 ;
119
130
}
120
131
121
132
#ifdef FEAT_MBYTE
@@ -124,7 +135,7 @@ buf_init_chartab(buf, global)
124
135
if ((enc_dbcs != 0 && MB_BYTE2LEN (c ) > 1 )
125
136
|| (enc_dbcs == DBCS_JPNU && c == 0x8e )
126
137
|| (enc_utf8 && c >= 0xa0 ))
127
- chartab [c ] |= CT_FNAME_CHAR ;
138
+ g_chartab [c ] |= CT_FNAME_CHAR ;
128
139
#endif
129
140
}
130
141
@@ -232,9 +243,9 @@ buf_init_chartab(buf, global)
232
243
if (i == 0 ) /* (re)set ID flag */
233
244
{
234
245
if (tilde )
235
- chartab [c ] &= ~CT_ID_CHAR ;
246
+ g_chartab [c ] &= ~CT_ID_CHAR ;
236
247
else
237
- chartab [c ] |= CT_ID_CHAR ;
248
+ g_chartab [c ] |= CT_ID_CHAR ;
238
249
}
239
250
else if (i == 1 ) /* (re)set printable */
240
251
{
@@ -256,23 +267,23 @@ buf_init_chartab(buf, global)
256
267
{
257
268
if (tilde )
258
269
{
259
- chartab [c ] = (chartab [c ] & ~CT_CELL_MASK )
270
+ g_chartab [c ] = (g_chartab [c ] & ~CT_CELL_MASK )
260
271
+ ((dy_flags & DY_UHEX ) ? 4 : 2 );
261
- chartab [c ] &= ~CT_PRINT_CHAR ;
272
+ g_chartab [c ] &= ~CT_PRINT_CHAR ;
262
273
}
263
274
else
264
275
{
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 ;
267
278
}
268
279
}
269
280
}
270
281
else if (i == 2 ) /* (re)set fname flag */
271
282
{
272
283
if (tilde )
273
- chartab [c ] &= ~CT_FNAME_CHAR ;
284
+ g_chartab [c ] &= ~CT_FNAME_CHAR ;
274
285
else
275
- chartab [c ] |= CT_FNAME_CHAR ;
286
+ g_chartab [c ] |= CT_FNAME_CHAR ;
276
287
}
277
288
else /* i == 3 */ /* (re)set keyword flag */
278
289
{
@@ -531,9 +542,9 @@ str_foldcase(str, orglen, buf, buflen)
531
542
#endif
532
543
533
544
/*
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
535
546
* 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 [].
537
548
* Does NOT work for multi-byte characters, c must be <= 255.
538
549
* Also doesn't work for the first byte of a multi-byte, "c" must be a
539
550
* character!
@@ -718,7 +729,7 @@ byte2cells(b)
718
729
if (enc_utf8 && b >= 0x80 )
719
730
return 0 ;
720
731
#endif
721
- return (chartab [b ] & CT_CELL_MASK );
732
+ return (g_chartab [b ] & CT_CELL_MASK );
722
733
}
723
734
724
735
/*
@@ -748,7 +759,7 @@ char2cells(c)
748
759
}
749
760
}
750
761
#endif
751
- return (chartab [c & 0xff ] & CT_CELL_MASK );
762
+ return (g_chartab [c & 0xff ] & CT_CELL_MASK );
752
763
}
753
764
754
765
/*
@@ -765,7 +776,7 @@ ptr2cells(p)
765
776
return utf_ptr2cells (p );
766
777
/* For DBCS we can tell the cell count from the first byte. */
767
778
#endif
768
- return (chartab [* p ] & CT_CELL_MASK );
779
+ return (g_chartab [* p ] & CT_CELL_MASK );
769
780
}
770
781
771
782
/*
@@ -900,7 +911,7 @@ win_linetabsize(wp, line, len)
900
911
vim_isIDc (c )
901
912
int c ;
902
913
{
903
- return (c > 0 && c < 0x100 && (chartab [c ] & CT_ID_CHAR ));
914
+ return (c > 0 && c < 0x100 && (g_chartab [c ] & CT_ID_CHAR ));
904
915
}
905
916
906
917
/*
@@ -966,7 +977,7 @@ vim_iswordp_buf(p, buf)
966
977
vim_isfilec (c )
967
978
int c ;
968
979
{
969
- return (c >= 0x100 || (c > 0 && (chartab [c ] & CT_FNAME_CHAR )));
980
+ return (c >= 0x100 || (c > 0 && (g_chartab [c ] & CT_FNAME_CHAR )));
970
981
}
971
982
972
983
/*
@@ -999,7 +1010,7 @@ vim_isprintc(c)
999
1010
if (enc_utf8 && c >= 0x100 )
1000
1011
return utf_printable (c );
1001
1012
#endif
1002
- return (c >= 0x100 || (c > 0 && (chartab [c ] & CT_PRINT_CHAR )));
1013
+ return (c >= 0x100 || (c > 0 && (g_chartab [c ] & CT_PRINT_CHAR )));
1003
1014
}
1004
1015
1005
1016
/*
@@ -1016,7 +1027,7 @@ vim_isprintc_strict(c)
1016
1027
if (enc_utf8 && c >= 0x100 )
1017
1028
return utf_printable (c );
1018
1029
#endif
1019
- return (c >= 0x100 || (c > 0 && (chartab [c ] & CT_PRINT_CHAR )));
1030
+ return (c >= 0x100 || (c > 0 && (g_chartab [c ] & CT_PRINT_CHAR )));
1020
1031
}
1021
1032
1022
1033
/*
@@ -1368,7 +1379,7 @@ getvcol(wp, pos, start, cursor, end)
1368
1379
if (enc_utf8 && c >= 0x80 )
1369
1380
incr = utf_ptr2cells (ptr );
1370
1381
else
1371
- incr = CHARSIZE ( c ) ;
1382
+ incr = g_chartab [ c ] & CT_CELL_MASK ;
1372
1383
1373
1384
/* If a double-cell char doesn't fit at the end of a line
1374
1385
* it wraps to the next line, it's like this char is three
@@ -1382,7 +1393,7 @@ getvcol(wp, pos, start, cursor, end)
1382
1393
}
1383
1394
else
1384
1395
#endif
1385
- incr = CHARSIZE ( c ) ;
1396
+ incr = g_chartab [ c ] & CT_CELL_MASK ;
1386
1397
}
1387
1398
1388
1399
if (posptr != NULL && ptr >= posptr ) /* character at pos->col */
0 commit comments