1
0
forked from aniani/vim

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.
This commit is contained in:
Bram Moolenaar
2016-01-20 22:48:02 +01:00
parent a7c3795a2e
commit 88e8f9f144
8 changed files with 48 additions and 51 deletions

View File

@@ -30,21 +30,32 @@ static int chartab_initialized = FALSE;
#define RESET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7)) #define RESET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7))
#define GET_CHARTAB(buf, c) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7))) #define GET_CHARTAB(buf, c) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7)))
/* table used below, see init_chartab() for an explanation */
static char_u g_chartab[256];
/* /*
* Fill chartab[]. Also fills curbuf->b_chartab[] with flags for keyword * Flags for g_chartab[].
*/
#define CT_CELL_MASK 0x07 /* mask: nr of display cells (1, 2 or 4) */
#define CT_PRINT_CHAR 0x10 /* flag: set for printable chars */
#define CT_ID_CHAR 0x20 /* flag: set for ID chars */
#define CT_FNAME_CHAR 0x40 /* flag: set for file name chars */
/*
* Fill g_chartab[]. Also fills curbuf->b_chartab[] with flags for keyword
* characters for current buffer. * characters for current buffer.
* *
* Depends on the option settings 'iskeyword', 'isident', 'isfname', * Depends on the option settings 'iskeyword', 'isident', 'isfname',
* 'isprint' and 'encoding'. * 'isprint' and 'encoding'.
* *
* The index in chartab[] depends on 'encoding': * The index in g_chartab[] depends on 'encoding':
* - For non-multi-byte index with the byte (same as the character). * - For non-multi-byte index with the byte (same as the character).
* - For DBCS index with the first byte. * - For DBCS index with the first byte.
* - For UTF-8 index with the character (when first byte is up to 0x80 it is * - For UTF-8 index with the character (when first byte is up to 0x80 it is
* the same as the character, if the first byte is 0x80 and above it depends * the same as the character, if the first byte is 0x80 and above it depends
* on further bytes). * on further bytes).
* *
* The contents of chartab[]: * The contents of g_chartab[]:
* - The lower two bits, masked by CT_CELL_MASK, give the number of display * - The lower two bits, masked by CT_CELL_MASK, give the number of display
* cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80. * cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80.
* - CT_PRINT_CHAR bit is set when the character is printable (no need to * - CT_PRINT_CHAR bit is set when the character is printable (no need to
@@ -86,18 +97,18 @@ buf_init_chartab(buf, global)
*/ */
c = 0; c = 0;
while (c < ' ') while (c < ' ')
chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2;
#ifdef EBCDIC #ifdef EBCDIC
while (c < 255) while (c < 255)
#else #else
while (c <= '~') while (c <= '~')
#endif #endif
chartab[c++] = 1 + CT_PRINT_CHAR; g_chartab[c++] = 1 + CT_PRINT_CHAR;
#ifdef FEAT_FKMAP #ifdef FEAT_FKMAP
if (p_altkeymap) if (p_altkeymap)
{ {
while (c < YE) while (c < YE)
chartab[c++] = 1 + CT_PRINT_CHAR; g_chartab[c++] = 1 + CT_PRINT_CHAR;
} }
#endif #endif
while (c < 256) while (c < 256)
@@ -105,17 +116,17 @@ buf_init_chartab(buf, global)
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
/* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */ /* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */
if (enc_utf8 && c >= 0xa0) if (enc_utf8 && c >= 0xa0)
chartab[c++] = CT_PRINT_CHAR + 1; g_chartab[c++] = CT_PRINT_CHAR + 1;
/* euc-jp characters starting with 0x8e are single width */ /* euc-jp characters starting with 0x8e are single width */
else if (enc_dbcs == DBCS_JPNU && c == 0x8e) else if (enc_dbcs == DBCS_JPNU && c == 0x8e)
chartab[c++] = CT_PRINT_CHAR + 1; g_chartab[c++] = CT_PRINT_CHAR + 1;
/* other double-byte chars can be printable AND double-width */ /* other double-byte chars can be printable AND double-width */
else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2) else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2)
chartab[c++] = CT_PRINT_CHAR + 2; g_chartab[c++] = CT_PRINT_CHAR + 2;
else else
#endif #endif
/* the rest is unprintable by default */ /* the rest is unprintable by default */
chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2;
} }
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
@@ -124,7 +135,7 @@ buf_init_chartab(buf, global)
if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1) if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1)
|| (enc_dbcs == DBCS_JPNU && c == 0x8e) || (enc_dbcs == DBCS_JPNU && c == 0x8e)
|| (enc_utf8 && c >= 0xa0)) || (enc_utf8 && c >= 0xa0))
chartab[c] |= CT_FNAME_CHAR; g_chartab[c] |= CT_FNAME_CHAR;
#endif #endif
} }
@@ -232,9 +243,9 @@ buf_init_chartab(buf, global)
if (i == 0) /* (re)set ID flag */ if (i == 0) /* (re)set ID flag */
{ {
if (tilde) if (tilde)
chartab[c] &= ~CT_ID_CHAR; g_chartab[c] &= ~CT_ID_CHAR;
else else
chartab[c] |= CT_ID_CHAR; g_chartab[c] |= CT_ID_CHAR;
} }
else if (i == 1) /* (re)set printable */ else if (i == 1) /* (re)set printable */
{ {
@@ -256,23 +267,23 @@ buf_init_chartab(buf, global)
{ {
if (tilde) if (tilde)
{ {
chartab[c] = (chartab[c] & ~CT_CELL_MASK) g_chartab[c] = (g_chartab[c] & ~CT_CELL_MASK)
+ ((dy_flags & DY_UHEX) ? 4 : 2); + ((dy_flags & DY_UHEX) ? 4 : 2);
chartab[c] &= ~CT_PRINT_CHAR; g_chartab[c] &= ~CT_PRINT_CHAR;
} }
else else
{ {
chartab[c] = (chartab[c] & ~CT_CELL_MASK) + 1; g_chartab[c] = (g_chartab[c] & ~CT_CELL_MASK) + 1;
chartab[c] |= CT_PRINT_CHAR; g_chartab[c] |= CT_PRINT_CHAR;
} }
} }
} }
else if (i == 2) /* (re)set fname flag */ else if (i == 2) /* (re)set fname flag */
{ {
if (tilde) if (tilde)
chartab[c] &= ~CT_FNAME_CHAR; g_chartab[c] &= ~CT_FNAME_CHAR;
else else
chartab[c] |= CT_FNAME_CHAR; g_chartab[c] |= CT_FNAME_CHAR;
} }
else /* i == 3 */ /* (re)set keyword flag */ else /* i == 3 */ /* (re)set keyword flag */
{ {
@@ -531,9 +542,9 @@ str_foldcase(str, orglen, buf, buflen)
#endif #endif
/* /*
* Catch 22: chartab[] can't be initialized before the options are * Catch 22: g_chartab[] can't be initialized before the options are
* initialized, and initializing options may cause transchar() to be called! * initialized, and initializing options may cause transchar() to be called!
* When chartab_initialized == FALSE don't use chartab[]. * When chartab_initialized == FALSE don't use g_chartab[].
* Does NOT work for multi-byte characters, c must be <= 255. * Does NOT work for multi-byte characters, c must be <= 255.
* Also doesn't work for the first byte of a multi-byte, "c" must be a * Also doesn't work for the first byte of a multi-byte, "c" must be a
* character! * character!
@@ -718,7 +729,7 @@ byte2cells(b)
if (enc_utf8 && b >= 0x80) if (enc_utf8 && b >= 0x80)
return 0; return 0;
#endif #endif
return (chartab[b] & CT_CELL_MASK); return (g_chartab[b] & CT_CELL_MASK);
} }
/* /*
@@ -748,7 +759,7 @@ char2cells(c)
} }
} }
#endif #endif
return (chartab[c & 0xff] & CT_CELL_MASK); return (g_chartab[c & 0xff] & CT_CELL_MASK);
} }
/* /*
@@ -765,7 +776,7 @@ ptr2cells(p)
return utf_ptr2cells(p); return utf_ptr2cells(p);
/* For DBCS we can tell the cell count from the first byte. */ /* For DBCS we can tell the cell count from the first byte. */
#endif #endif
return (chartab[*p] & CT_CELL_MASK); return (g_chartab[*p] & CT_CELL_MASK);
} }
/* /*
@@ -900,7 +911,7 @@ win_linetabsize(wp, line, len)
vim_isIDc(c) vim_isIDc(c)
int c; int c;
{ {
return (c > 0 && c < 0x100 && (chartab[c] & CT_ID_CHAR)); return (c > 0 && c < 0x100 && (g_chartab[c] & CT_ID_CHAR));
} }
/* /*
@@ -966,7 +977,7 @@ vim_iswordp_buf(p, buf)
vim_isfilec(c) vim_isfilec(c)
int c; int c;
{ {
return (c >= 0x100 || (c > 0 && (chartab[c] & CT_FNAME_CHAR))); return (c >= 0x100 || (c > 0 && (g_chartab[c] & CT_FNAME_CHAR)));
} }
/* /*
@@ -999,7 +1010,7 @@ vim_isprintc(c)
if (enc_utf8 && c >= 0x100) if (enc_utf8 && c >= 0x100)
return utf_printable(c); return utf_printable(c);
#endif #endif
return (c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR))); return (c >= 0x100 || (c > 0 && (g_chartab[c] & CT_PRINT_CHAR)));
} }
/* /*
@@ -1016,7 +1027,7 @@ vim_isprintc_strict(c)
if (enc_utf8 && c >= 0x100) if (enc_utf8 && c >= 0x100)
return utf_printable(c); return utf_printable(c);
#endif #endif
return (c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR))); return (c >= 0x100 || (c > 0 && (g_chartab[c] & CT_PRINT_CHAR)));
} }
/* /*
@@ -1368,7 +1379,7 @@ getvcol(wp, pos, start, cursor, end)
if (enc_utf8 && c >= 0x80) if (enc_utf8 && c >= 0x80)
incr = utf_ptr2cells(ptr); incr = utf_ptr2cells(ptr);
else else
incr = CHARSIZE(c); incr = g_chartab[c] & CT_CELL_MASK;
/* If a double-cell char doesn't fit at the end of a line /* If a double-cell char doesn't fit at the end of a line
* it wraps to the next line, it's like this char is three * it wraps to the next line, it's like this char is three
@@ -1382,7 +1393,7 @@ getvcol(wp, pos, start, cursor, end)
} }
else else
#endif #endif
incr = CHARSIZE(c); incr = g_chartab[c] & CT_CELL_MASK;
} }
if (posptr != NULL && ptr >= posptr) /* character at pos->col */ if (posptr != NULL && ptr >= posptr) /* character at pos->col */

View File

@@ -1012,9 +1012,6 @@ EXTERN int vgetc_im_active; /* Input Method was active for last
#endif #endif
EXTERN int maptick INIT(= 0); /* tick for each non-mapped char */ EXTERN int maptick INIT(= 0); /* tick for each non-mapped char */
EXTERN char_u chartab[256]; /* table used in charset.c; See
init_chartab() for explanation */
EXTERN int must_redraw INIT(= 0); /* type of redraw necessary */ EXTERN int must_redraw INIT(= 0); /* type of redraw necessary */
EXTERN int skip_redraw INIT(= FALSE); /* skip redraw once */ EXTERN int skip_redraw INIT(= FALSE); /* skip redraw once */
EXTERN int do_redraw INIT(= FALSE); /* extra redraw once */ EXTERN int do_redraw INIT(= FALSE); /* extra redraw once */

View File

@@ -121,11 +121,6 @@
/* Returns empty string if it is NULL. */ /* Returns empty string if it is NULL. */
#define EMPTY_IF_NULL(x) ((x) ? (x) : (u_char *)"") #define EMPTY_IF_NULL(x) ((x) ? (x) : (u_char *)"")
/* macro version of chartab().
* Only works with values 0-255!
* Doesn't work for UTF-8 mode with chars >= 0x80. */
#define CHARSIZE(c) (chartab[c] & CT_CELL_MASK)
#ifdef FEAT_LANGMAP #ifdef FEAT_LANGMAP
/* /*
* Adjust chars in a language according to 'langmap' option. * Adjust chars in a language according to 'langmap' option.

View File

@@ -1582,8 +1582,8 @@ init_locale()
/* Initialize the gettext library */ /* Initialize the gettext library */
dyn_libintl_init(); dyn_libintl_init();
# endif # endif
/* expand_env() doesn't work yet, because chartab[] is not initialized /* expand_env() doesn't work yet, because g_chartab[] is not
* yet, call vim_getenv() directly */ * initialized yet, call vim_getenv() directly */
p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
if (p != NULL && *p != NUL) if (p != NULL && *p != NUL)
{ {

View File

@@ -5934,9 +5934,9 @@ did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
#endif #endif
/* /*
* 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[] * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
* If the new option is invalid, use old value. 'lisp' option: refill * If the new option is invalid, use old value. 'lisp' option: refill
* chartab[] for '-' char * g_chartab[] for '-' char
*/ */
else if ( varp == &p_isi else if ( varp == &p_isi
|| varp == &(curbuf->b_p_isk) || varp == &(curbuf->b_p_isk)

View File

@@ -4598,7 +4598,7 @@ win_line(wp, lnum, startrow, endrow, nochange)
/* /*
* Handling of non-printable characters. * Handling of non-printable characters.
*/ */
if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) if (!vim_isprintc(c))
{ {
/* /*
* when getting a character from the file, we may have to * when getting a character from the file, we may have to

View File

@@ -741,6 +741,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1147,
/**/ /**/
1146, 1146,
/**/ /**/

View File

@@ -1110,14 +1110,6 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
#define HIST_DEBUG 4 /* debug commands */ #define HIST_DEBUG 4 /* debug commands */
#define HIST_COUNT 5 /* number of history tables */ #define HIST_COUNT 5 /* number of history tables */
/*
* Flags for chartab[].
*/
#define CT_CELL_MASK 0x07 /* mask: nr of display cells (1, 2 or 4) */
#define CT_PRINT_CHAR 0x10 /* flag: set for printable chars */
#define CT_ID_CHAR 0x20 /* flag: set for ID chars */
#define CT_FNAME_CHAR 0x40 /* flag: set for file name chars */
/* /*
* Values for do_tag(). * Values for do_tag().
*/ */