diff options
| author | Tom Tromey | 2013-07-06 23:18:58 -0600 |
|---|---|---|
| committer | Tom Tromey | 2013-07-06 23:18:58 -0600 |
| commit | 6dacdad5fcb278e5a16b38bb81786aac9ca27be4 (patch) | |
| tree | f5f331ea361ba0f99e0f9b638d183ad492a7da31 /src/coding.c | |
| parent | 0a6f2ff0c8ceb29703e76cddd46ea3f176dd873a (diff) | |
| parent | 219afb88d9d484393418820d1c08dc93299110ec (diff) | |
| download | emacs-6dacdad5fcb278e5a16b38bb81786aac9ca27be4.tar.gz emacs-6dacdad5fcb278e5a16b38bb81786aac9ca27be4.zip | |
merge from trunk
this merges frmo trunk and fixes various build issues.
this needed a few ugly tweaks.
this hangs in "make check" now
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 92 |
1 files changed, 82 insertions, 10 deletions
diff --git a/src/coding.c b/src/coding.c index 42fd81b6322..1ab59294b98 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -649,12 +649,45 @@ static struct coding_system coding_categories[coding_category_max]; | |||
| 649 | #define max(a, b) ((a) > (b) ? (a) : (b)) | 649 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
| 650 | #endif | 650 | #endif |
| 651 | 651 | ||
| 652 | /* Encode a flag that can be nil, something else, or t as -1, 0, 1. */ | ||
| 653 | |||
| 654 | static int | ||
| 655 | encode_inhibit_flag (Lisp_Object flag) | ||
| 656 | { | ||
| 657 | return NILP (flag) ? -1 : EQ (flag, Qt); | ||
| 658 | } | ||
| 659 | |||
| 660 | /* True if the value of ENCODED_FLAG says a flag should be treated as set. | ||
| 661 | 1 means yes, -1 means no, 0 means ask the user variable VAR. */ | ||
| 662 | |||
| 663 | static bool | ||
| 664 | inhibit_flag (int encoded_flag, bool var) | ||
| 665 | { | ||
| 666 | return 0 < encoded_flag + var; | ||
| 667 | } | ||
| 668 | |||
| 652 | #define CODING_GET_INFO(coding, attrs, charset_list) \ | 669 | #define CODING_GET_INFO(coding, attrs, charset_list) \ |
| 653 | do { \ | 670 | do { \ |
| 654 | (attrs) = CODING_ID_ATTRS ((coding)->id); \ | 671 | (attrs) = CODING_ID_ATTRS ((coding)->id); \ |
| 655 | (charset_list) = CODING_ATTR_CHARSET_LIST (attrs); \ | 672 | (charset_list) = CODING_ATTR_CHARSET_LIST (attrs); \ |
| 656 | } while (0) | 673 | } while (0) |
| 657 | 674 | ||
| 675 | static void | ||
| 676 | CHECK_NATNUM_CAR (Lisp_Object x) | ||
| 677 | { | ||
| 678 | Lisp_Object tmp = XCAR (x); | ||
| 679 | CHECK_NATNUM (tmp); | ||
| 680 | XSETCAR (x, tmp); | ||
| 681 | } | ||
| 682 | |||
| 683 | static void | ||
| 684 | CHECK_NATNUM_CDR (Lisp_Object x) | ||
| 685 | { | ||
| 686 | Lisp_Object tmp = XCDR (x); | ||
| 687 | CHECK_NATNUM (tmp); | ||
| 688 | XSETCDR (x, tmp); | ||
| 689 | } | ||
| 690 | |||
| 658 | 691 | ||
| 659 | /* Safely get one byte from the source text pointed by SRC which ends | 692 | /* Safely get one byte from the source text pointed by SRC which ends |
| 660 | at SRC_END, and set C to that byte. If there are not enough bytes | 693 | at SRC_END, and set C to that byte. If there are not enough bytes |
| @@ -5689,6 +5722,14 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding) | |||
| 5689 | coding->decoder = decode_coding_raw_text; | 5722 | coding->decoder = decode_coding_raw_text; |
| 5690 | coding->encoder = encode_coding_raw_text; | 5723 | coding->encoder = encode_coding_raw_text; |
| 5691 | coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; | 5724 | coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; |
| 5725 | coding->spec.undecided.inhibit_nbd | ||
| 5726 | = (encode_inhibit_flag | ||
| 5727 | (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection))); | ||
| 5728 | coding->spec.undecided.inhibit_ied | ||
| 5729 | = (encode_inhibit_flag | ||
| 5730 | (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection))); | ||
| 5731 | coding->spec.undecided.prefer_utf_8 | ||
| 5732 | = ! NILP (AREF (attrs, coding_attr_undecided_prefer_utf_8)); | ||
| 5692 | } | 5733 | } |
| 5693 | else if (EQ (coding_type, Qiso_2022)) | 5734 | else if (EQ (coding_type, Qiso_2022)) |
| 5694 | { | 5735 | { |
| @@ -6446,6 +6487,11 @@ detect_coding (struct coding_system *coding) | |||
| 6446 | int c, i; | 6487 | int c, i; |
| 6447 | struct coding_detection_info detect_info; | 6488 | struct coding_detection_info detect_info; |
| 6448 | bool null_byte_found = 0, eight_bit_found = 0; | 6489 | bool null_byte_found = 0, eight_bit_found = 0; |
| 6490 | bool inhibit_nbd = inhibit_flag (coding->spec.undecided.inhibit_nbd, | ||
| 6491 | inhibit_null_byte_detection); | ||
| 6492 | bool inhibit_ied = inhibit_flag (coding->spec.undecided.inhibit_ied, | ||
| 6493 | inhibit_iso_escape_detection); | ||
| 6494 | bool prefer_utf_8 = coding->spec.undecided.prefer_utf_8; | ||
| 6449 | 6495 | ||
| 6450 | coding->head_ascii = 0; | 6496 | coding->head_ascii = 0; |
| 6451 | detect_info.checked = detect_info.found = detect_info.rejected = 0; | 6497 | detect_info.checked = detect_info.found = detect_info.rejected = 0; |
| @@ -6461,7 +6507,7 @@ detect_coding (struct coding_system *coding) | |||
| 6461 | else if (c < 0x20) | 6507 | else if (c < 0x20) |
| 6462 | { | 6508 | { |
| 6463 | if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) | 6509 | if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) |
| 6464 | && ! inhibit_iso_escape_detection | 6510 | && ! inhibit_ied |
| 6465 | && ! detect_info.checked) | 6511 | && ! detect_info.checked) |
| 6466 | { | 6512 | { |
| 6467 | if (detect_coding_iso_2022 (coding, &detect_info)) | 6513 | if (detect_coding_iso_2022 (coding, &detect_info)) |
| @@ -6480,7 +6526,7 @@ detect_coding (struct coding_system *coding) | |||
| 6480 | break; | 6526 | break; |
| 6481 | } | 6527 | } |
| 6482 | } | 6528 | } |
| 6483 | else if (! c && !inhibit_null_byte_detection) | 6529 | else if (! c && !inhibit_nbd) |
| 6484 | { | 6530 | { |
| 6485 | null_byte_found = 1; | 6531 | null_byte_found = 1; |
| 6486 | if (eight_bit_found) | 6532 | if (eight_bit_found) |
| @@ -6537,6 +6583,12 @@ detect_coding (struct coding_system *coding) | |||
| 6537 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; | 6583 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; |
| 6538 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; | 6584 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; |
| 6539 | } | 6585 | } |
| 6586 | else if (prefer_utf_8 | ||
| 6587 | && detect_coding_utf_8 (coding, &detect_info)) | ||
| 6588 | { | ||
| 6589 | detect_info.checked |= ~CATEGORY_MASK_UTF_8; | ||
| 6590 | detect_info.rejected |= ~CATEGORY_MASK_UTF_8; | ||
| 6591 | } | ||
| 6540 | for (i = 0; i < coding_category_raw_text; i++) | 6592 | for (i = 0; i < coding_category_raw_text; i++) |
| 6541 | { | 6593 | { |
| 6542 | category = coding_priorities[i]; | 6594 | category = coding_priorities[i]; |
| @@ -8498,6 +8550,11 @@ detect_coding_system (const unsigned char *src, | |||
| 8498 | enum coding_category category IF_LINT (= 0); | 8550 | enum coding_category category IF_LINT (= 0); |
| 8499 | struct coding_system *this IF_LINT (= NULL); | 8551 | struct coding_system *this IF_LINT (= NULL); |
| 8500 | int c, i; | 8552 | int c, i; |
| 8553 | bool inhibit_nbd = inhibit_flag (coding.spec.undecided.inhibit_nbd, | ||
| 8554 | inhibit_null_byte_detection); | ||
| 8555 | bool inhibit_ied = inhibit_flag (coding.spec.undecided.inhibit_ied, | ||
| 8556 | inhibit_iso_escape_detection); | ||
| 8557 | bool prefer_utf_8 = coding.spec.undecided.prefer_utf_8; | ||
| 8501 | 8558 | ||
| 8502 | /* Skip all ASCII bytes except for a few ISO2022 controls. */ | 8559 | /* Skip all ASCII bytes except for a few ISO2022 controls. */ |
| 8503 | for (; src < src_end; src++) | 8560 | for (; src < src_end; src++) |
| @@ -8512,7 +8569,7 @@ detect_coding_system (const unsigned char *src, | |||
| 8512 | else if (c < 0x20) | 8569 | else if (c < 0x20) |
| 8513 | { | 8570 | { |
| 8514 | 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) |
| 8515 | && ! inhibit_iso_escape_detection | 8572 | && ! inhibit_ied |
| 8516 | && ! detect_info.checked) | 8573 | && ! detect_info.checked) |
| 8517 | { | 8574 | { |
| 8518 | if (detect_coding_iso_2022 (&coding, &detect_info)) | 8575 | if (detect_coding_iso_2022 (&coding, &detect_info)) |
| @@ -8531,7 +8588,7 @@ detect_coding_system (const unsigned char *src, | |||
| 8531 | break; | 8588 | break; |
| 8532 | } | 8589 | } |
| 8533 | } | 8590 | } |
| 8534 | else if (! c && !inhibit_null_byte_detection) | 8591 | else if (! c && !inhibit_nbd) |
| 8535 | { | 8592 | { |
| 8536 | null_byte_found = 1; | 8593 | null_byte_found = 1; |
| 8537 | if (eight_bit_found) | 8594 | if (eight_bit_found) |
| @@ -8564,6 +8621,12 @@ detect_coding_system (const unsigned char *src, | |||
| 8564 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; | 8621 | detect_info.checked |= ~CATEGORY_MASK_UTF_16; |
| 8565 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; | 8622 | detect_info.rejected |= ~CATEGORY_MASK_UTF_16; |
| 8566 | } | 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 | } | ||
| 8567 | for (i = 0; i < coding_category_raw_text; i++) | 8630 | for (i = 0; i < coding_category_raw_text; i++) |
| 8568 | { | 8631 | { |
| 8569 | category = coding_priorities[i]; | 8632 | category = coding_priorities[i]; |
| @@ -8902,8 +8965,7 @@ DEFUN ("find-coding-systems-region-internal", | |||
| 8902 | Lisp_Object attrs; | 8965 | Lisp_Object attrs; |
| 8903 | 8966 | ||
| 8904 | attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); | 8967 | attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); |
| 8905 | if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) | 8968 | if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs))) |
| 8906 | && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) | ||
| 8907 | { | 8969 | { |
| 8908 | ASET (attrs, coding_attr_trans_tbl, | 8970 | ASET (attrs, coding_attr_trans_tbl, |
| 8909 | get_translation_table (attrs, 1, NULL)); | 8971 | get_translation_table (attrs, 1, NULL)); |
| @@ -10317,7 +10379,17 @@ usage: (define-coding-system-internal ...) */) | |||
| 10317 | : coding_category_utf_8_sig); | 10379 | : coding_category_utf_8_sig); |
| 10318 | } | 10380 | } |
| 10319 | else if (EQ (coding_type, Qundecided)) | 10381 | else if (EQ (coding_type, Qundecided)) |
| 10320 | 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 | } | ||
| 10321 | else | 10393 | else |
| 10322 | error ("Invalid coding system type: %s", | 10394 | error ("Invalid coding system type: %s", |
| 10323 | SDATA (SYMBOL_NAME (coding_type))); | 10395 | SDATA (SYMBOL_NAME (coding_type))); |
| @@ -11105,11 +11177,11 @@ internal character representation. */); | |||
| 11105 | Vtranslation_table_for_input = Qnil; | 11177 | Vtranslation_table_for_input = Qnil; |
| 11106 | 11178 | ||
| 11107 | { | 11179 | { |
| 11108 | Lisp_Object args[coding_arg_max]; | 11180 | Lisp_Object args[coding_arg_undecided_max]; |
| 11109 | Lisp_Object plist[16]; | 11181 | Lisp_Object plist[16]; |
| 11110 | int i; | 11182 | int i; |
| 11111 | 11183 | ||
| 11112 | for (i = 0; i < coding_arg_max; i++) | 11184 | for (i = 0; i < coding_arg_undecided_max; i++) |
| 11113 | args[i] = Qnil; | 11185 | args[i] = Qnil; |
| 11114 | 11186 | ||
| 11115 | plist[0] = intern_c_string (":name"); | 11187 | plist[0] = intern_c_string (":name"); |
| @@ -11146,7 +11218,7 @@ character."); | |||
| 11146 | 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."); |
| 11147 | plist[15] = args[coding_arg_eol_type] = Qnil; | 11219 | plist[15] = args[coding_arg_eol_type] = Qnil; |
| 11148 | args[coding_arg_plist] = Flist (16, plist); | 11220 | args[coding_arg_plist] = Flist (16, plist); |
| 11149 | Fdefine_coding_system_internal (coding_arg_max, args); | 11221 | Fdefine_coding_system_internal (coding_arg_undecided_max, args); |
| 11150 | } | 11222 | } |
| 11151 | 11223 | ||
| 11152 | setup_coding_system (Qno_conversion, &safe_terminal_coding); | 11224 | setup_coding_system (Qno_conversion, &safe_terminal_coding); |