Mercurial > emacs
comparison src/callproc.c @ 88356:5ace79aaf5ad
Include "character.h" instead of "charset.h".
(Fcall_process): Big change for the new code-conversion APIs.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 01 Mar 2002 01:11:12 +0000 |
parents | 56385cb63c61 |
children | 47b395dd6f2c |
comparison
equal
deleted
inserted
replaced
88355:7b6dd9fc65ad | 88356:5ace79aaf5ad |
---|---|
73 #endif | 73 #endif |
74 | 74 |
75 #include "lisp.h" | 75 #include "lisp.h" |
76 #include "commands.h" | 76 #include "commands.h" |
77 #include "buffer.h" | 77 #include "buffer.h" |
78 #include "charset.h" | 78 #include "character.h" |
79 #include "ccl.h" | 79 #include "ccl.h" |
80 #include "coding.h" | 80 #include "coding.h" |
81 #include "composite.h" | 81 #include "composite.h" |
82 #include <epaths.h> | 82 #include <epaths.h> |
83 #include "process.h" | 83 #include "process.h" |
399 argument_coding.dst_multibyte = 0; | 399 argument_coding.dst_multibyte = 0; |
400 for (i = 4; i < nargs; i++) | 400 for (i = 4; i < nargs; i++) |
401 { | 401 { |
402 argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]); | 402 argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]); |
403 if (CODING_REQUIRE_ENCODING (&argument_coding)) | 403 if (CODING_REQUIRE_ENCODING (&argument_coding)) |
404 { | 404 /* We must encode this argument. */ |
405 /* We must encode this argument. */ | 405 args[i] = encode_coding_string (&argument_coding, args[i], 1); |
406 args[i] = encode_coding_string (args[i], &argument_coding, 1); | |
407 if (argument_coding.type == coding_type_ccl) | |
408 setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil); | |
409 } | |
410 new_argv[i - 3] = XSTRING (args[i])->data; | 406 new_argv[i - 3] = XSTRING (args[i])->data; |
411 } | 407 } |
412 UNGCPRO; | 408 UNGCPRO; |
413 new_argv[nargs - 3] = 0; | 409 new_argv[nargs - 3] = 0; |
414 } | 410 } |
712 else if (CONSP (Vdefault_process_coding_system)) | 708 else if (CONSP (Vdefault_process_coding_system)) |
713 val = XCAR (Vdefault_process_coding_system); | 709 val = XCAR (Vdefault_process_coding_system); |
714 else | 710 else |
715 val = Qnil; | 711 val = Qnil; |
716 } | 712 } |
717 setup_coding_system (Fcheck_coding_system (val), &process_coding); | 713 Fcheck_coding_system (val); |
718 /* In unibyte mode, character code conversion should not take | 714 /* In unibyte mode, character code conversion should not take |
719 place but EOL conversion should. So, setup raw-text or one | 715 place but EOL conversion should. So, setup raw-text or one |
720 of the subsidiary according to the information just setup. */ | 716 of the subsidiary according to the information just setup. */ |
721 if (NILP (current_buffer->enable_multibyte_characters) | 717 if (NILP (current_buffer->enable_multibyte_characters) |
722 && !NILP (val)) | 718 && !NILP (val)) |
723 setup_raw_text_coding_system (&process_coding); | 719 val = raw_text_coding_system (val); |
724 } | 720 setup_coding_system (val, &process_coding); |
725 process_coding.src_multibyte = 0; | 721 } |
726 process_coding.dst_multibyte | |
727 = (BUFFERP (buffer) | |
728 ? ! NILP (XBUFFER (buffer)->enable_multibyte_characters) | |
729 : ! NILP (current_buffer->enable_multibyte_characters)); | |
730 | 722 |
731 immediate_quit = 1; | 723 immediate_quit = 1; |
732 QUIT; | 724 QUIT; |
733 | 725 |
734 { | 726 { |
740 struct coding_system saved_coding; | 732 struct coding_system saved_coding; |
741 int pt_orig = PT, pt_byte_orig = PT_BYTE; | 733 int pt_orig = PT, pt_byte_orig = PT_BYTE; |
742 int inserted; | 734 int inserted; |
743 | 735 |
744 saved_coding = process_coding; | 736 saved_coding = process_coding; |
745 if (process_coding.composing != COMPOSITION_DISABLED) | |
746 coding_allocate_composition_data (&process_coding, PT); | |
747 while (1) | 737 while (1) |
748 { | 738 { |
749 /* Repeatedly read until we've filled as much as possible | 739 /* Repeatedly read until we've filled as much as possible |
750 of the buffer size we have. But don't read | 740 of the buffer size we have. But don't read |
751 less than 1024--save that for the next bufferful. */ | 741 less than 1024--save that for the next bufferful. */ |
778 { | 768 { |
779 if (! CODING_MAY_REQUIRE_DECODING (&process_coding)) | 769 if (! CODING_MAY_REQUIRE_DECODING (&process_coding)) |
780 insert_1_both (bufptr, nread, nread, 0, 1, 0); | 770 insert_1_both (bufptr, nread, nread, 0, 1, 0); |
781 else | 771 else |
782 { /* We have to decode the input. */ | 772 { /* We have to decode the input. */ |
783 int size; | 773 decode_coding_c_string (&process_coding, bufptr, nread, |
784 char *decoding_buf; | 774 buffer); |
785 | |
786 repeat_decoding: | |
787 size = decoding_buffer_size (&process_coding, nread); | |
788 decoding_buf = (char *) xmalloc (size); | |
789 | |
790 if (process_coding.cmp_data) | |
791 process_coding.cmp_data->char_offset = PT; | |
792 | |
793 decode_coding (&process_coding, bufptr, decoding_buf, | |
794 nread, size); | |
795 | |
796 if (display_on_the_fly | 775 if (display_on_the_fly |
797 && saved_coding.type == coding_type_undecided | 776 && CODING_REQUIRE_DETECTION (&saved_coding) |
798 && process_coding.type != coding_type_undecided) | 777 && ! CODING_REQUIRE_DETECTION (&process_coding)) |
799 { | 778 { |
800 /* We have detected some coding system. But, | 779 /* We have detected some coding system. But, |
801 there's a possibility that the detection was | 780 there's a possibility that the detection was |
802 done by insufficient data. So, we give up | 781 done by insufficient data. So, we give up |
803 displaying on the fly. */ | 782 displaying on the fly. */ |
804 xfree (decoding_buf); | 783 if (process_coding.produced > 0) |
784 del_range_2 (process_coding.dst_pos, | |
785 process_coding.dst_pos_byte, | |
786 process_coding.dst_pos | |
787 + process_coding.produced_char, | |
788 process_coding.dst_pos_byte | |
789 + process_coding.produced, 0); | |
805 display_on_the_fly = 0; | 790 display_on_the_fly = 0; |
806 process_coding = saved_coding; | 791 process_coding = saved_coding; |
807 carryover = nread; | 792 carryover = nread; |
808 continue; | 793 continue; |
809 } | |
810 | |
811 if (process_coding.produced > 0) | |
812 insert_1_both (decoding_buf, process_coding.produced_char, | |
813 process_coding.produced, 0, 1, 0); | |
814 xfree (decoding_buf); | |
815 | |
816 if (process_coding.result == CODING_FINISH_INCONSISTENT_EOL) | |
817 { | |
818 Lisp_Object eol_type, coding; | |
819 | |
820 if (process_coding.eol_type == CODING_EOL_CR) | |
821 { | |
822 /* CRs have been replaced with LFs. Undo | |
823 that in the text inserted above. */ | |
824 unsigned char *p; | |
825 | |
826 move_gap_both (PT, PT_BYTE); | |
827 | |
828 p = BYTE_POS_ADDR (pt_byte_orig); | |
829 for (; p < GPT_ADDR; ++p) | |
830 if (*p == '\n') | |
831 *p = '\r'; | |
832 } | |
833 else if (process_coding.eol_type == CODING_EOL_CRLF) | |
834 { | |
835 /* CR LFs have been replaced with LFs. Undo | |
836 that by inserting CRs in front of LFs in | |
837 the text inserted above. */ | |
838 EMACS_INT bytepos, old_pt, old_pt_byte, nCR; | |
839 | |
840 old_pt = PT; | |
841 old_pt_byte = PT_BYTE; | |
842 nCR = 0; | |
843 | |
844 for (bytepos = PT_BYTE - 1; | |
845 bytepos >= pt_byte_orig; | |
846 --bytepos) | |
847 if (FETCH_BYTE (bytepos) == '\n') | |
848 { | |
849 EMACS_INT charpos = BYTE_TO_CHAR (bytepos); | |
850 TEMP_SET_PT_BOTH (charpos, bytepos); | |
851 insert_1_both ("\r", 1, 1, 0, 1, 0); | |
852 ++nCR; | |
853 } | |
854 | |
855 TEMP_SET_PT_BOTH (old_pt + nCR, old_pt_byte + nCR); | |
856 } | |
857 | |
858 /* Set the coding system symbol to that for | |
859 Unix-like EOL. */ | |
860 eol_type = Fget (saved_coding.symbol, Qeol_type); | |
861 if (VECTORP (eol_type) | |
862 && ASIZE (eol_type) == 3 | |
863 && SYMBOLP (AREF (eol_type, CODING_EOL_LF))) | |
864 coding = AREF (eol_type, CODING_EOL_LF); | |
865 else | |
866 coding = saved_coding.symbol; | |
867 | |
868 process_coding.symbol = coding; | |
869 process_coding.eol_type = CODING_EOL_LF; | |
870 process_coding.mode | |
871 &= ~CODING_MODE_INHIBIT_INCONSISTENT_EOL; | |
872 } | 794 } |
873 | 795 |
874 nread -= process_coding.consumed; | 796 nread -= process_coding.consumed; |
875 carryover = nread; | 797 carryover = nread; |
876 if (carryover > 0) | 798 if (carryover > 0) |
877 /* As CARRYOVER should not be that large, we had | 799 /* As CARRYOVER should not be that large, we had |
878 better avoid overhead of bcopy. */ | 800 better avoid overhead of bcopy. */ |
879 BCOPY_SHORT (bufptr + process_coding.consumed, bufptr, | 801 BCOPY_SHORT (bufptr + process_coding.consumed, bufptr, |
880 carryover); | 802 carryover); |
881 if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP) | |
882 { | |
883 /* The decoding ended because of insufficient data | |
884 area to record information about composition. | |
885 We must try decoding with additional data area | |
886 before reading more output for the process. */ | |
887 coding_allocate_composition_data (&process_coding, PT); | |
888 goto repeat_decoding; | |
889 } | |
890 } | 803 } |
891 } | 804 } |
892 | 805 |
893 if (process_coding.mode & CODING_MODE_LAST_BLOCK) | 806 if (process_coding.mode & CODING_MODE_LAST_BLOCK) |
894 break; | 807 break; |
915 immediate_quit = 1; | 828 immediate_quit = 1; |
916 QUIT; | 829 QUIT; |
917 } | 830 } |
918 give_up: ; | 831 give_up: ; |
919 | 832 |
920 if (!NILP (buffer) | 833 Vlast_coding_system_used = CODING_ID_NAME (process_coding.id); |
921 && process_coding.cmp_data) | 834 /* If the caller required, let the buffer inherit the |
922 { | 835 coding-system used to decode the process output. */ |
923 coding_restore_composition (&process_coding, Fcurrent_buffer ()); | 836 if (inherit_process_coding_system) |
924 coding_free_composition_data (&process_coding); | 837 call1 (intern ("after-insert-file-set-buffer-file-coding-system"), |
925 } | |
926 | |
927 { | |
928 int post_read_count = specpdl_ptr - specpdl; | |
929 | |
930 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
931 inserted = PT - pt_orig; | |
932 TEMP_SET_PT_BOTH (pt_orig, pt_byte_orig); | |
933 if (SYMBOLP (process_coding.post_read_conversion) | |
934 && !NILP (Ffboundp (process_coding.post_read_conversion))) | |
935 call1 (process_coding.post_read_conversion, make_number (inserted)); | |
936 | |
937 Vlast_coding_system_used = process_coding.symbol; | |
938 | |
939 /* If the caller required, let the buffer inherit the | |
940 coding-system used to decode the process output. */ | |
941 if (inherit_process_coding_system) | |
942 call1 (intern ("after-insert-file-set-buffer-file-coding-system"), | |
943 make_number (total_read)); | 838 make_number (total_read)); |
944 | |
945 unbind_to (post_read_count, Qnil); | |
946 } | |
947 } | 839 } |
948 | 840 |
949 /* Wait for it to terminate, unless it already has. */ | 841 /* Wait for it to terminate, unless it already has. */ |
950 wait_for_termination (pid); | 842 wait_for_termination (pid); |
951 | 843 |