Skip to content

Commit 88e8f9f

Browse files
committed
patch 7.4.1147
Problem: Conflict for "chartab". (Kazunobu Kuriyama) Solution: Rename the global one to something less obvious. Move it into src/chartab.c.
1 parent a7c3795 commit 88e8f9f

File tree

8 files changed

+48
-51
lines changed

8 files changed

+48
-51
lines changed

src/charset.c

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
900911
vim_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)
966977
vim_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 */

src/globals.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,6 @@ EXTERN int vgetc_im_active; /* Input Method was active for last
10121012
#endif
10131013
EXTERN int maptick INIT(= 0); /* tick for each non-mapped char */
10141014

1015-
EXTERN char_u chartab[256]; /* table used in charset.c; See
1016-
init_chartab() for explanation */
1017-
10181015
EXTERN int must_redraw INIT(= 0); /* type of redraw necessary */
10191016
EXTERN int skip_redraw INIT(= FALSE); /* skip redraw once */
10201017
EXTERN int do_redraw INIT(= FALSE); /* extra redraw once */

src/macros.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@
121121
/* Returns empty string if it is NULL. */
122122
#define EMPTY_IF_NULL(x) ((x) ? (x) : (u_char *)"")
123123

124-
/* macro version of chartab().
125-
* Only works with values 0-255!
126-
* Doesn't work for UTF-8 mode with chars >= 0x80. */
127-
#define CHARSIZE(c) (chartab[c] & CT_CELL_MASK)
128-
129124
#ifdef FEAT_LANGMAP
130125
/*
131126
* Adjust chars in a language according to 'langmap' option.

src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,8 @@ init_locale()
15821582
/* Initialize the gettext library */
15831583
dyn_libintl_init();
15841584
# endif
1585-
/* expand_env() doesn't work yet, because chartab[] is not initialized
1586-
* yet, call vim_getenv() directly */
1585+
/* expand_env() doesn't work yet, because g_chartab[] is not
1586+
* initialized yet, call vim_getenv() directly */
15871587
p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
15881588
if (p != NULL && *p != NUL)
15891589
{

src/option.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5934,9 +5934,9 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
59345934
#endif
59355935

59365936
/*
5937-
* 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5937+
* 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
59385938
* If the new option is invalid, use old value. 'lisp' option: refill
5939-
* chartab[] for '-' char
5939+
* g_chartab[] for '-' char
59405940
*/
59415941
else if ( varp == &p_isi
59425942
|| varp == &(curbuf->b_p_isk)

src/screen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4598,7 +4598,7 @@ win_line(wp, lnum, startrow, endrow, nochange)
45984598
/*
45994599
* Handling of non-printable characters.
46004600
*/
4601-
if (!(chartab[c & 0xff] & CT_PRINT_CHAR))
4601+
if (!vim_isprintc(c))
46024602
{
46034603
/*
46044604
* when getting a character from the file, we may have to

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1147,
744746
/**/
745747
1146,
746748
/**/

src/vim.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,14 +1110,6 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
11101110
#define HIST_DEBUG 4 /* debug commands */
11111111
#define HIST_COUNT 5 /* number of history tables */
11121112

1113-
/*
1114-
* Flags for chartab[].
1115-
*/
1116-
#define CT_CELL_MASK 0x07 /* mask: nr of display cells (1, 2 or 4) */
1117-
#define CT_PRINT_CHAR 0x10 /* flag: set for printable chars */
1118-
#define CT_ID_CHAR 0x20 /* flag: set for ID chars */
1119-
#define CT_FNAME_CHAR 0x40 /* flag: set for file name chars */
1120-
11211113
/*
11221114
* Values for do_tag().
11231115
*/

0 commit comments

Comments
 (0)