aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c180
1 files changed, 32 insertions, 148 deletions
diff --git a/src/callproc.c b/src/callproc.c
index d92176ccd91..20b3ee22add 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -75,7 +75,7 @@ extern int errno;
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"
@@ -408,12 +408,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
408 { 408 {
409 argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]); 409 argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
410 if (CODING_REQUIRE_ENCODING (&argument_coding)) 410 if (CODING_REQUIRE_ENCODING (&argument_coding))
411 { 411 /* We must encode this argument. */
412 /* We must encode this argument. */ 412 args[i] = encode_coding_string (&argument_coding, args[i], 1);
413 args[i] = encode_coding_string (args[i], &argument_coding, 1);
414 if (argument_coding.type == coding_type_ccl)
415 setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil);
416 }
417 new_argv[i - 3] = SDATA (args[i]); 413 new_argv[i - 3] = SDATA (args[i]);
418 } 414 }
419 UNGCPRO; 415 UNGCPRO;
@@ -721,19 +717,15 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
721 else 717 else
722 val = Qnil; 718 val = Qnil;
723 } 719 }
724 setup_coding_system (Fcheck_coding_system (val), &process_coding); 720 Fcheck_coding_system (val);
725 /* In unibyte mode, character code conversion should not take 721 /* In unibyte mode, character code conversion should not take
726 place but EOL conversion should. So, setup raw-text or one 722 place but EOL conversion should. So, setup raw-text or one
727 of the subsidiary according to the information just setup. */ 723 of the subsidiary according to the information just setup. */
728 if (NILP (current_buffer->enable_multibyte_characters) 724 if (NILP (current_buffer->enable_multibyte_characters)
729 && !NILP (val)) 725 && !NILP (val))
730 setup_raw_text_coding_system (&process_coding); 726 val = raw_text_coding_system (val);
727 setup_coding_system (val, &process_coding);
731 } 728 }
732 process_coding.src_multibyte = 0;
733 process_coding.dst_multibyte
734 = (BUFFERP (buffer)
735 ? ! NILP (XBUFFER (buffer)->enable_multibyte_characters)
736 : ! NILP (current_buffer->enable_multibyte_characters));
737 729
738 immediate_quit = 1; 730 immediate_quit = 1;
739 QUIT; 731 QUIT;
@@ -745,12 +737,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
745 int carryover = 0; 737 int carryover = 0;
746 int display_on_the_fly = !NILP (display) && INTERACTIVE; 738 int display_on_the_fly = !NILP (display) && INTERACTIVE;
747 struct coding_system saved_coding; 739 struct coding_system saved_coding;
748 int pt_orig = PT, pt_byte_orig = PT_BYTE;
749 int inserted;
750 740
751 saved_coding = process_coding; 741 saved_coding = process_coding;
752 if (process_coding.composing != COMPOSITION_DISABLED)
753 coding_allocate_composition_data (&process_coding, PT);
754 while (1) 742 while (1)
755 { 743 {
756 /* Repeatedly read until we've filled as much as possible 744 /* Repeatedly read until we've filled as much as possible
@@ -783,128 +771,45 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
783 771
784 if (!NILP (buffer)) 772 if (!NILP (buffer))
785 { 773 {
786 if (! CODING_MAY_REQUIRE_DECODING (&process_coding)) 774 if (NILP (current_buffer->enable_multibyte_characters)
775 && ! CODING_MAY_REQUIRE_DECODING (&process_coding))
787 insert_1_both (bufptr, nread, nread, 0, 1, 0); 776 insert_1_both (bufptr, nread, nread, 0, 1, 0);
788 else 777 else
789 { /* We have to decode the input. */ 778 { /* We have to decode the input. */
790 int size; 779 Lisp_Object buf;
791 char *decoding_buf;
792
793 repeat_decoding:
794 size = decoding_buffer_size (&process_coding, nread);
795 decoding_buf = (char *) xmalloc (size);
796
797 /* We can't use the macro CODING_REQUIRE_DETECTION
798 because it always returns nonzero if the coding
799 system requires EOL detection. Here, we have to
800 check only whether or not the coding system
801 requires text-encoding detection. */
802 if (process_coding.type == coding_type_undecided)
803 {
804 detect_coding (&process_coding, bufptr, nread);
805 if (process_coding.composing != COMPOSITION_DISABLED)
806 coding_allocate_composition_data (&process_coding, PT);
807 }
808 if (process_coding.cmp_data)
809 process_coding.cmp_data->char_offset = PT;
810
811 decode_coding (&process_coding, bufptr, decoding_buf,
812 nread, size);
813 780
781 XSETBUFFER (buf, current_buffer);
782 decode_coding_c_string (&process_coding, bufptr, nread,
783 buf);
814 if (display_on_the_fly 784 if (display_on_the_fly
815 && saved_coding.type == coding_type_undecided 785 && CODING_REQUIRE_DETECTION (&saved_coding)
816 && process_coding.type != coding_type_undecided) 786 && ! CODING_REQUIRE_DETECTION (&process_coding))
817 { 787 {
818 /* We have detected some coding system. But, 788 /* We have detected some coding system. But,
819 there's a possibility that the detection was 789 there's a possibility that the detection was
820 done by insufficient data. So, we give up 790 done by insufficient data. So, we give up
821 displaying on the fly. */ 791 displaying on the fly. */
822 xfree (decoding_buf); 792 if (process_coding.produced > 0)
793 del_range_2 (process_coding.dst_pos,
794 process_coding.dst_pos_byte,
795 process_coding.dst_pos
796 + process_coding.produced_char,
797 process_coding.dst_pos_byte
798 + process_coding.produced, 0);
823 display_on_the_fly = 0; 799 display_on_the_fly = 0;
824 process_coding = saved_coding; 800 process_coding = saved_coding;
825 carryover = nread; 801 carryover = nread;
826 continue; 802 continue;
827 } 803 }
828 804
829 if (process_coding.produced > 0) 805 TEMP_SET_PT_BOTH (PT + process_coding.produced_char,
830 insert_1_both (decoding_buf, process_coding.produced_char, 806 PT_BYTE + process_coding.produced);
831 process_coding.produced, 0, 1, 0); 807 carryover = process_coding.carryover_bytes;
832 xfree (decoding_buf);
833
834 if (process_coding.result == CODING_FINISH_INCONSISTENT_EOL)
835 {
836 Lisp_Object eol_type, coding;
837
838 if (process_coding.eol_type == CODING_EOL_CR)
839 {
840 /* CRs have been replaced with LFs. Undo
841 that in the text inserted above. */
842 unsigned char *p;
843
844 move_gap_both (PT, PT_BYTE);
845
846 p = BYTE_POS_ADDR (pt_byte_orig);
847 for (; p < GPT_ADDR; ++p)
848 if (*p == '\n')
849 *p = '\r';
850 }
851 else if (process_coding.eol_type == CODING_EOL_CRLF)
852 {
853 /* CR LFs have been replaced with LFs. Undo
854 that by inserting CRs in front of LFs in
855 the text inserted above. */
856 EMACS_INT bytepos, old_pt, old_pt_byte, nCR;
857
858 old_pt = PT;
859 old_pt_byte = PT_BYTE;
860 nCR = 0;
861
862 for (bytepos = PT_BYTE - 1;
863 bytepos >= pt_byte_orig;
864 --bytepos)
865 if (FETCH_BYTE (bytepos) == '\n')
866 {
867 EMACS_INT charpos = BYTE_TO_CHAR (bytepos);
868 TEMP_SET_PT_BOTH (charpos, bytepos);
869 insert_1_both ("\r", 1, 1, 0, 1, 0);
870 ++nCR;
871 }
872
873 TEMP_SET_PT_BOTH (old_pt + nCR, old_pt_byte + nCR);
874 }
875
876 /* Set the coding system symbol to that for
877 Unix-like EOL. */
878 eol_type = Fget (saved_coding.symbol, Qeol_type);
879 if (VECTORP (eol_type)
880 && ASIZE (eol_type) == 3
881 && SYMBOLP (AREF (eol_type, CODING_EOL_LF)))
882 coding = AREF (eol_type, CODING_EOL_LF);
883 else
884 coding = saved_coding.symbol;
885
886 process_coding.symbol = coding;
887 process_coding.eol_type = CODING_EOL_LF;
888 process_coding.mode
889 &= ~CODING_MODE_INHIBIT_INCONSISTENT_EOL;
890 }
891
892 nread -= process_coding.consumed;
893 carryover = nread;
894 if (carryover > 0) 808 if (carryover > 0)
895 /* As CARRYOVER should not be that large, we had 809 /* As CARRYOVER should not be that large, we had
896 better avoid overhead of bcopy. */ 810 better avoid overhead of bcopy. */
897 BCOPY_SHORT (bufptr + process_coding.consumed, bufptr, 811 BCOPY_SHORT (process_coding.carryover, bufptr,
898 carryover); 812 process_coding.carryover_bytes);
899 if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP)
900 {
901 /* The decoding ended because of insufficient data
902 area to record information about composition.
903 We must try decoding with additional data area
904 before reading more output for the process. */
905 coding_allocate_composition_data (&process_coding, PT);
906 goto repeat_decoding;
907 }
908 } 813 }
909 } 814 }
910 815
@@ -935,33 +840,12 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
935 } 840 }
936 give_up: ; 841 give_up: ;
937 842
938 if (!NILP (buffer) 843 Vlast_coding_system_used = CODING_ID_NAME (process_coding.id);
939 && process_coding.cmp_data) 844 /* If the caller required, let the buffer inherit the
940 { 845 coding-system used to decode the process output. */
941 coding_restore_composition (&process_coding, Fcurrent_buffer ()); 846 if (inherit_process_coding_system)
942 coding_free_composition_data (&process_coding); 847 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
943 } 848 make_number (total_read));
944
945 {
946 int post_read_count = SPECPDL_INDEX ();
947
948 record_unwind_protect (save_excursion_restore, save_excursion_save ());
949 inserted = PT - pt_orig;
950 TEMP_SET_PT_BOTH (pt_orig, pt_byte_orig);
951 if (SYMBOLP (process_coding.post_read_conversion)
952 && !NILP (Ffboundp (process_coding.post_read_conversion)))
953 call1 (process_coding.post_read_conversion, make_number (inserted));
954
955 Vlast_coding_system_used = process_coding.symbol;
956
957 /* If the caller required, let the buffer inherit the
958 coding-system used to decode the process output. */
959 if (inherit_process_coding_system)
960 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
961 make_number (total_read));
962
963 unbind_to (post_read_count, Qnil);
964 }
965 } 849 }
966 850
967 /* Wait for it to terminate, unless it already has. */ 851 /* Wait for it to terminate, unless it already has. */