Commit 200fc949 authored by Dmitry Antipov's avatar Dmitry Antipov

Simplify and cleanup character conversion stuff.

* lisp.h (multibyte_char_to_unibyte, multibyte_char_to_unibyte_safe):
Remove prototypes.
* character.c (multibyte_char_to_unibyte)
(multibyte_char_to_unibyte_safe): Remove; no longer used.
* character.h (make_char): Remove; unused.
(CHAR_TO_BYTE8, CHAR_TO_BYTE_SAFE): Simplify.
(ASCII_BYTE_P): Remove; ASCII_CHAR_P does the same thing.
* buffer.c, charset.c, charset.h, cmds.c, coding.c, editfns.c:
* fileio.c, indent.c, insdel.c, keyboard.c, lread.c, print.c:
* search.c, term.c, xdisp.c, xterm.c: Related users changed.
parent 33848c48
2014-06-23 Dmitry Antipov <dmantipov@yandex.ru>
Simplify and cleanup character conversion stuff.
* lisp.h (multibyte_char_to_unibyte, multibyte_char_to_unibyte_safe):
Remove prototypes.
* character.c (multibyte_char_to_unibyte)
(multibyte_char_to_unibyte_safe): Remove; no longer used.
* character.h (make_char): Remove; unused.
(CHAR_TO_BYTE8, CHAR_TO_BYTE_SAFE): Simplify.
(ASCII_BYTE_P): Remove; ASCII_CHAR_P does the same thing.
* buffer.c, charset.c, charset.h, cmds.c, coding.c, editfns.c:
* fileio.c, indent.c, insdel.c, keyboard.c, lread.c, print.c:
* search.c, term.c, xdisp.c, xterm.c: Related users changed.
2014-06-22 Mario Lang <mlang@delysid.org>
* w32fns.c (Fw32_shell_execute): The the -> the.
......
......@@ -2530,7 +2530,7 @@ current buffer is cleared. */)
p = GAP_END_ADDR;
stop = Z;
}
if (ASCII_BYTE_P (*p))
if (ASCII_CHAR_P (*p))
p++, pos++;
else if (CHAR_BYTE8_HEAD_P (*p))
{
......@@ -2602,7 +2602,7 @@ current buffer is cleared. */)
stop = Z;
}
if (ASCII_BYTE_P (*p))
if (ASCII_CHAR_P (*p))
p++, pos++;
else if (EQ (flag, Qt)
&& ! CHAR_BYTE8_HEAD_P (*p)
......
......@@ -233,32 +233,6 @@ translate_char (Lisp_Object table, int c)
return c;
}
/* Convert ASCII or 8-bit character C to unibyte. If C is none of
them, return (C & 0xFF). */
int
multibyte_char_to_unibyte (int c)
{
if (c < 0x80)
return c;
if (CHAR_BYTE8_P (c))
return CHAR_TO_BYTE8 (c);
return (c & 0xFF);
}
/* Like multibyte_char_to_unibyte, but return -1 if C is not supported
by charset_unibyte. */
int
multibyte_char_to_unibyte_safe (int c)
{
if (c < 0x80)
return c;
if (CHAR_BYTE8_P (c))
return CHAR_TO_BYTE8 (c);
return -1;
}
DEFUN ("characterp", Fcharacterp, Scharacterp, 1, 2, 0,
doc: /* Return non-nil if OBJECT is a character.
In Emacs Lisp, characters are represented by character codes, which
......
......@@ -67,20 +67,15 @@ INLINE_HEADER_BEGIN
#define BYTE8_TO_CHAR(byte) ((byte) + 0x3FFF00)
#define UNIBYTE_TO_CHAR(byte) \
(ASCII_BYTE_P (byte) ? (byte) : BYTE8_TO_CHAR (byte))
(ASCII_CHAR_P (byte) ? (byte) : BYTE8_TO_CHAR (byte))
/* Return the raw 8-bit byte for character C. */
#define CHAR_TO_BYTE8(c) \
(CHAR_BYTE8_P (c) \
? (c) - 0x3FFF00 \
: multibyte_char_to_unibyte (c))
#define CHAR_TO_BYTE8(c) (CHAR_BYTE8_P (c) ? (c) - 0x3FFF00 : (c & 0xFF))
/* Return the raw 8-bit byte for character C,
or -1 if C doesn't correspond to a byte. */
#define CHAR_TO_BYTE_SAFE(c) \
(CHAR_BYTE8_P (c) \
? (c) - 0x3FFF00 \
: multibyte_char_to_unibyte_safe (c))
#define CHAR_TO_BYTE_SAFE(c) \
(ASCII_CHAR_P (c) ? c : (CHAR_BYTE8_P (c) ? (c) - 0x3FFF00 : -1))
/* Nonzero iff BYTE is the 1st byte of a multibyte form of a character
that corresponds to a raw 8-bit byte. */
......@@ -101,13 +96,6 @@ INLINE_HEADER_BEGIN
/* This is the maximum byte length of multibyte form. */
#define MAX_MULTIBYTE_LENGTH 5
/* Return a Lisp character whose character code is C. Assumes C is
a valid character code. */
#define make_char(c) make_number (c)
/* Nonzero iff C is an ASCII byte. */
#define ASCII_BYTE_P(c) UNSIGNED_CMP (c, <, 0x80)
/* Nonzero iff X is a character. */
#define CHARACTERP(x) (NATNUMP (x) && XFASTINT (x) <= MAX_CHAR)
......@@ -222,7 +210,7 @@ INLINE_HEADER_BEGIN
/* Nonzero iff BYTE starts a character in a multibyte form.
This is equivalent to:
(ASCII_BYTE_P (byte) || LEADING_CODE_P (byte)) */
(ASCII_CHAR_P (byte) || LEADING_CODE_P (byte)) */
#define CHAR_HEAD_P(byte) (((byte) & 0xC0) != 0x80)
/* How many bytes a character that starts with BYTE occupies in a
......
......@@ -389,12 +389,12 @@ load_charset_map (struct charset *charset, struct charset_map_entries *entries,
{
if (ascii_compatible_p)
{
if (! ASCII_BYTE_P (from_c))
if (! ASCII_CHAR_P (from_c))
{
if (from_c < nonascii_min_char)
nonascii_min_char = from_c;
}
else if (! ASCII_BYTE_P (to_c))
else if (! ASCII_CHAR_P (to_c))
{
nonascii_min_char = 0x80;
}
......@@ -1522,7 +1522,7 @@ find_charsets_in_text (const unsigned char *ptr, ptrdiff_t nchars,
if (!NILP (table))
c = translate_char (table, c);
if (ASCII_BYTE_P (c))
if (ASCII_CHAR_P (c))
ASET (charsets, charset_ascii, Qt);
else
ASET (charsets, charset_eight_bit, Qt);
......
......@@ -403,7 +403,7 @@ extern Lisp_Object Vchar_charset_set;
Try some optimization before calling decode_char. */
#define DECODE_CHAR(charset, code) \
((ASCII_BYTE_P (code) && (charset)->ascii_compatible_p) \
((ASCII_CHAR_P (code) && (charset)->ascii_compatible_p) \
? (code) \
: ((code) < (charset)->min_code || (code) > (charset)->max_code) \
? -1 \
......
......@@ -359,9 +359,7 @@ internal_self_insert (int c, EMACS_INT n)
}
else
{
str[0] = (SINGLE_BYTE_CHAR_P (c)
? c
: multibyte_char_to_unibyte (c));
str[0] = SINGLE_BYTE_CHAR_P (c) ? c : CHAR_TO_BYTE8 (c);
len = 1;
}
if (!NILP (overwrite)
......
......@@ -1485,7 +1485,7 @@ decode_coding_utf_8 (struct coding_system *coding)
src = src_base;
consumed_chars = consumed_chars_base;
ONE_MORE_BYTE (c);
*charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c);
*charbuf++ = ASCII_CHAR_P (c) ? c : BYTE8_TO_CHAR (c);
coding->errors++;
}
......@@ -1725,7 +1725,7 @@ decode_coding_utf_16 (struct coding_system *coding)
ONE_MORE_BYTE (c2);
if (c2 < 0)
{
*charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
*charbuf++ = ASCII_CHAR_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
*charbuf++ = -c2;
continue;
}
......@@ -2108,7 +2108,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src,
case 1:
code = c;
charset_ID = ASCII_BYTE_P (code) ? charset_ascii : charset_eight_bit;
charset_ID = ASCII_CHAR_P (code) ? charset_ascii : charset_eight_bit;
break;
default:
......@@ -2596,7 +2596,7 @@ decode_coding_emacs_mule (struct coding_system *coding)
src = src_base;
consumed_chars = consumed_chars_base;
ONE_MORE_BYTE (c);
*charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c);
*charbuf++ = ASCII_CHAR_P (c) ? c : BYTE8_TO_CHAR (c);
char_offset++;
coding->errors++;
}
......@@ -3573,7 +3573,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
if (CODING_ISO_EXTSEGMENT_LEN (coding) > 0)
{
*charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
*charbuf++ = ASCII_CHAR_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
char_offset++;
CODING_ISO_EXTSEGMENT_LEN (coding)--;
continue;
......@@ -3600,7 +3600,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
}
else
{
*charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
*charbuf++ = ASCII_CHAR_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
char_offset++;
}
continue;
......@@ -3974,7 +3974,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
MAYBE_FINISH_COMPOSITION ();
for (; src_base < src; src_base++, char_offset++)
{
if (ASCII_BYTE_P (*src_base))
if (ASCII_CHAR_P (*src_base))
*charbuf++ = *src_base;
else
*charbuf++ = BYTE8_TO_CHAR (*src_base);
......@@ -4004,7 +4004,7 @@ decode_coding_iso_2022 (struct coding_system *coding)
src = src_base;
consumed_chars = consumed_chars_base;
ONE_MORE_BYTE (c);
*charbuf++ = c < 0 ? -c : ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c);
*charbuf++ = c < 0 ? -c : ASCII_CHAR_P (c) ? c : BYTE8_TO_CHAR (c);
char_offset++;
coding->errors++;
/* Reset the invocation and designation status to the safest
......@@ -5640,7 +5640,7 @@ decode_coding_charset (struct coding_system *coding)
src = src_base;
consumed_chars = consumed_chars_base;
ONE_MORE_BYTE (c);
*charbuf++ = c < 0 ? -c : ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c);
*charbuf++ = c < 0 ? -c : ASCII_CHAR_P (c) ? c : BYTE8_TO_CHAR (c);
char_offset++;
coding->errors++;
}
......@@ -9031,13 +9031,13 @@ DEFUN ("find-coding-systems-region-internal",
p = pbeg = BYTE_POS_ADDR (start_byte);
pend = p + (end_byte - start_byte);
while (p < pend && ASCII_BYTE_P (*p)) p++;
while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--;
while (p < pend && ASCII_CHAR_P (*p)) p++;
while (p < pend && ASCII_CHAR_P (*(pend - 1))) pend--;
work_table = Fmake_char_table (Qnil, Qnil);
while (p < pend)
{
if (ASCII_BYTE_P (*p))
if (ASCII_CHAR_P (*p))
p++;
else
{
......@@ -9169,7 +9169,7 @@ to the string. */)
int c;
if (ascii_compatible)
while (p < stop && ASCII_BYTE_P (*p))
while (p < stop && ASCII_CHAR_P (*p))
p++, from++;
if (p >= stop)
{
......@@ -9285,12 +9285,12 @@ is nil. */)
p = pbeg = BYTE_POS_ADDR (start_byte);
pend = p + (end_byte - start_byte);
while (p < pend && ASCII_BYTE_P (*p)) p++, pos++;
while (p < pend && ASCII_BYTE_P (*(pend - 1))) pend--;
while (p < pend && ASCII_CHAR_P (*p)) p++, pos++;
while (p < pend && ASCII_CHAR_P (*(pend - 1))) pend--;
while (p < pend)
{
if (ASCII_BYTE_P (*p))
if (ASCII_CHAR_P (*p))
p++;
else
{
......@@ -9598,7 +9598,7 @@ Return the corresponding character. */)
CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec);
attrs = AREF (spec, 0);
if (ASCII_BYTE_P (ch)
if (ASCII_CHAR_P (ch)
&& ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)))
return code;
......@@ -9679,7 +9679,7 @@ Return the corresponding character. */)
CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec);
attrs = AREF (spec, 0);
if (ASCII_BYTE_P (ch)
if (ASCII_CHAR_P (ch)
&& ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)))
return code;
......
......@@ -2238,7 +2238,7 @@ general_insert_function (void (*insert_func)
len = CHAR_STRING (c, str);
else
{
str[0] = ASCII_CHAR_P (c) ? c : multibyte_char_to_unibyte (c);
str[0] = CHAR_TO_BYTE8 (c);
len = 1;
}
(*insert_func) ((char *) str, len);
......@@ -2852,7 +2852,7 @@ Both characters must have the same length of multi-byte form. */)
len = CHAR_STRING (fromc, fromstr);
if (CHAR_STRING (toc, tostr) != len)
error ("Characters in `subst-char-in-region' have different byte-lengths");
if (!ASCII_BYTE_P (*tostr))
if (!ASCII_CHAR_P (*tostr))
{
/* If *TOSTR is in the range 0x80..0x9F and TOCHAR is not a
complete multibyte character, it may be combined with the
......@@ -2945,7 +2945,7 @@ Both characters must have the same length of multi-byte form. */)
: ((pos_byte_next < Z_BYTE
&& ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next)))
|| (pos_byte > BEG_BYTE
&& ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1))))))
&& ! ASCII_CHAR_P (FETCH_BYTE (pos_byte - 1))))))
{
Lisp_Object tem, string;
......@@ -3126,7 +3126,7 @@ It returns the number of characters changed. */)
else
{
nc = tt[oc];
if (! ASCII_BYTE_P (nc) && multibyte)
if (! ASCII_CHAR_P (nc) && multibyte)
{
str_len = BYTE8_STRING (nc, buf);
str = buf;
......@@ -3877,7 +3877,7 @@ usage: (format STRING &rest OBJECTS) */)
if (p > buf
&& multibyte
&& !ASCII_BYTE_P (*((unsigned char *) p - 1))
&& !ASCII_CHAR_P (*((unsigned char *) p - 1))
&& STRING_MULTIBYTE (args[n])
&& !CHAR_HEAD_P (SREF (args[n], 0)))
maybe_combine_byte = 1;
......@@ -4167,7 +4167,7 @@ usage: (format STRING &rest OBJECTS) */)
{
/* Copy a whole multibyte character. */
if (p > buf
&& !ASCII_BYTE_P (*((unsigned char *) p - 1))
&& !ASCII_CHAR_P (*((unsigned char *) p - 1))
&& !CHAR_HEAD_P (*format))
maybe_combine_byte = 1;
......@@ -4181,7 +4181,7 @@ usage: (format STRING &rest OBJECTS) */)
else
{
unsigned char uc = *format++;
if (! multibyte || ASCII_BYTE_P (uc))
if (! multibyte || ASCII_CHAR_P (uc))
convbytes = 1;
else
{
......
......@@ -990,7 +990,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
{
unsigned char *p = SDATA (name);
while (*p && ASCII_BYTE_P (*p))
while (*p && ASCII_CHAR_P (*p))
p++;
if (*p == '\0')
{
......
......@@ -920,7 +920,7 @@ position_indentation (ptrdiff_t pos_byte)
column += tab_width - column % tab_width;
break;
default:
if (ASCII_BYTE_P (p[-1])
if (ASCII_CHAR_P (p[-1])
|| NILP (BVAR (current_buffer, enable_multibyte_characters)))
return column;
{
......
......@@ -701,7 +701,7 @@ count_combining_after (const unsigned char *string,
(2) POS is the last of the current buffer.
(3) A character at POS can't be a following byte of multibyte
character. */
if (length > 0 && ASCII_BYTE_P (string[length - 1])) /* case (1) */
if (length > 0 && ASCII_CHAR_P (string[length - 1])) /* case (1) */
return 0;
if (pos_byte == Z_BYTE) /* case (2) */
return 0;
......
......@@ -2084,7 +2084,7 @@ make_ctrl_char (int c)
/* Save the upper bits here. */
int upper = c & ~0177;
if (! ASCII_BYTE_P (c))
if (! ASCII_CHAR_P (c))
return c |= ctrl_modifier;
c &= 0177;
......
......@@ -3433,8 +3433,6 @@ extern void syms_of_coding (void);
/* Defined in character.c. */
extern ptrdiff_t chars_in_text (const unsigned char *, ptrdiff_t);
extern ptrdiff_t multibyte_chars_in_text (const unsigned char *, ptrdiff_t);
extern int multibyte_char_to_unibyte (int) ATTRIBUTE_CONST;
extern int multibyte_char_to_unibyte_safe (int) ATTRIBUTE_CONST;
extern void syms_of_character (void);
/* Defined in charset.c. */
......
......@@ -213,7 +213,7 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
else
{
c = BUF_FETCH_BYTE (inbuffer, pt_byte);
if (! ASCII_BYTE_P (c))
if (! ASCII_CHAR_P (c))
c = BYTE8_TO_CHAR (c);
pt_byte++;
}
......@@ -242,7 +242,7 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
else
{
c = BUF_FETCH_BYTE (inbuffer, bytepos);
if (! ASCII_BYTE_P (c))
if (! ASCII_CHAR_P (c))
c = BYTE8_TO_CHAR (c);
bytepos++;
}
......@@ -324,7 +324,7 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
return c;
if (multibyte)
*multibyte = 1;
if (ASCII_BYTE_P (c))
if (ASCII_CHAR_P (c))
return c;
if (emacs_mule_encoding)
return read_emacs_mule_char (c, readbyte, readcharfun);
......
......@@ -1472,7 +1472,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
strout (outbuf, len, len, printcharfun);
}
else if (! multibyte
&& SINGLE_BYTE_CHAR_P (c) && ! ASCII_BYTE_P (c)
&& SINGLE_BYTE_CHAR_P (c) && ! ASCII_CHAR_P (c)
&& print_escape_nonascii)
{
/* When printing in a multibyte buffer
......
......@@ -1416,7 +1416,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
while (boyer_moore_ok)
{
if (ASCII_BYTE_P (inverse))
if (ASCII_CHAR_P (inverse))
{
if (this_char_base > 0)
boyer_moore_ok = 0;
......@@ -1827,7 +1827,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat,
matching with CHAR_BASE are to be checked. */
int ch = -1;
if (ASCII_BYTE_P (*ptr) || ! multibyte)
if (ASCII_CHAR_P (*ptr) || ! multibyte)
ch = *ptr;
else if (char_base
&& ((pat_end - ptr) == 1 || CHAR_HEAD_P (ptr[1])))
......@@ -2596,7 +2596,7 @@ since only regular expressions have distinguished subexpressions. */)
{
FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext, pos, pos_byte);
if (!buf_multibyte)
c = multibyte_char_to_unibyte (c);
c = CHAR_TO_BYTE8 (c);
}
else
{
......@@ -2619,7 +2619,7 @@ since only regular expressions have distinguished subexpressions. */)
FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext,
pos, pos_byte);
if (!buf_multibyte && !ASCII_CHAR_P (c))
c = multibyte_char_to_unibyte (c);
c = CHAR_TO_BYTE8 (c);
}
else
{
......
......@@ -1861,7 +1861,7 @@ produce_glyphless_glyph (struct it *it, Lisp_Object acronym)
acronym = XCDR (acronym);
buf[0] = '[';
str = STRINGP (acronym) ? SSDATA (acronym) : "";
for (len = 0; len < 6 && str[len] && ASCII_BYTE_P (str[len]); len++)
for (len = 0; len < 6 && str[len] && ASCII_CHAR_P (str[len]); len++)
buf[1 + len] = str[len];
buf[1 + len] = ']';
len += 2;
......
......@@ -8269,7 +8269,7 @@ next_element_from_buffer (struct it *it)
/* Get the next character, maybe multibyte. */
p = BYTE_POS_ADDR (IT_BYTEPOS (*it));
if (it->multibyte_p && !ASCII_BYTE_P (*p))
if (it->multibyte_p && !ASCII_CHAR_P (*p))
it->c = STRING_CHAR_AND_LENGTH (p, it->len);
else
it->c = *p, it->len = 1;
......@@ -9932,9 +9932,7 @@ message_dolog (const char *m, ptrdiff_t nbytes, bool nlflag, bool multibyte)
for (i = 0; i < nbytes; i += char_bytes)
{
c = string_char_and_length (msg + i, &char_bytes);
work[0] = (ASCII_CHAR_P (c)
? c
: multibyte_char_to_unibyte (c));
work[0] = CHAR_TO_BYTE8 (c);
insert_1_both (work, 1, 1, 1, 0, 0);
}
}
......@@ -25781,7 +25779,7 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
sprintf (buf, "%0*X", it->c < 0x10000 ? 4 : 6, it->c);
str = buf;
}
for (len = 0; str[len] && ASCII_BYTE_P (str[len]) && len < 6; len++)
for (len = 0; str[len] && ASCII_CHAR_P (str[len]) && len < 6; len++)
code[len] = font->driver->encode_char (font, str[len]);
upper_len = (len + 1) / 2;
font->driver->text_extents (font, code, upper_len,
......
......@@ -6460,7 +6460,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
for (i = 0, nchars = 0; i < nbytes; i++)
{
if (ASCII_BYTE_P (copy_bufptr[i]))
if (ASCII_CHAR_P (copy_bufptr[i]))
nchars++;
STORE_KEYSYM_FOR_DEBUG (copy_bufptr[i]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment