aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c107
1 files changed, 56 insertions, 51 deletions
diff --git a/src/process.c b/src/process.c
index a6387630628..59bb8e3757d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1180,7 +1180,7 @@ Remaining arguments are strings to give program as arguments.")
1180 if (!NILP (Vcoding_system_for_read)) 1180 if (!NILP (Vcoding_system_for_read))
1181 val = Vcoding_system_for_read; 1181 val = Vcoding_system_for_read;
1182 else if (NILP (current_buffer->enable_multibyte_characters)) 1182 else if (NILP (current_buffer->enable_multibyte_characters))
1183 val = Qemacs_mule; 1183 val = Qraw_text;
1184 else 1184 else
1185 { 1185 {
1186 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); 1186 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
@@ -1225,7 +1225,9 @@ Remaining arguments are strings to give program as arguments.")
1225 } 1225 }
1226 1226
1227 XPROCESS (proc)->decoding_buf = make_uninit_string (0); 1227 XPROCESS (proc)->decoding_buf = make_uninit_string (0);
1228 XPROCESS (proc)->decoding_carryover = make_number (0);
1228 XPROCESS (proc)->encoding_buf = make_uninit_string (0); 1229 XPROCESS (proc)->encoding_buf = make_uninit_string (0);
1230 XPROCESS (proc)->encoding_carryover = make_number (0);
1229 1231
1230 create_process (proc, (char **) new_argv, current_dir); 1232 create_process (proc, (char **) new_argv, current_dir);
1231 1233
@@ -1411,23 +1413,22 @@ create_process (process, new_argv, current_dir)
1411 int i = 1; 1413 int i = 1;
1412 struct coding_system *coding = proc_encode_coding_system[outchannel]; 1414 struct coding_system *coding = proc_encode_coding_system[outchannel];
1413 1415
1414 coding->last_block = 1; 1416 coding->mode |= CODING_MODE_LAST_BLOCK;
1415 GCPRO1 (process); 1417 GCPRO1 (process);
1416 while (new_argv[i] != 0) 1418 while (new_argv[i] != 0)
1417 { 1419 {
1418 int len = strlen (new_argv[i]); 1420 int len = strlen (new_argv[i]);
1419 int size = encoding_buffer_size (coding, len); 1421 int size = encoding_buffer_size (coding, len);
1420 unsigned char *buf = (unsigned char *) alloca (size); 1422 unsigned char *buf = (unsigned char *) alloca (size);
1421 int produced, dmy;
1422 1423
1423 produced = encode_coding (coding, new_argv[i], buf, len, size, &dmy); 1424 encode_coding (coding, new_argv[i], buf, len, size);
1424 buf[produced] = 0; 1425 buf[coding->produced] = 0;
1425 /* We don't have to free new_argv[i] because it points to a 1426 /* We don't have to free new_argv[i] because it points to a
1426 Lisp string given as an argument to `start-process'. */ 1427 Lisp string given as an argument to `start-process'. */
1427 new_argv[i++] = buf; 1428 new_argv[i++] = buf;
1428 } 1429 }
1429 UNGCPRO; 1430 UNGCPRO;
1430 coding->last_block = 0; 1431 coding->mode &= ~CODING_MODE_LAST_BLOCK;
1431 } 1432 }
1432 1433
1433 /* Delay interrupts until we have a chance to store 1434 /* Delay interrupts until we have a chance to store
@@ -1959,7 +1960,7 @@ Fourth arg SERVICE is name of the service desired, or an integer\n\
1959 val = Vcoding_system_for_read; 1960 val = Vcoding_system_for_read;
1960 else if (NILP (current_buffer->enable_multibyte_characters)) 1961 else if (NILP (current_buffer->enable_multibyte_characters))
1961 /* We dare not decode end-of-line format by setting VAL to 1962 /* We dare not decode end-of-line format by setting VAL to
1962 Qemacs_mule, because the existing Emacs Lisp libraries 1963 Qraw_text, because the existing Emacs Lisp libraries
1963 assume that they receive bare code including a sequene of 1964 assume that they receive bare code including a sequene of
1964 CR LF. */ 1965 CR LF. */
1965 val = Qnil; 1966 val = Qnil;
@@ -2015,7 +2016,9 @@ Fourth arg SERVICE is name of the service desired, or an integer\n\
2015 proc_encode_coding_system[outch]); 2016 proc_encode_coding_system[outch]);
2016 2017
2017 XPROCESS (proc)->decoding_buf = make_uninit_string (0); 2018 XPROCESS (proc)->decoding_buf = make_uninit_string (0);
2019 XPROCESS (proc)->decoding_carryover = make_number (0);
2018 XPROCESS (proc)->encoding_buf = make_uninit_string (0); 2020 XPROCESS (proc)->encoding_buf = make_uninit_string (0);
2021 XPROCESS (proc)->encoding_carryover = make_number (0);
2019 2022
2020 UNGCPRO; 2023 UNGCPRO;
2021 return proc; 2024 return proc;
@@ -2724,7 +2727,7 @@ read_process_output (proc, channel)
2724 struct coding_system *coding = proc_decode_coding_system[channel]; 2727 struct coding_system *coding = proc_decode_coding_system[channel];
2725 int chars_in_decoding_buf = 0; /* If 1, `chars' points 2728 int chars_in_decoding_buf = 0; /* If 1, `chars' points
2726 XSTRING (p->decoding_buf)->data. */ 2729 XSTRING (p->decoding_buf)->data. */
2727 int multibyte; 2730 int carryover = XINT (p->decoding_carryover);
2728 2731
2729#ifdef VMS 2732#ifdef VMS
2730 VMS_PROC_STUFF *vs, *get_vms_process_pointer(); 2733 VMS_PROC_STUFF *vs, *get_vms_process_pointer();
@@ -2746,33 +2749,36 @@ read_process_output (proc, channel)
2746 start_vms_process_read (vs); /* Crank up the next read on the process */ 2749 start_vms_process_read (vs); /* Crank up the next read on the process */
2747 return 1; /* Nothing worth printing, say we got 1 */ 2750 return 1; /* Nothing worth printing, say we got 1 */
2748 } 2751 }
2749 if (coding->carryover_size) 2752 if (carryover > 0)
2750 { 2753 {
2751 /* The data carried over in the previous decoding should be 2754 /* The data carried over in the previous decoding (which are at
2752 prepended to the new data read to decode all together. */ 2755 the tail of decoding buffer) should be prepended to the new
2753 char *buf = (char *) xmalloc (nbytes + coding->carryover_size); 2756 data read to decode all together. */
2754 2757 char *buf = (char *) xmalloc (nbytes + carryover);
2755 bcopy (coding->carryover, buf, coding->carryover_size); 2758
2756 bcopy (chars, buf + coding->carryover_size, nbytes); 2759 bcopy (XSTRING (p->decoding_buf)->data
2760 + XSTRING (p->decoding_buf)->size_byte - carryover,
2761 buf, carryover);
2762 bcopy (chars, buf + carryover, nbytes);
2757 chars = buf; 2763 chars = buf;
2758 chars_allocated = 1; 2764 chars_allocated = 1;
2759 } 2765 }
2760#else /* not VMS */ 2766#else /* not VMS */
2761 2767
2762 if (coding->carryover_size) 2768 if (carryover)
2763 /* The data carried over in the previous decoding should be 2769 /* See the comment above. */
2764 prepended to the new data read to decode all together. */ 2770 bcopy (XSTRING (p->decoding_buf)->data
2765 bcopy (coding->carryover, buf, coding->carryover_size); 2771 + XSTRING (p->decoding_buf)->size_byte - carryover,
2772 buf, carryover);
2766 2773
2767 if (proc_buffered_char[channel] < 0) 2774 if (proc_buffered_char[channel] < 0)
2768 nbytes = read (channel, buf + coding->carryover_size, 2775 nbytes = read (channel, buf + carryover, (sizeof buf) - carryover);
2769 (sizeof buf) - coding->carryover_size);
2770 else 2776 else
2771 { 2777 {
2772 buf[coding->carryover_size] = proc_buffered_char[channel]; 2778 buf[carryover] = proc_buffered_char[channel];
2773 proc_buffered_char[channel] = -1; 2779 proc_buffered_char[channel] = -1;
2774 nbytes = read (channel, buf + coding->carryover_size + 1, 2780 nbytes = read (channel, buf + carryover + 1,
2775 (sizeof buf) - coding->carryover_size - 1); 2781 (sizeof buf) - carryover - 1);
2776 if (nbytes < 0) 2782 if (nbytes < 0)
2777 nbytes = 1; 2783 nbytes = 1;
2778 else 2784 else
@@ -2786,21 +2792,21 @@ read_process_output (proc, channel)
2786 if (nbytes <= 0) return nbytes; 2792 if (nbytes <= 0) return nbytes;
2787 2793
2788 /* Now set NBYTES how many bytes we must decode. */ 2794 /* Now set NBYTES how many bytes we must decode. */
2789 nbytes += coding->carryover_size; 2795 nbytes += carryover;
2796 nchars = nbytes;
2790 2797
2791 if (CODING_REQUIRE_DECODING (coding) 2798 if (CODING_MAY_REQUIRE_DECODING (coding))
2792 || CODING_REQUIRE_DETECTION (coding))
2793 { 2799 {
2794 int require = decoding_buffer_size (coding, nbytes); 2800 int require = decoding_buffer_size (coding, nbytes);
2795 int consumed, produced; 2801 int result;
2796 2802
2797 if (XSTRING (p->decoding_buf)->size_byte < require) 2803 if (XSTRING (p->decoding_buf)->size_byte < require)
2798 p->decoding_buf = make_uninit_string (require); 2804 p->decoding_buf = make_uninit_string (require);
2799 produced = decode_coding (coding, chars, XSTRING (p->decoding_buf)->data, 2805 result = decode_coding (coding, chars, XSTRING (p->decoding_buf)->data,
2800 nbytes, XSTRING (p->decoding_buf)->size_byte, 2806 nbytes, XSTRING (p->decoding_buf)->size_byte);
2801 &consumed); 2807 carryover = nbytes - coding->consumed;
2802 2808
2803 /* New coding-system might be found by `decode_coding'. */ 2809 /* A new coding system might be found by `decode_coding'. */
2804 if (!EQ (p->decode_coding_system, coding->symbol)) 2810 if (!EQ (p->decode_coding_system, coding->symbol))
2805 { 2811 {
2806 p->decode_coding_system = coding->symbol; 2812 p->decode_coding_system = coding->symbol;
@@ -2809,7 +2815,7 @@ read_process_output (proc, channel)
2809 proc_decode_coding_system[channel] here. It is done in 2815 proc_decode_coding_system[channel] here. It is done in
2810 detect_coding called via decode_coding above. */ 2816 detect_coding called via decode_coding above. */
2811 2817
2812 /* If coding-system for encoding is not yet decided, we set 2818 /* If a coding system for encoding is not yet decided, we set
2813 it as the same as coding-system for decoding. 2819 it as the same as coding-system for decoding.
2814 2820
2815 But, before doing that we must check if 2821 But, before doing that we must check if
@@ -2830,10 +2836,11 @@ read_process_output (proc, channel)
2830 if (chars_allocated) 2836 if (chars_allocated)
2831 free (chars); 2837 free (chars);
2832#endif 2838#endif
2833 if (produced == 0) 2839 if (coding->produced == 0)
2834 return 0; 2840 return 0;
2835 chars = (char *) XSTRING (p->decoding_buf)->data; 2841 chars = (char *) XSTRING (p->decoding_buf)->data;
2836 nbytes = produced; 2842 nbytes = coding->produced;
2843 nchars = coding->produced_char;
2837 chars_in_decoding_buf = 1; 2844 chars_in_decoding_buf = 1;
2838 } 2845 }
2839#ifdef VMS 2846#ifdef VMS
@@ -2848,22 +2855,14 @@ read_process_output (proc, channel)
2848 free (chars); 2855 free (chars);
2849 chars = XSTRING (p->decoding_buf)->data; 2856 chars = XSTRING (p->decoding_buf)->data;
2850 chars_in_decoding_buf = 1; 2857 chars_in_decoding_buf = 1;
2858 carryover = 0;
2851 } 2859 }
2852#endif 2860#endif
2853 2861
2862 XSETINT (p->decoding_carryover, carryover);
2854 Vlast_coding_system_used = coding->symbol; 2863 Vlast_coding_system_used = coding->symbol;
2855 2864
2856 multibyte = (coding->type != coding_type_emacs_mule
2857 && coding->type != coding_type_no_conversion
2858 && coding->type != coding_type_undecided
2859 && coding->type != coding_type_raw_text);
2860
2861 /* Read and dispose of the process output. */ 2865 /* Read and dispose of the process output. */
2862 if (multibyte)
2863 nchars = multibyte_chars_in_text (chars, nbytes);
2864 else
2865 nchars = nbytes;
2866
2867 outstream = p->filter; 2866 outstream = p->filter;
2868 if (!NILP (outstream)) 2867 if (!NILP (outstream))
2869 { 2868 {
@@ -3065,6 +3064,7 @@ send_process (proc, buf, len, object)
3065 volatile unsigned char *procname = XSTRING (XPROCESS (proc)->name)->data; 3064 volatile unsigned char *procname = XSTRING (XPROCESS (proc)->name)->data;
3066 struct coding_system *coding; 3065 struct coding_system *coding;
3067 struct gcpro gcpro1; 3066 struct gcpro gcpro1;
3067 int carryover = XINT (XPROCESS (proc)->encoding_carryover);
3068 3068
3069 GCPRO1 (object); 3069 GCPRO1 (object);
3070 3070
@@ -3098,9 +3098,9 @@ send_process (proc, buf, len, object)
3098 ? offset = buf - XSTRING (object)->data 3098 ? offset = buf - XSTRING (object)->data
3099 : -1)); 3099 : -1));
3100 3100
3101 if (coding->carryover_size > 0) 3101 if (carryover > 0)
3102 { 3102 {
3103 temp_buf = (unsigned char *) xmalloc (len + coding->carryover_size); 3103 temp_buf = (unsigned char *) xmalloc (len + carryover);
3104 3104
3105 if (offset >= 0) 3105 if (offset >= 0)
3106 { 3106 {
@@ -3111,8 +3111,12 @@ send_process (proc, buf, len, object)
3111 /* Now we don't have to care relocation. */ 3111 /* Now we don't have to care relocation. */
3112 offset = -1; 3112 offset = -1;
3113 } 3113 }
3114 bcopy (coding->carryover, temp_buf, coding->carryover_size); 3114 bcopy ((XSTRING (XPROCESS (proc)->encoding_buf)->data
3115 bcopy (buf, temp_buf + coding->carryover_size, len); 3115 + XSTRING (XPROCESS (proc)->encoding_buf)->size_byte
3116 - carryover),
3117 temp_buf,
3118 carryover);
3119 bcopy (buf, temp_buf + carryover, len);
3116 buf = temp_buf; 3120 buf = temp_buf;
3117 } 3121 }
3118 3122
@@ -3129,8 +3133,9 @@ send_process (proc, buf, len, object)
3129 } 3133 }
3130 } 3134 }
3131 object = XPROCESS (proc)->encoding_buf; 3135 object = XPROCESS (proc)->encoding_buf;
3132 len = encode_coding (coding, buf, XSTRING (object)->data, 3136 encode_coding (coding, buf, XSTRING (object)->data,
3133 len, XSTRING (object)->size_byte, &dummy); 3137 len, XSTRING (object)->size_byte);
3138 len = coding->produced;
3134 buf = XSTRING (object)->data; 3139 buf = XSTRING (object)->data;
3135 if (temp_buf) 3140 if (temp_buf)
3136 xfree (temp_buf); 3141 xfree (temp_buf);