5224 |
else if (VECTORP (val) || STRINGP (val)) |
else if (VECTORP (val) || STRINGP (val)) |
5225 |
{ |
{ |
5226 |
int len = (VECTORP (val) |
int len = (VECTORP (val) |
5227 |
? XVECTOR (val)->size : XSTRING (val)->size); |
? XVECTOR (val)->size : SCHARS (val)); |
5228 |
int i; |
int i; |
5229 |
for (i = 0; i < len; i++) |
for (i = 0; i < len; i++) |
5230 |
{ |
{ |
5832 |
buf->enable_multibyte_characters = multibyte ? Qt : Qnil; |
buf->enable_multibyte_characters = multibyte ? Qt : Qnil; |
5833 |
|
|
5834 |
insert_from_string (str, 0, 0, |
insert_from_string (str, 0, 0, |
5835 |
XSTRING (str)->size, STRING_BYTES (XSTRING (str)), 0); |
SCHARS (str), SBYTES (str), 0); |
5836 |
UNGCPRO; |
UNGCPRO; |
5837 |
inhibit_pre_post_conversion = 1; |
inhibit_pre_post_conversion = 1; |
5838 |
if (encodep) |
if (encodep) |
5864 |
int consumed, consumed_char, produced, produced_char; |
int consumed, consumed_char, produced, produced_char; |
5865 |
|
|
5866 |
from = 0; |
from = 0; |
5867 |
to_byte = STRING_BYTES (XSTRING (str)); |
to_byte = SBYTES (str); |
5868 |
|
|
5869 |
saved_coding_symbol = coding->symbol; |
saved_coding_symbol = coding->symbol; |
5870 |
coding->src_multibyte = STRING_MULTIBYTE (str); |
coding->src_multibyte = STRING_MULTIBYTE (str); |
5874 |
/* See the comments in code_convert_region. */ |
/* See the comments in code_convert_region. */ |
5875 |
if (coding->type == coding_type_undecided) |
if (coding->type == coding_type_undecided) |
5876 |
{ |
{ |
5877 |
detect_coding (coding, XSTRING (str)->data, to_byte); |
detect_coding (coding, SDATA (str), to_byte); |
5878 |
if (coding->type == coding_type_undecided) |
if (coding->type == coding_type_undecided) |
5879 |
{ |
{ |
5880 |
coding->type = coding_type_emacs_mule; |
coding->type = coding_type_emacs_mule; |
5889 |
&& coding->type != coding_type_ccl) |
&& coding->type != coding_type_ccl) |
5890 |
{ |
{ |
5891 |
saved_coding_symbol = coding->symbol; |
saved_coding_symbol = coding->symbol; |
5892 |
detect_eol (coding, XSTRING (str)->data, to_byte); |
detect_eol (coding, SDATA (str), to_byte); |
5893 |
if (coding->eol_type == CODING_EOL_UNDECIDED) |
if (coding->eol_type == CODING_EOL_UNDECIDED) |
5894 |
coding->eol_type = CODING_EOL_LF; |
coding->eol_type = CODING_EOL_LF; |
5895 |
/* We had better recover the original eol format if we |
/* We had better recover the original eol format if we |
5908 |
{ |
{ |
5909 |
/* Decoding routines expect the source text to be unibyte. */ |
/* Decoding routines expect the source text to be unibyte. */ |
5910 |
str = Fstring_as_unibyte (str); |
str = Fstring_as_unibyte (str); |
5911 |
to_byte = STRING_BYTES (XSTRING (str)); |
to_byte = SBYTES (str); |
5912 |
nocopy = 1; |
nocopy = 1; |
5913 |
coding->src_multibyte = 0; |
coding->src_multibyte = 0; |
5914 |
} |
} |
5916 |
/* Try to skip the heading and tailing ASCIIs. */ |
/* Try to skip the heading and tailing ASCIIs. */ |
5917 |
if (require_decoding && coding->type != coding_type_ccl) |
if (require_decoding && coding->type != coding_type_ccl) |
5918 |
{ |
{ |
5919 |
SHRINK_CONVERSION_REGION (&from, &to_byte, coding, XSTRING (str)->data, |
SHRINK_CONVERSION_REGION (&from, &to_byte, coding, SDATA (str), |
5920 |
0); |
0); |
5921 |
if (from == to_byte) |
if (from == to_byte) |
5922 |
require_decoding = 0; |
require_decoding = 0; |
5923 |
shrinked_bytes = from + (STRING_BYTES (XSTRING (str)) - to_byte); |
shrinked_bytes = from + (SBYTES (str) - to_byte); |
5924 |
} |
} |
5925 |
|
|
5926 |
if (!require_decoding) |
if (!require_decoding) |
5927 |
{ |
{ |
5928 |
coding->consumed = STRING_BYTES (XSTRING (str)); |
coding->consumed = SBYTES (str); |
5929 |
coding->consumed_char = XSTRING (str)->size; |
coding->consumed_char = SCHARS (str); |
5930 |
if (coding->dst_multibyte) |
if (coding->dst_multibyte) |
5931 |
{ |
{ |
5932 |
str = Fstring_as_multibyte (str); |
str = Fstring_as_multibyte (str); |
5933 |
nocopy = 1; |
nocopy = 1; |
5934 |
} |
} |
5935 |
coding->produced = STRING_BYTES (XSTRING (str)); |
coding->produced = SBYTES (str); |
5936 |
coding->produced_char = XSTRING (str)->size; |
coding->produced_char = SCHARS (str); |
5937 |
return (nocopy ? str : Fcopy_sequence (str)); |
return (nocopy ? str : Fcopy_sequence (str)); |
5938 |
} |
} |
5939 |
|
|
5945 |
consumed = consumed_char = produced = produced_char = 0; |
consumed = consumed_char = produced = produced_char = 0; |
5946 |
while (1) |
while (1) |
5947 |
{ |
{ |
5948 |
result = decode_coding (coding, XSTRING (str)->data + from + consumed, |
result = decode_coding (coding, SDATA (str) + from + consumed, |
5949 |
buf.data + produced, to_byte - from - consumed, |
buf.data + produced, to_byte - from - consumed, |
5950 |
buf.size - produced); |
buf.size - produced); |
5951 |
consumed += coding->consumed; |
consumed += coding->consumed; |
6014 |
else |
else |
6015 |
newstr = make_uninit_string (produced + shrinked_bytes); |
newstr = make_uninit_string (produced + shrinked_bytes); |
6016 |
if (from > 0) |
if (from > 0) |
6017 |
bcopy (XSTRING (str)->data, XSTRING (newstr)->data, from); |
bcopy (SDATA (str), SDATA (newstr), from); |
6018 |
bcopy (buf.data, XSTRING (newstr)->data + from, produced); |
bcopy (buf.data, SDATA (newstr) + from, produced); |
6019 |
if (shrinked_bytes > from) |
if (shrinked_bytes > from) |
6020 |
bcopy (XSTRING (str)->data + to_byte, |
bcopy (SDATA (str) + to_byte, |
6021 |
XSTRING (newstr)->data + from + produced, |
SDATA (newstr) + from + produced, |
6022 |
shrinked_bytes - from); |
shrinked_bytes - from); |
6023 |
free_conversion_buffer (&buf); |
free_conversion_buffer (&buf); |
6024 |
|
|
6052 |
str = run_pre_post_conversion_on_str (str, coding, 1); |
str = run_pre_post_conversion_on_str (str, coding, 1); |
6053 |
|
|
6054 |
from = 0; |
from = 0; |
6055 |
to = XSTRING (str)->size; |
to = SCHARS (str); |
6056 |
to_byte = STRING_BYTES (XSTRING (str)); |
to_byte = SBYTES (str); |
6057 |
|
|
6058 |
/* Encoding routines determine the multibyteness of the source text |
/* Encoding routines determine the multibyteness of the source text |
6059 |
by coding->src_multibyte. */ |
by coding->src_multibyte. */ |
6061 |
coding->dst_multibyte = 0; |
coding->dst_multibyte = 0; |
6062 |
if (! CODING_REQUIRE_ENCODING (coding)) |
if (! CODING_REQUIRE_ENCODING (coding)) |
6063 |
{ |
{ |
6064 |
coding->consumed = STRING_BYTES (XSTRING (str)); |
coding->consumed = SBYTES (str); |
6065 |
coding->consumed_char = XSTRING (str)->size; |
coding->consumed_char = SCHARS (str); |
6066 |
if (STRING_MULTIBYTE (str)) |
if (STRING_MULTIBYTE (str)) |
6067 |
{ |
{ |
6068 |
str = Fstring_as_unibyte (str); |
str = Fstring_as_unibyte (str); |
6069 |
nocopy = 1; |
nocopy = 1; |
6070 |
} |
} |
6071 |
coding->produced = STRING_BYTES (XSTRING (str)); |
coding->produced = SBYTES (str); |
6072 |
coding->produced_char = XSTRING (str)->size; |
coding->produced_char = SCHARS (str); |
6073 |
return (nocopy ? str : Fcopy_sequence (str)); |
return (nocopy ? str : Fcopy_sequence (str)); |
6074 |
} |
} |
6075 |
|
|
6079 |
/* Try to skip the heading and tailing ASCIIs. */ |
/* Try to skip the heading and tailing ASCIIs. */ |
6080 |
if (coding->type != coding_type_ccl) |
if (coding->type != coding_type_ccl) |
6081 |
{ |
{ |
6082 |
SHRINK_CONVERSION_REGION (&from, &to_byte, coding, XSTRING (str)->data, |
SHRINK_CONVERSION_REGION (&from, &to_byte, coding, SDATA (str), |
6083 |
1); |
1); |
6084 |
if (from == to_byte) |
if (from == to_byte) |
6085 |
return (nocopy ? str : Fcopy_sequence (str)); |
return (nocopy ? str : Fcopy_sequence (str)); |
6086 |
shrinked_bytes = from + (STRING_BYTES (XSTRING (str)) - to_byte); |
shrinked_bytes = from + (SBYTES (str) - to_byte); |
6087 |
} |
} |
6088 |
|
|
6089 |
len = encoding_buffer_size (coding, to_byte - from); |
len = encoding_buffer_size (coding, to_byte - from); |
6092 |
consumed = consumed_char = produced = produced_char = 0; |
consumed = consumed_char = produced = produced_char = 0; |
6093 |
while (1) |
while (1) |
6094 |
{ |
{ |
6095 |
result = encode_coding (coding, XSTRING (str)->data + from + consumed, |
result = encode_coding (coding, SDATA (str) + from + consumed, |
6096 |
buf.data + produced, to_byte - from - consumed, |
buf.data + produced, to_byte - from - consumed, |
6097 |
buf.size - produced); |
buf.size - produced); |
6098 |
consumed += coding->consumed; |
consumed += coding->consumed; |
6114 |
|
|
6115 |
newstr = make_uninit_string (produced + shrinked_bytes); |
newstr = make_uninit_string (produced + shrinked_bytes); |
6116 |
if (from > 0) |
if (from > 0) |
6117 |
bcopy (XSTRING (str)->data, XSTRING (newstr)->data, from); |
bcopy (SDATA (str), SDATA (newstr), from); |
6118 |
bcopy (buf.data, XSTRING (newstr)->data + from, produced); |
bcopy (buf.data, SDATA (newstr) + from, produced); |
6119 |
if (shrinked_bytes > from) |
if (shrinked_bytes > from) |
6120 |
bcopy (XSTRING (str)->data + to_byte, |
bcopy (SDATA (str) + to_byte, |
6121 |
XSTRING (newstr)->data + from + produced, |
SDATA (newstr) + from + produced, |
6122 |
shrinked_bytes - from); |
shrinked_bytes - from); |
6123 |
|
|
6124 |
free_conversion_buffer (&buf); |
free_conversion_buffer (&buf); |
6160 |
val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
6161 |
Qt, Qnil, Qcoding_system_history, Qnil, Qnil); |
Qt, Qnil, Qcoding_system_history, Qnil, Qnil); |
6162 |
} |
} |
6163 |
while (XSTRING (val)->size == 0); |
while (SCHARS (val) == 0); |
6164 |
return (Fintern (val, Qnil)); |
return (Fintern (val, Qnil)); |
6165 |
} |
} |
6166 |
|
|
6176 |
val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, |
6177 |
Qt, Qnil, Qcoding_system_history, |
Qt, Qnil, Qcoding_system_history, |
6178 |
default_coding_system, Qnil); |
default_coding_system, Qnil); |
6179 |
return (XSTRING (val)->size == 0 ? Qnil : Fintern (val, Qnil)); |
return (SCHARS (val) == 0 ? Qnil : Fintern (val, Qnil)); |
6180 |
} |
} |
6181 |
|
|
6182 |
DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, |
DEFUN ("check-coding-system", Fcheck_coding_system, Scheck_coding_system, |
6318 |
{ |
{ |
6319 |
CHECK_STRING (string); |
CHECK_STRING (string); |
6320 |
|
|
6321 |
return detect_coding_system (XSTRING (string)->data, |
return detect_coding_system (SDATA (string), |
6322 |
/* "+ 1" is to include the anchor byte |
/* "+ 1" is to include the anchor byte |
6323 |
`\0'. With this, code detectors can |
`\0'. With this, code detectors can |
6324 |
handle the tailing bytes more |
handle the tailing bytes more |
6325 |
accurately. */ |
accurately. */ |
6326 |
STRING_BYTES (XSTRING (string)) + 1, |
SBYTES (string) + 1, |
6327 |
!NILP (highest), |
!NILP (highest), |
6328 |
STRING_MULTIBYTE (string)); |
STRING_MULTIBYTE (string)); |
6329 |
} |
} |
6420 |
{ |
{ |
6421 |
if (!STRING_MULTIBYTE (start)) |
if (!STRING_MULTIBYTE (start)) |
6422 |
return Qt; |
return Qt; |
6423 |
p1 = XSTRING (start)->data, p1end = p1 + STRING_BYTES (XSTRING (start)); |
p1 = SDATA (start), p1end = p1 + SBYTES (start); |
6424 |
p2 = p2end = p1end; |
p2 = p2end = p1end; |
6425 |
if (XSTRING (start)->size != STRING_BYTES (XSTRING (start))) |
if (SCHARS (start) != SBYTES (start)) |
6426 |
non_ascii_p = 1; |
non_ascii_p = 1; |
6427 |
} |
} |
6428 |
else |
else |
6508 |
return make_number (to - from); |
return make_number (to - from); |
6509 |
|
|
6510 |
if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
6511 |
error ("Invalid coding system: %s", XSTRING (SYMBOL_NAME (coding_system))->data); |
error ("Invalid coding system: %s", SDATA (SYMBOL_NAME (coding_system))); |
6512 |
|
|
6513 |
coding.mode |= CODING_MODE_LAST_BLOCK; |
coding.mode |= CODING_MODE_LAST_BLOCK; |
6514 |
coding.src_multibyte = coding.dst_multibyte |
coding.src_multibyte = coding.dst_multibyte |
6563 |
return (NILP (nocopy) ? Fcopy_sequence (string) : string); |
return (NILP (nocopy) ? Fcopy_sequence (string) : string); |
6564 |
|
|
6565 |
if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
6566 |
error ("Invalid coding system: %s", XSTRING (SYMBOL_NAME (coding_system))->data); |
error ("Invalid coding system: %s", SDATA (SYMBOL_NAME (coding_system))); |
6567 |
|
|
6568 |
coding.mode |= CODING_MODE_LAST_BLOCK; |
coding.mode |= CODING_MODE_LAST_BLOCK; |
6569 |
string = (encodep |
string = (encodep |
6622 |
return string; |
return string; |
6623 |
|
|
6624 |
if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
if (setup_coding_system (Fcheck_coding_system (coding_system), &coding) < 0) |
6625 |
error ("Invalid coding system: %s", XSTRING (SYMBOL_NAME (coding_system))->data); |
error ("Invalid coding system: %s", SDATA (SYMBOL_NAME (coding_system))); |
6626 |
|
|
6627 |
coding.composing = COMPOSITION_DISABLED; |
coding.composing = COMPOSITION_DISABLED; |
6628 |
coding.mode |= CODING_MODE_LAST_BLOCK; |
coding.mode |= CODING_MODE_LAST_BLOCK; |
6867 |
error ("Invalid first argument"); |
error ("Invalid first argument"); |
6868 |
if (nargs < 1 + XINT (target_idx)) |
if (nargs < 1 + XINT (target_idx)) |
6869 |
error ("Too few arguments for operation: %s", |
error ("Too few arguments for operation: %s", |
6870 |
XSTRING (SYMBOL_NAME (operation))->data); |
SDATA (SYMBOL_NAME (operation))); |
6871 |
target = args[XINT (target_idx) + 1]; |
target = args[XINT (target_idx) + 1]; |
6872 |
if (!(STRINGP (target) |
if (!(STRINGP (target) |
6873 |
|| (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) |
|| (EQ (operation, Qopen_network_stream) && INTEGERP (target)))) |
7430 |
Lisp_Object dec = code_convert_string_norecord (build_string (str), |
Lisp_Object dec = code_convert_string_norecord (build_string (str), |
7431 |
Vlocale_coding_system, |
Vlocale_coding_system, |
7432 |
0); |
0); |
7433 |
str = (char *) XSTRING (dec)->data; |
str = (char *) SDATA (dec); |
7434 |
} |
} |
7435 |
|
|
7436 |
return str; |
return str; |