diff options
| author | Kenichi Handa | 2013-06-29 00:00:17 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2013-06-29 00:00:17 +0900 |
| commit | c3a7b3f45f9baffd3e7b4dbc4381fd67356adb44 (patch) | |
| tree | ff227b5eb694132b58007e8ccda4ee12a486e16b /src/coding.c | |
| parent | 270afa77ee4ddb2144ba35c9745a43fdf02e653d (diff) | |
| download | emacs-c3a7b3f45f9baffd3e7b4dbc4381fd67356adb44.tar.gz emacs-c3a7b3f45f9baffd3e7b4dbc4381fd67356adb44.zip | |
coding.c (setup_coding_system): Handle CODING->spec.undecided.
(detect_coding): Likewise.
(detect_coding_system): Likewise.
(Fdefine_coding_system_internal): New coding system properties
:inhibit-null-byte-detection, :inhibit-iso-escape-detection, and
:prefer-utf-8.
(syms_of_coding): Adjusted for coding_arg_undecided_max.
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/src/coding.c b/src/coding.c index 497c26d4856..c4aaefa8182 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -5705,6 +5705,20 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding) | |||
| 5705 | coding->decoder = decode_coding_raw_text; | 5705 | coding->decoder = decode_coding_raw_text; |
| 5706 | coding->encoder = encode_coding_raw_text; | 5706 | coding->encoder = encode_coding_raw_text; |
| 5707 | coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | 5707 | coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; |
| 5708 | coding->spec.undecided.inhibit_nbd | ||
| 5709 | = (NILP (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection)) | ||
| 5710 | ? -1 | ||
| 5711 | : EQ (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection), Qt) | ||
| 5712 | ? 1 | ||
| 5713 | : 0); | ||
| 5714 | coding->spec.undecided.inhibit_ied | ||
| 5715 | = (NILP (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection)) | ||
| 5716 | ? -1 | ||
| 5717 | : EQ (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection), Qt) | ||
| 5718 | ? 1 | ||
| 5719 | : 0); | ||
| 5720 | coding->spec.undecided.prefer_utf_8 | ||
| 5721 | = ! NILP (AREF (attrs, coding_attr_undecided_prefer_utf_8)); | ||
| 5708 | } | 5722 | } |
| 5709 | else if (EQ (coding_type, Qiso_2022)) | 5723 | else if (EQ (coding_type, Qiso_2022)) |
| 5710 | { | 5724 | { |
| @@ -6462,6 +6476,16 @@ detect_coding (struct coding_system *coding) | |||
| 6462 | int c, i; | 6476 | int c, i; |
| 6463 | struct coding_detection_info detect_info; | 6477 | struct coding_detection_info detect_info; |
| 6464 | bool null_byte_found = 0, eight_bit_found = 0; | 6478 | bool null_byte_found = 0, eight_bit_found = 0; |
| 6479 | int inhibit_nbd /* null byte detection */ | ||
| 6480 | = (coding->spec.undecided.inhibit_nbd > 0 | ||
| 6481 | | (coding->spec.undecided.inhibit_nbd == 0 | ||
| 6482 | & inhibit_null_byte_detection)); | ||
| 6483 | int inhibit_ied /* iso escape detection */ | ||
| 6484 | = (coding->spec.undecided.inhibit_ied > 0 | ||
| 6485 | | (coding->spec.undecided.inhibit_ied == 0 | ||
| 6486 | & inhibit_iso_escape_detection)); | ||
| 6487 | int prefer_utf_8 | ||
| 6488 | = coding->spec.undecided.prefer_utf_8; | ||
| 6465 | 6489 | ||
| 6466 | coding->head_ascii = 0; | 6490 | coding->head_ascii = 0; |
| 6467 | detect_info.checked = detect_info.found = detect_info.rejected = 0; | 6491 | detect_info.checked = detect_info.found = detect_info.rejected = 0; |
| @@ -6477,7 +6501,7 @@ detect_coding (struct coding_system *coding) | |||
| 6477 | else if (c < 0x20) | 6501 | else if (c < 0x20) |
| 6478 | { | 6502 | { |
| 6479 | if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) | 6503 | if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) |
| 6480 | && ! inhibit_iso_escape_detection | 6504 | && ! inhibit_ied |
| 6481 | && ! detect_info.checked) | 6505 | && ! detect_info.checked) |
| 6482 | { | 6506 | { |
| 6483 | if (detect_coding_iso_2022 (coding, &detect_info)) | 6507 | if (detect_coding_iso_2022 (coding, &detect_info)) |
| @@ -6496,7 +6520,7 @@ detect_coding (struct coding_system *coding) | |||
| 6496 | break; | 6520 | break; |
| 6497 | } | 6521 | } |
| 6498 | } | 6522 | } |
| 6499 | else if (! c && !inhibit_null_byte_detection) | 6523 | else if (! c && !inhibit_nbd) |
| 6500 | { | 6524 | { |
| 6501 | null_byte_found = 1; | 6525 | null_byte_found = 1; |
| 6502 | if (eight_bit_found) | 6526 | if (eight_bit_found) |
| @@ -6553,6 +6577,12 @@ detect_coding (struct coding_system *coding) | |||
| 6553 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; | 6577 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; |
| 6554 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; | 6578 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; |
| 6555 | } | 6579 | } |
| 6580 | else if (prefer_utf_8 | ||
| 6581 | && detect_coding_utf_8 (coding, &detect_info)) | ||
| 6582 | { | ||
| 6583 | detect_info.checked |= ~CATEGORY_MASK_UTF_8; | ||
| 6584 | detect_info.rejected |= ~CATEGORY_MASK_UTF_8; | ||
| 6585 | } | ||
| 6556 | for (i = 0; i < coding_category_raw_text; i++) | 6586 | for (i = 0; i < coding_category_raw_text; i++) |
| 6557 | { | 6587 | { |
| 6558 | category = coding_priorities[i]; | 6588 | category = coding_priorities[i]; |
| @@ -8514,6 +8544,17 @@ detect_coding_system (const unsigned char *src, | |||
| 8514 | enum coding_category category IF_LINT (= 0); | 8544 | enum coding_category category IF_LINT (= 0); |
| 8515 | struct coding_system *this IF_LINT (= NULL); | 8545 | struct coding_system *this IF_LINT (= NULL); |
| 8516 | int c, i; | 8546 | int c, i; |
| 8547 | int inhibit_nbd /* null byte detection */ | ||
| 8548 | = (coding.spec.undecided.inhibit_nbd > 0 | ||
| 8549 | | (coding.spec.undecided.inhibit_nbd == 0 | ||
| 8550 | & inhibit_null_byte_detection)); | ||
| 8551 | int inhibit_ied /* iso escape detection */ | ||
| 8552 | = (coding.spec.undecided.inhibit_ied > 0 | ||
| 8553 | | (coding.spec.undecided.inhibit_ied == 0 | ||
| 8554 | & inhibit_iso_escape_detection)); | ||
| 8555 | int prefer_utf_8 | ||
| 8556 | = coding.spec.undecided.prefer_utf_8; | ||
| 8557 | |||
| 8517 | 8558 | ||
| 8518 | /* Skip all ASCII bytes except for a few ISO2022 controls. */ | 8559 | /* Skip all ASCII bytes except for a few ISO2022 controls. */ |
| 8519 | for (; src < src_end; src++) | 8560 | for (; src < src_end; src++) |
| @@ -8528,7 +8569,7 @@ detect_coding_system (const unsigned char *src, | |||
| 8528 | else if (c < 0x20) | 8569 | else if (c < 0x20) |
| 8529 | { | 8570 | { |
| 8530 | if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) | 8571 | if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) |
| 8531 | && ! inhibit_iso_escape_detection | 8572 | && ! inhibit_ied |
| 8532 | && ! detect_info.checked) | 8573 | && ! detect_info.checked) |
| 8533 | { | 8574 | { |
| 8534 | if (detect_coding_iso_2022 (&coding, &detect_info)) | 8575 | if (detect_coding_iso_2022 (&coding, &detect_info)) |
| @@ -8547,7 +8588,7 @@ detect_coding_system (const unsigned char *src, | |||
| 8547 | break; | 8588 | break; |
| 8548 | } | 8589 | } |
| 8549 | } | 8590 | } |
| 8550 | else if (! c && !inhibit_null_byte_detection) | 8591 | else if (! c && !inhibit_nbd) |
| 8551 | { | 8592 | { |
| 8552 | null_byte_found = 1; | 8593 | null_byte_found = 1; |
| 8553 | if (eight_bit_found) | 8594 | if (eight_bit_found) |
| @@ -8580,6 +8621,12 @@ detect_coding_system (const unsigned char *src, | |||
| 8580 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; | 8621 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; |
| 8581 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; | 8622 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; |
| 8582 | } | 8623 | } |
| 8624 | else if (prefer_utf_8 | ||
| 8625 | && detect_coding_utf_8 (&coding, &detect_info)) | ||
| 8626 | { | ||
| 8627 | detect_info.checked |= ~CATEGORY_MASK_UTF_8; | ||
| 8628 | detect_info.rejected |= ~CATEGORY_MASK_UTF_8; | ||
| 8629 | } | ||
| 8583 | for (i = 0; i < coding_category_raw_text; i++) | 8630 | for (i = 0; i < coding_category_raw_text; i++) |
| 8584 | { | 8631 | { |
| 8585 | category = coding_priorities[i]; | 8632 | category = coding_priorities[i]; |
| @@ -8918,8 +8965,7 @@ DEFUN ("find-coding-systems-region-internal", | |||
| 8918 | Lisp_Object attrs; | 8965 | Lisp_Object attrs; |
| 8919 | 8966 | ||
| 8920 | attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | 8967 | attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); |
| 8921 | if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | 8968 | if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs))) |
| 8922 | && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | ||
| 8923 | { | 8969 | { |
| 8924 | ASET (attrs, coding_attr_trans_tbl, | 8970 | ASET (attrs, coding_attr_trans_tbl, |
| 8925 | get_translation_table (attrs, 1, NULL)); | 8971 | get_translation_table (attrs, 1, NULL)); |
| @@ -10333,7 +10379,17 @@ usage: (define-coding-system-internal ...) */) | |||
| 10333 | : coding_category_utf_8_sig); | 10379 | : coding_category_utf_8_sig); |
| 10334 | } | 10380 | } |
| 10335 | else if (EQ (coding_type, Qundecided)) | 10381 | else if (EQ (coding_type, Qundecided)) |
| 10336 | category = coding_category_undecided; | 10382 | { |
| 10383 | if (nargs < coding_arg_undecided_max) | ||
| 10384 | goto short_args; | ||
| 10385 | ASET (attrs, coding_attr_undecided_inhibit_null_byte_detection, | ||
| 10386 | args[coding_arg_undecided_inhibit_null_byte_detection]); | ||
| 10387 | ASET (attrs, coding_attr_undecided_inhibit_iso_escape_detection, | ||
| 10388 | args[coding_arg_undecided_inhibit_iso_escape_detection]); | ||
| 10389 | ASET (attrs, coding_attr_undecided_prefer_utf_8, | ||
| 10390 | args[coding_arg_undecided_prefer_utf_8]); | ||
| 10391 | category = coding_category_undecided; | ||
| 10392 | } | ||
| 10337 | else | 10393 | else |
| 10338 | error ("Invalid coding system type: %s", | 10394 | error ("Invalid coding system type: %s", |
| 10339 | SDATA (SYMBOL_NAME (coding_type))); | 10395 | SDATA (SYMBOL_NAME (coding_type))); |
| @@ -11121,11 +11177,11 @@ internal character representation. */); | |||
| 11121 | Vtranslation_table_for_input = Qnil; | 11177 | Vtranslation_table_for_input = Qnil; |
| 11122 | 11178 | ||
| 11123 | { | 11179 | { |
| 11124 | Lisp_Object args[coding_arg_max]; | 11180 | Lisp_Object args[coding_arg_undecided_max]; |
| 11125 | Lisp_Object plist[16]; | 11181 | Lisp_Object plist[16]; |
| 11126 | int i; | 11182 | int i; |
| 11127 | 11183 | ||
| 11128 | for (i = 0; i < coding_arg_max; i++) | 11184 | for (i = 0; i < coding_arg_undecided_max; i++) |
| 11129 | args[i] = Qnil; | 11185 | args[i] = Qnil; |
| 11130 | 11186 | ||
| 11131 | plist[0] = intern_c_string (":name"); | 11187 | plist[0] = intern_c_string (":name"); |
| @@ -11162,7 +11218,7 @@ character."); | |||
| 11162 | plist[13] = build_pure_c_string ("No conversion on encoding, automatic conversion on decoding."); | 11218 | plist[13] = build_pure_c_string ("No conversion on encoding, automatic conversion on decoding."); |
| 11163 | plist[15] = args[coding_arg_eol_type] = Qnil; | 11219 | plist[15] = args[coding_arg_eol_type] = Qnil; |
| 11164 | args[coding_arg_plist] = Flist (16, plist); | 11220 | args[coding_arg_plist] = Flist (16, plist); |
| 11165 | Fdefine_coding_system_internal (coding_arg_max, args); | 11221 | Fdefine_coding_system_internal (coding_arg_undecided_max, args); |
| 11166 | } | 11222 | } |
| 11167 | 11223 | ||
| 11168 | setup_coding_system (Qno_conversion, &safe_terminal_coding); | 11224 | setup_coding_system (Qno_conversion, &safe_terminal_coding); |