diff options
| author | Miles Bader | 2008-02-01 16:01:31 +0000 |
|---|---|---|
| committer | Miles Bader | 2008-02-01 16:01:31 +0000 |
| commit | 6cc41fb06c37234822d5aedf7ce0f77b88bb450a (patch) | |
| tree | a130326faf29d4410ed126e4f0d6a13f11a19df3 /src/callproc.c | |
| parent | b502217bd845bc6280fd2bb1eacce176ed4f7d90 (diff) | |
| parent | dd559368b0db67654f643320b1d84afdabe60e97 (diff) | |
| download | emacs-6cc41fb06c37234822d5aedf7ce0f77b88bb450a.tar.gz emacs-6cc41fb06c37234822d5aedf7ce0f77b88bb450a.zip | |
Merge unicode branch
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1037
Diffstat (limited to 'src/callproc.c')
| -rw-r--r-- | src/callproc.c | 202 |
1 files changed, 45 insertions, 157 deletions
diff --git a/src/callproc.c b/src/callproc.c index 3a725b80a0a..a3b7b7afa4a 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -76,7 +76,7 @@ extern int errno; | |||
| 76 | #include "lisp.h" | 76 | #include "lisp.h" |
| 77 | #include "commands.h" | 77 | #include "commands.h" |
| 78 | #include "buffer.h" | 78 | #include "buffer.h" |
| 79 | #include "charset.h" | 79 | #include "character.h" |
| 80 | #include "ccl.h" | 80 | #include "ccl.h" |
| 81 | #include "coding.h" | 81 | #include "coding.h" |
| 82 | #include "composite.h" | 82 | #include "composite.h" |
| @@ -275,6 +275,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 275 | if (nargs >= 5) | 275 | if (nargs >= 5) |
| 276 | { | 276 | { |
| 277 | int must_encode = 0; | 277 | int must_encode = 0; |
| 278 | Lisp_Object coding_attrs; | ||
| 278 | 279 | ||
| 279 | for (i = 4; i < nargs; i++) | 280 | for (i = 4; i < nargs; i++) |
| 280 | CHECK_STRING (args[i]); | 281 | CHECK_STRING (args[i]); |
| @@ -300,11 +301,15 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 300 | else | 301 | else |
| 301 | val = Qnil; | 302 | val = Qnil; |
| 302 | } | 303 | } |
| 304 | val = coding_inherit_eol_type (val, Qnil); | ||
| 303 | setup_coding_system (Fcheck_coding_system (val), &argument_coding); | 305 | setup_coding_system (Fcheck_coding_system (val), &argument_coding); |
| 304 | if (argument_coding.common_flags & CODING_ASCII_INCOMPATIBLE_MASK) | 306 | coding_attrs = CODING_ID_ATTRS (argument_coding.id); |
| 305 | setup_coding_system (Qraw_text, &argument_coding); | 307 | if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs))) |
| 306 | if (argument_coding.eol_type == CODING_EOL_UNDECIDED) | 308 | { |
| 307 | argument_coding.eol_type = system_eol_type; | 309 | /* We should not use an ASCII incompatible coding system. */ |
| 310 | val = raw_text_coding_system (val); | ||
| 311 | setup_coding_system (val, &argument_coding); | ||
| 312 | } | ||
| 308 | } | 313 | } |
| 309 | } | 314 | } |
| 310 | 315 | ||
| @@ -427,12 +432,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 427 | { | 432 | { |
| 428 | argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]); | 433 | argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]); |
| 429 | if (CODING_REQUIRE_ENCODING (&argument_coding)) | 434 | if (CODING_REQUIRE_ENCODING (&argument_coding)) |
| 430 | { | 435 | /* We must encode this argument. */ |
| 431 | /* We must encode this argument. */ | 436 | args[i] = encode_coding_string (&argument_coding, args[i], 1); |
| 432 | args[i] = encode_coding_string (args[i], &argument_coding, 1); | ||
| 433 | if (argument_coding.type == coding_type_ccl) | ||
| 434 | setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil); | ||
| 435 | } | ||
| 436 | new_argv[i - 3] = SDATA (args[i]); | 437 | new_argv[i - 3] = SDATA (args[i]); |
| 437 | } | 438 | } |
| 438 | UNGCPRO; | 439 | UNGCPRO; |
| @@ -675,19 +676,15 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 675 | else | 676 | else |
| 676 | val = Qnil; | 677 | val = Qnil; |
| 677 | } | 678 | } |
| 678 | setup_coding_system (Fcheck_coding_system (val), &process_coding); | 679 | Fcheck_coding_system (val); |
| 679 | /* In unibyte mode, character code conversion should not take | 680 | /* In unibyte mode, character code conversion should not take |
| 680 | place but EOL conversion should. So, setup raw-text or one | 681 | place but EOL conversion should. So, setup raw-text or one |
| 681 | of the subsidiary according to the information just setup. */ | 682 | of the subsidiary according to the information just setup. */ |
| 682 | if (NILP (current_buffer->enable_multibyte_characters) | 683 | if (NILP (current_buffer->enable_multibyte_characters) |
| 683 | && !NILP (val)) | 684 | && !NILP (val)) |
| 684 | setup_raw_text_coding_system (&process_coding); | 685 | val = raw_text_coding_system (val); |
| 686 | setup_coding_system (val, &process_coding); | ||
| 685 | } | 687 | } |
| 686 | process_coding.src_multibyte = 0; | ||
| 687 | process_coding.dst_multibyte | ||
| 688 | = (BUFFERP (buffer) | ||
| 689 | ? ! NILP (XBUFFER (buffer)->enable_multibyte_characters) | ||
| 690 | : ! NILP (current_buffer->enable_multibyte_characters)); | ||
| 691 | 688 | ||
| 692 | immediate_quit = 1; | 689 | immediate_quit = 1; |
| 693 | QUIT; | 690 | QUIT; |
| @@ -699,12 +696,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 699 | int carryover = 0; | 696 | int carryover = 0; |
| 700 | int display_on_the_fly = display_p; | 697 | int display_on_the_fly = display_p; |
| 701 | struct coding_system saved_coding; | 698 | struct coding_system saved_coding; |
| 702 | int pt_orig = PT, pt_byte_orig = PT_BYTE; | ||
| 703 | int inserted; | ||
| 704 | 699 | ||
| 705 | saved_coding = process_coding; | 700 | saved_coding = process_coding; |
| 706 | if (process_coding.composing != COMPOSITION_DISABLED) | ||
| 707 | coding_allocate_composition_data (&process_coding, PT); | ||
| 708 | while (1) | 701 | while (1) |
| 709 | { | 702 | { |
| 710 | /* Repeatedly read until we've filled as much as possible | 703 | /* Repeatedly read until we've filled as much as possible |
| @@ -737,133 +730,49 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 737 | 730 | ||
| 738 | if (!NILP (buffer)) | 731 | if (!NILP (buffer)) |
| 739 | { | 732 | { |
| 740 | if (! CODING_MAY_REQUIRE_DECODING (&process_coding)) | 733 | if (NILP (current_buffer->enable_multibyte_characters) |
| 734 | && ! CODING_MAY_REQUIRE_DECODING (&process_coding)) | ||
| 741 | insert_1_both (buf, nread, nread, 0, 1, 0); | 735 | insert_1_both (buf, nread, nread, 0, 1, 0); |
| 742 | else | 736 | else |
| 743 | { /* We have to decode the input. */ | 737 | { /* We have to decode the input. */ |
| 744 | int size; | 738 | Lisp_Object curbuf; |
| 745 | char *decoding_buf; | ||
| 746 | |||
| 747 | repeat_decoding: | ||
| 748 | size = decoding_buffer_size (&process_coding, nread); | ||
| 749 | decoding_buf = (char *) xmalloc (size); | ||
| 750 | |||
| 751 | /* We can't use the macro CODING_REQUIRE_DETECTION | ||
| 752 | because it always returns nonzero if the coding | ||
| 753 | system requires EOL detection. Here, we have to | ||
| 754 | check only whether or not the coding system | ||
| 755 | requires text-encoding detection. */ | ||
| 756 | if (process_coding.type == coding_type_undecided) | ||
| 757 | { | ||
| 758 | detect_coding (&process_coding, buf, nread); | ||
| 759 | if (process_coding.composing != COMPOSITION_DISABLED) | ||
| 760 | /* We have not yet allocated the composition | ||
| 761 | data because the coding type was undecided. */ | ||
| 762 | coding_allocate_composition_data (&process_coding, PT); | ||
| 763 | } | ||
| 764 | if (process_coding.cmp_data) | ||
| 765 | process_coding.cmp_data->char_offset = PT; | ||
| 766 | |||
| 767 | decode_coding (&process_coding, buf, decoding_buf, | ||
| 768 | nread, size); | ||
| 769 | 739 | ||
| 740 | XSETBUFFER (curbuf, current_buffer); | ||
| 741 | decode_coding_c_string (&process_coding, buf, nread, | ||
| 742 | curbuf); | ||
| 770 | if (display_on_the_fly | 743 | if (display_on_the_fly |
| 771 | && saved_coding.type == coding_type_undecided | 744 | && CODING_REQUIRE_DETECTION (&saved_coding) |
| 772 | && process_coding.type != coding_type_undecided) | 745 | && ! CODING_REQUIRE_DETECTION (&process_coding)) |
| 773 | { | 746 | { |
| 774 | /* We have detected some coding system. But, | 747 | /* We have detected some coding system. But, |
| 775 | there's a possibility that the detection was | 748 | there's a possibility that the detection was |
| 776 | done by insufficient data. So, we try the code | 749 | done by insufficient data. So, we give up |
| 777 | detection again with more data. */ | 750 | displaying on the fly. */ |
| 778 | xfree (decoding_buf); | 751 | if (process_coding.produced > 0) |
| 752 | del_range_2 (process_coding.dst_pos, | ||
| 753 | process_coding.dst_pos_byte, | ||
| 754 | process_coding.dst_pos | ||
| 755 | + process_coding.produced_char, | ||
| 756 | process_coding.dst_pos_byte | ||
| 757 | + process_coding.produced, 0); | ||
| 779 | display_on_the_fly = 0; | 758 | display_on_the_fly = 0; |
| 780 | process_coding = saved_coding; | 759 | process_coding = saved_coding; |
| 781 | carryover = nread; | 760 | carryover = nread; |
| 782 | /* This is to make the above condition always | 761 | /* This is to make the above condition always |
| 783 | fails in the future. */ | 762 | fails in the future. */ |
| 784 | saved_coding.type = coding_type_no_conversion; | 763 | saved_coding.common_flags |
| 764 | &= ~CODING_REQUIRE_DETECTION_MASK; | ||
| 785 | continue; | 765 | continue; |
| 786 | } | 766 | } |
| 787 | 767 | ||
| 788 | if (process_coding.produced > 0) | 768 | TEMP_SET_PT_BOTH (PT + process_coding.produced_char, |
| 789 | insert_1_both (decoding_buf, process_coding.produced_char, | 769 | PT_BYTE + process_coding.produced); |
| 790 | process_coding.produced, 0, 1, 0); | 770 | carryover = process_coding.carryover_bytes; |
| 791 | xfree (decoding_buf); | ||
| 792 | |||
| 793 | if (process_coding.result == CODING_FINISH_INCONSISTENT_EOL) | ||
| 794 | { | ||
| 795 | Lisp_Object eol_type, coding; | ||
| 796 | |||
| 797 | if (process_coding.eol_type == CODING_EOL_CR) | ||
| 798 | { | ||
| 799 | /* CRs have been replaced with LFs. Undo | ||
| 800 | that in the text inserted above. */ | ||
| 801 | unsigned char *p; | ||
| 802 | |||
| 803 | move_gap_both (PT, PT_BYTE); | ||
| 804 | |||
| 805 | p = BYTE_POS_ADDR (pt_byte_orig); | ||
| 806 | for (; p < GPT_ADDR; ++p) | ||
| 807 | if (*p == '\n') | ||
| 808 | *p = '\r'; | ||
| 809 | } | ||
| 810 | else if (process_coding.eol_type == CODING_EOL_CRLF) | ||
| 811 | { | ||
| 812 | /* CR LFs have been replaced with LFs. Undo | ||
| 813 | that by inserting CRs in front of LFs in | ||
| 814 | the text inserted above. */ | ||
| 815 | EMACS_INT bytepos, old_pt, old_pt_byte, nCR; | ||
| 816 | |||
| 817 | old_pt = PT; | ||
| 818 | old_pt_byte = PT_BYTE; | ||
| 819 | nCR = 0; | ||
| 820 | |||
| 821 | for (bytepos = PT_BYTE - 1; | ||
| 822 | bytepos >= pt_byte_orig; | ||
| 823 | --bytepos) | ||
| 824 | if (FETCH_BYTE (bytepos) == '\n') | ||
| 825 | { | ||
| 826 | EMACS_INT charpos = BYTE_TO_CHAR (bytepos); | ||
| 827 | TEMP_SET_PT_BOTH (charpos, bytepos); | ||
| 828 | insert_1_both ("\r", 1, 1, 0, 1, 0); | ||
| 829 | ++nCR; | ||
| 830 | } | ||
| 831 | |||
| 832 | TEMP_SET_PT_BOTH (old_pt + nCR, old_pt_byte + nCR); | ||
| 833 | } | ||
| 834 | |||
| 835 | /* Set the coding system symbol to that for | ||
| 836 | Unix-like EOL. */ | ||
| 837 | eol_type = Fget (saved_coding.symbol, Qeol_type); | ||
| 838 | if (VECTORP (eol_type) | ||
| 839 | && ASIZE (eol_type) == 3 | ||
| 840 | && SYMBOLP (AREF (eol_type, CODING_EOL_LF))) | ||
| 841 | coding = AREF (eol_type, CODING_EOL_LF); | ||
| 842 | else | ||
| 843 | coding = saved_coding.symbol; | ||
| 844 | |||
| 845 | process_coding.symbol = coding; | ||
| 846 | process_coding.eol_type = CODING_EOL_LF; | ||
| 847 | process_coding.mode | ||
| 848 | &= ~CODING_MODE_INHIBIT_INCONSISTENT_EOL; | ||
| 849 | } | ||
| 850 | |||
| 851 | nread -= process_coding.consumed; | ||
| 852 | carryover = nread; | ||
| 853 | if (carryover > 0) | 771 | if (carryover > 0) |
| 854 | /* As CARRYOVER should not be that large, we had | 772 | /* As CARRYOVER should not be that large, we had |
| 855 | better avoid overhead of bcopy. */ | 773 | better avoid overhead of bcopy. */ |
| 856 | BCOPY_SHORT (buf + process_coding.consumed, buf, | 774 | BCOPY_SHORT (process_coding.carryover, buf, |
| 857 | carryover); | 775 | process_coding.carryover_bytes); |
| 858 | if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP) | ||
| 859 | { | ||
| 860 | /* The decoding ended because of insufficient data | ||
| 861 | area to record information about composition. | ||
| 862 | We must try decoding with additional data area | ||
| 863 | before reading more output for the process. */ | ||
| 864 | coding_allocate_composition_data (&process_coding, PT); | ||
| 865 | goto repeat_decoding; | ||
| 866 | } | ||
| 867 | } | 776 | } |
| 868 | } | 777 | } |
| 869 | 778 | ||
| @@ -894,33 +803,12 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 894 | } | 803 | } |
| 895 | give_up: ; | 804 | give_up: ; |
| 896 | 805 | ||
| 897 | if (!NILP (buffer) | 806 | Vlast_coding_system_used = CODING_ID_NAME (process_coding.id); |
| 898 | && process_coding.cmp_data) | 807 | /* If the caller required, let the buffer inherit the |
| 899 | { | 808 | coding-system used to decode the process output. */ |
| 900 | coding_restore_composition (&process_coding, Fcurrent_buffer ()); | 809 | if (inherit_process_coding_system) |
| 901 | coding_free_composition_data (&process_coding); | 810 | call1 (intern ("after-insert-file-set-buffer-file-coding-system"), |
| 902 | } | 811 | make_number (total_read)); |
| 903 | |||
| 904 | { | ||
| 905 | int post_read_count = SPECPDL_INDEX (); | ||
| 906 | |||
| 907 | record_unwind_protect (save_excursion_restore, save_excursion_save ()); | ||
| 908 | inserted = PT - pt_orig; | ||
| 909 | TEMP_SET_PT_BOTH (pt_orig, pt_byte_orig); | ||
| 910 | if (SYMBOLP (process_coding.post_read_conversion) | ||
| 911 | && !NILP (Ffboundp (process_coding.post_read_conversion))) | ||
| 912 | call1 (process_coding.post_read_conversion, make_number (inserted)); | ||
| 913 | |||
| 914 | Vlast_coding_system_used = process_coding.symbol; | ||
| 915 | |||
| 916 | /* If the caller required, let the buffer inherit the | ||
| 917 | coding-system used to decode the process output. */ | ||
| 918 | if (inherit_process_coding_system) | ||
| 919 | call1 (intern ("after-insert-file-set-buffer-file-coding-system"), | ||
| 920 | make_number (total_read)); | ||
| 921 | |||
| 922 | unbind_to (post_read_count, Qnil); | ||
| 923 | } | ||
| 924 | } | 812 | } |
| 925 | 813 | ||
| 926 | /* Wait for it to terminate, unless it already has. */ | 814 | /* Wait for it to terminate, unless it already has. */ |