summaryrefslogtreecommitdiff
path: root/src/charset.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-01-20 22:48:02 +0100
committerBram Moolenaar <Bram@vim.org>2016-01-20 22:48:02 +0100
commit88e8f9f14434a7cd538d0c159dc432bea869a5bd (patch)
tree0cc419113941be1200c09d347f96bf76cc7acaab /src/charset.c
parenta7c3795a2e65233ba2d187d680acc83bf6bf4ef5 (diff)
downloadvim-git-88e8f9f14434a7cd538d0c159dc432bea869a5bd.tar.gz
patch 7.4.1147v7.4.1147
Problem: Conflict for "chartab". (Kazunobu Kuriyama) Solution: Rename the global one to something less obvious. Move it into src/chartab.c.
Diffstat (limited to 'src/charset.c')
-rw-r--r--src/charset.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/src/charset.c b/src/charset.c
index 1000692cc..8a4fb7d6c 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -30,21 +30,32 @@ static int chartab_initialized = FALSE;
#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)))
+/* table used below, see init_chartab() for an explanation */
+static char_u g_chartab[256];
+
+/*
+ * 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 chartab[]. Also fills curbuf->b_chartab[] with flags for keyword
+ * Fill g_chartab[]. Also fills curbuf->b_chartab[] with flags for keyword
* characters for current buffer.
*
* Depends on the option settings 'iskeyword', 'isident', 'isfname',
* '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 DBCS index with the first byte.
* - 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
* 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
* 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
@@ -86,18 +97,18 @@ buf_init_chartab(buf, global)
*/
c = 0;
while (c < ' ')
- chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2;
+ g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2;
#ifdef EBCDIC
while (c < 255)
#else
while (c <= '~')
#endif
- chartab[c++] = 1 + CT_PRINT_CHAR;
+ g_chartab[c++] = 1 + CT_PRINT_CHAR;
#ifdef FEAT_FKMAP
if (p_altkeymap)
{
while (c < YE)
- chartab[c++] = 1 + CT_PRINT_CHAR;
+ g_chartab[c++] = 1 + CT_PRINT_CHAR;
}
#endif
while (c < 256)
@@ -105,17 +116,17 @@ buf_init_chartab(buf, global)
#ifdef FEAT_MBYTE
/* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */
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 */
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 */
else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2)
- chartab[c++] = CT_PRINT_CHAR + 2;
+ g_chartab[c++] = CT_PRINT_CHAR + 2;
else
#endif
/* 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
@@ -124,7 +135,7 @@ buf_init_chartab(buf, global)
if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1)
|| (enc_dbcs == DBCS_JPNU && c == 0x8e)
|| (enc_utf8 && c >= 0xa0))
- chartab[c] |= CT_FNAME_CHAR;
+ g_chartab[c] |= CT_FNAME_CHAR;
#endif
}
@@ -232,9 +243,9 @@ buf_init_chartab(buf, global)
if (i == 0) /* (re)set ID flag */
{
if (tilde)
- chartab[c] &= ~CT_ID_CHAR;
+ g_chartab[c] &= ~CT_ID_CHAR;
else
- chartab[c] |= CT_ID_CHAR;
+ g_chartab[c] |= CT_ID_CHAR;
}
else if (i == 1) /* (re)set printable */
{
@@ -256,23 +267,23 @@ buf_init_chartab(buf, global)
{
if (tilde)
{
- chartab[c] = (chartab[c] & ~CT_CELL_MASK)
+ g_chartab[c] = (g_chartab[c] & ~CT_CELL_MASK)
+ ((dy_flags & DY_UHEX) ? 4 : 2);
- chartab[c] &= ~CT_PRINT_CHAR;
+ g_chartab[c] &= ~CT_PRINT_CHAR;
}
else
{
- chartab[c] = (chartab[c] & ~CT_CELL_MASK) + 1;
- chartab[c] |= CT_PRINT_CHAR;
+ g_chartab[c] = (g_chartab[c] & ~CT_CELL_MASK) + 1;
+ g_chartab[c] |= CT_PRINT_CHAR;
}
}
}
else if (i == 2) /* (re)set fname flag */
{
if (tilde)
- chartab[c] &= ~CT_FNAME_CHAR;
+ g_chartab[c] &= ~CT_FNAME_CHAR;
else
- chartab[c] |= CT_FNAME_CHAR;
+ g_chartab[c] |= CT_FNAME_CHAR;
}
else /* i == 3 */ /* (re)set keyword flag */
{
@@ -531,9 +542,9 @@ str_foldcase(str, orglen, buf, buflen)
#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!
- * 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.
* Also doesn't work for the first byte of a multi-byte, "c" must be a
* character!
@@ -718,7 +729,7 @@ byte2cells(b)
if (enc_utf8 && b >= 0x80)
return 0;
#endif
- return (chartab[b] & CT_CELL_MASK);
+ return (g_chartab[b] & CT_CELL_MASK);
}
/*
@@ -748,7 +759,7 @@ char2cells(c)
}
}
#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);
/* For DBCS we can tell the cell count from the first byte. */
#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)
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)
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)
return utf_printable(c);
#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)
return utf_printable(c);
#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)
incr = utf_ptr2cells(ptr);
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
* it wraps to the next line, it's like this char is three
@@ -1382,7 +1393,7 @@ getvcol(wp, pos, start, cursor, end)
}
else
#endif
- incr = CHARSIZE(c);
+ incr = g_chartab[c] & CT_CELL_MASK;
}
if (posptr != NULL && ptr >= posptr) /* character at pos->col */