diff options
| author | Richard M. Stallman | 1998-01-05 17:33:41 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-01-05 17:33:41 +0000 |
| commit | 1d2fc6120d6a7f3f435506cdb69c76afe2b8a463 (patch) | |
| tree | fcf32db3d4a9627620e38390affbfbab625b03cb /src | |
| parent | 797ddf5794adb41ca6af668320608e7ed9d7bdc5 (diff) | |
| download | emacs-1d2fc6120d6a7f3f435506cdb69c76afe2b8a463.tar.gz emacs-1d2fc6120d6a7f3f435506cdb69c76afe2b8a463.zip | |
(read_process_output): Use insert_1_both.
(read_process_output): New var `multibyte'.
Set it according to which coding system was used.
(read_process_output): Handle bytes vs chars.
(send_process): Use size_byte of OBJECT.
(Fprocess_send_string): Pass size_byte to send_process.
Diffstat (limited to 'src')
| -rw-r--r-- | src/process.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/src/process.c b/src/process.c index d2779dd3517..17fc467e6d3 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -1089,12 +1089,12 @@ Remaining arguments are strings to give program as arguments.") | |||
| 1089 | #ifdef VMS | 1089 | #ifdef VMS |
| 1090 | /* Make a one member argv with all args concatenated | 1090 | /* Make a one member argv with all args concatenated |
| 1091 | together separated by a blank. */ | 1091 | together separated by a blank. */ |
| 1092 | len = XSTRING (program)->size + 2; | 1092 | len = XSTRING (program)->size_byte + 2; |
| 1093 | for (i = 3; i < nargs; i++) | 1093 | for (i = 3; i < nargs; i++) |
| 1094 | { | 1094 | { |
| 1095 | tem = args[i]; | 1095 | tem = args[i]; |
| 1096 | CHECK_STRING (tem, i); | 1096 | CHECK_STRING (tem, i); |
| 1097 | len += XSTRING (tem)->size + 1; /* count the blank */ | 1097 | len += XSTRING (tem)->size_byte + 1; /* count the blank */ |
| 1098 | } | 1098 | } |
| 1099 | new_argv = (unsigned char *) alloca (len); | 1099 | new_argv = (unsigned char *) alloca (len); |
| 1100 | strcpy (new_argv, XSTRING (program)->data); | 1100 | strcpy (new_argv, XSTRING (program)->data); |
| @@ -2710,7 +2710,7 @@ read_process_output (proc, channel) | |||
| 2710 | Lisp_Object proc; | 2710 | Lisp_Object proc; |
| 2711 | register int channel; | 2711 | register int channel; |
| 2712 | { | 2712 | { |
| 2713 | register int nchars; | 2713 | register int nchars, nbytes; |
| 2714 | char *chars; | 2714 | char *chars; |
| 2715 | #ifdef VMS | 2715 | #ifdef VMS |
| 2716 | int chars_allocated = 0; /* If 1, `chars' should be freed later. */ | 2716 | int chars_allocated = 0; /* If 1, `chars' should be freed later. */ |
| @@ -2724,6 +2724,7 @@ read_process_output (proc, channel) | |||
| 2724 | struct coding_system *coding = proc_decode_coding_system[channel]; | 2724 | struct coding_system *coding = proc_decode_coding_system[channel]; |
| 2725 | int chars_in_decoding_buf = 0; /* If 1, `chars' points | 2725 | int chars_in_decoding_buf = 0; /* If 1, `chars' points |
| 2726 | XSTRING (p->decoding_buf)->data. */ | 2726 | XSTRING (p->decoding_buf)->data. */ |
| 2727 | int multibyte; | ||
| 2727 | 2728 | ||
| 2728 | #ifdef VMS | 2729 | #ifdef VMS |
| 2729 | VMS_PROC_STUFF *vs, *get_vms_process_pointer(); | 2730 | VMS_PROC_STUFF *vs, *get_vms_process_pointer(); |
| @@ -2739,8 +2740,8 @@ read_process_output (proc, channel) | |||
| 2739 | else | 2740 | else |
| 2740 | error ("Could not get VMS process pointer"); | 2741 | error ("Could not get VMS process pointer"); |
| 2741 | chars = vs->inputBuffer; | 2742 | chars = vs->inputBuffer; |
| 2742 | nchars = clean_vms_buffer (chars, vs->iosb[1]); | 2743 | nbytes = clean_vms_buffer (chars, vs->iosb[1]); |
| 2743 | if (nchars <= 0) | 2744 | if (nbytes <= 0) |
| 2744 | { | 2745 | { |
| 2745 | start_vms_process_read (vs); /* Crank up the next read on the process */ | 2746 | start_vms_process_read (vs); /* Crank up the next read on the process */ |
| 2746 | return 1; /* Nothing worth printing, say we got 1 */ | 2747 | return 1; /* Nothing worth printing, say we got 1 */ |
| @@ -2749,10 +2750,10 @@ read_process_output (proc, channel) | |||
| 2749 | { | 2750 | { |
| 2750 | /* The data carried over in the previous decoding should be | 2751 | /* The data carried over in the previous decoding should be |
| 2751 | prepended to the new data read to decode all together. */ | 2752 | prepended to the new data read to decode all together. */ |
| 2752 | char *buf = (char *) xmalloc (nchars + coding->carryover_size); | 2753 | char *buf = (char *) xmalloc (nbytes + coding->carryover_size); |
| 2753 | 2754 | ||
| 2754 | bcopy (coding->carryover, buf, coding->carryover_size); | 2755 | bcopy (coding->carryover, buf, coding->carryover_size); |
| 2755 | bcopy (chars, buf + coding->carryover_size, nchars); | 2756 | bcopy (chars, buf + coding->carryover_size, nbytes); |
| 2756 | chars = buf; | 2757 | chars = buf; |
| 2757 | chars_allocated = 1; | 2758 | chars_allocated = 1; |
| 2758 | } | 2759 | } |
| @@ -2764,39 +2765,39 @@ read_process_output (proc, channel) | |||
| 2764 | bcopy (coding->carryover, buf, coding->carryover_size); | 2765 | bcopy (coding->carryover, buf, coding->carryover_size); |
| 2765 | 2766 | ||
| 2766 | if (proc_buffered_char[channel] < 0) | 2767 | if (proc_buffered_char[channel] < 0) |
| 2767 | nchars = read (channel, buf + coding->carryover_size, | 2768 | nbytes = read (channel, buf + coding->carryover_size, |
| 2768 | (sizeof buf) - coding->carryover_size); | 2769 | (sizeof buf) - coding->carryover_size); |
| 2769 | else | 2770 | else |
| 2770 | { | 2771 | { |
| 2771 | buf[coding->carryover_size] = proc_buffered_char[channel]; | 2772 | buf[coding->carryover_size] = proc_buffered_char[channel]; |
| 2772 | proc_buffered_char[channel] = -1; | 2773 | proc_buffered_char[channel] = -1; |
| 2773 | nchars = read (channel, buf + coding->carryover_size + 1, | 2774 | nbytes = read (channel, buf + coding->carryover_size + 1, |
| 2774 | (sizeof buf) - coding->carryover_size - 1); | 2775 | (sizeof buf) - coding->carryover_size - 1); |
| 2775 | if (nchars < 0) | 2776 | if (nbytes < 0) |
| 2776 | nchars = 1; | 2777 | nbytes = 1; |
| 2777 | else | 2778 | else |
| 2778 | nchars = nchars + 1; | 2779 | nbytes = nbytes + 1; |
| 2779 | } | 2780 | } |
| 2780 | chars = buf; | 2781 | chars = buf; |
| 2781 | #endif /* not VMS */ | 2782 | #endif /* not VMS */ |
| 2782 | 2783 | ||
| 2783 | /* At this point, NCHARS holds number of characters just received | 2784 | /* At this point, NBYTES holds number of characters just received |
| 2784 | (including the one in proc_buffered_char[channel]). */ | 2785 | (including the one in proc_buffered_char[channel]). */ |
| 2785 | if (nchars <= 0) return nchars; | 2786 | if (nbytes <= 0) return nbytes; |
| 2786 | 2787 | ||
| 2787 | /* Now set NCHARS how many bytes we must decode. */ | 2788 | /* Now set NBYTES how many bytes we must decode. */ |
| 2788 | nchars += coding->carryover_size; | 2789 | nbytes += coding->carryover_size; |
| 2789 | 2790 | ||
| 2790 | if (CODING_REQUIRE_DECODING (coding) | 2791 | if (CODING_REQUIRE_DECODING (coding) |
| 2791 | || CODING_REQUIRE_DETECTION (coding)) | 2792 | || CODING_REQUIRE_DETECTION (coding)) |
| 2792 | { | 2793 | { |
| 2793 | int require = decoding_buffer_size (coding, nchars); | 2794 | int require = decoding_buffer_size (coding, nbytes); |
| 2794 | int consumed, produced; | 2795 | int consumed, produced; |
| 2795 | 2796 | ||
| 2796 | if (XSTRING (p->decoding_buf)->size < require) | 2797 | if (XSTRING (p->decoding_buf)->size_byte < require) |
| 2797 | p->decoding_buf = make_uninit_string (require); | 2798 | p->decoding_buf = make_uninit_string (require); |
| 2798 | produced = decode_coding (coding, chars, XSTRING (p->decoding_buf)->data, | 2799 | produced = decode_coding (coding, chars, XSTRING (p->decoding_buf)->data, |
| 2799 | nchars, XSTRING (p->decoding_buf)->size, | 2800 | nbytes, XSTRING (p->decoding_buf)->size_byte, |
| 2800 | &consumed); | 2801 | &consumed); |
| 2801 | 2802 | ||
| 2802 | /* New coding-system might be found by `decode_coding'. */ | 2803 | /* New coding-system might be found by `decode_coding'. */ |
| @@ -2823,6 +2824,7 @@ read_process_output (proc, channel) | |||
| 2823 | proc_encode_coding_system[p->outfd]); | 2824 | proc_encode_coding_system[p->outfd]); |
| 2824 | } | 2825 | } |
| 2825 | } | 2826 | } |
| 2827 | |||
| 2826 | #ifdef VMS | 2828 | #ifdef VMS |
| 2827 | /* Now we don't need the contents of `chars'. */ | 2829 | /* Now we don't need the contents of `chars'. */ |
| 2828 | if (chars_allocated) | 2830 | if (chars_allocated) |
| @@ -2831,7 +2833,7 @@ read_process_output (proc, channel) | |||
| 2831 | if (produced == 0) | 2833 | if (produced == 0) |
| 2832 | return 0; | 2834 | return 0; |
| 2833 | chars = (char *) XSTRING (p->decoding_buf)->data; | 2835 | chars = (char *) XSTRING (p->decoding_buf)->data; |
| 2834 | nchars = produced; | 2836 | nbytes = produced; |
| 2835 | chars_in_decoding_buf = 1; | 2837 | chars_in_decoding_buf = 1; |
| 2836 | } | 2838 | } |
| 2837 | #ifdef VMS | 2839 | #ifdef VMS |
| @@ -2840,9 +2842,9 @@ read_process_output (proc, channel) | |||
| 2840 | /* Although we don't have to decode the received data, we must | 2842 | /* Although we don't have to decode the received data, we must |
| 2841 | move it to an area which we don't have to free. */ | 2843 | move it to an area which we don't have to free. */ |
| 2842 | if (! STRINGP (p->decoding_buf) | 2844 | if (! STRINGP (p->decoding_buf) |
| 2843 | || XSTRING (p->decoding_buf)->size < nchars) | 2845 | || XSTRING (p->decoding_buf)->size < nbytes) |
| 2844 | p->decoding_buf = make_uninit_string (nchars); | 2846 | p->decoding_buf = make_uninit_string (nbytes); |
| 2845 | bcopy (chars, XSTRING (p->decoding_buf)->data, nchars); | 2847 | bcopy (chars, XSTRING (p->decoding_buf)->data, nbytes); |
| 2846 | free (chars); | 2848 | free (chars); |
| 2847 | chars = XSTRING (p->decoding_buf)->data; | 2849 | chars = XSTRING (p->decoding_buf)->data; |
| 2848 | chars_in_decoding_buf = 1; | 2850 | chars_in_decoding_buf = 1; |
| @@ -2851,6 +2853,17 @@ read_process_output (proc, channel) | |||
| 2851 | 2853 | ||
| 2852 | Vlast_coding_system_used = coding->symbol; | 2854 | Vlast_coding_system_used = coding->symbol; |
| 2853 | 2855 | ||
| 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. */ | ||
| 2862 | if (multibyte) | ||
| 2863 | nchars = multibyte_chars_in_text (chars, nbytes); | ||
| 2864 | else | ||
| 2865 | nchars = nbytes; | ||
| 2866 | |||
| 2854 | outstream = p->filter; | 2867 | outstream = p->filter; |
| 2855 | if (!NILP (outstream)) | 2868 | if (!NILP (outstream)) |
| 2856 | { | 2869 | { |
| @@ -2860,6 +2873,7 @@ read_process_output (proc, channel) | |||
| 2860 | int count = specpdl_ptr - specpdl; | 2873 | int count = specpdl_ptr - specpdl; |
| 2861 | Lisp_Object odeactivate; | 2874 | Lisp_Object odeactivate; |
| 2862 | Lisp_Object obuffer, okeymap; | 2875 | Lisp_Object obuffer, okeymap; |
| 2876 | Lisp_Object text; | ||
| 2863 | int outer_running_asynch_code = running_asynch_code; | 2877 | int outer_running_asynch_code = running_asynch_code; |
| 2864 | 2878 | ||
| 2865 | /* No need to gcpro these, because all we do with them later | 2879 | /* No need to gcpro these, because all we do with them later |
| @@ -2888,13 +2902,10 @@ read_process_output (proc, channel) | |||
| 2888 | save the match data in a special nonrecursive fashion. */ | 2902 | save the match data in a special nonrecursive fashion. */ |
| 2889 | running_asynch_code = 1; | 2903 | running_asynch_code = 1; |
| 2890 | 2904 | ||
| 2891 | /* Read and dispose of the process output. */ | 2905 | text = make_multibyte_string (chars, nchars, nbytes); |
| 2892 | internal_condition_case_1 (read_process_output_call, | 2906 | internal_condition_case_1 (read_process_output_call, |
| 2893 | Fcons (outstream, | 2907 | Fcons (outstream, |
| 2894 | Fcons (proc, | 2908 | Fcons (proc, Fcons (text, Qnil))), |
| 2895 | Fcons (make_string (chars, | ||
| 2896 | nchars), | ||
| 2897 | Qnil))), | ||
| 2898 | !NILP (Vdebug_on_error) ? Qnil : Qerror, | 2909 | !NILP (Vdebug_on_error) ? Qnil : Qerror, |
| 2899 | read_process_output_error_handler); | 2910 | read_process_output_error_handler); |
| 2900 | 2911 | ||
| @@ -2967,9 +2978,10 @@ read_process_output (proc, channel) | |||
| 2967 | /* Insert before markers in case we are inserting where | 2978 | /* Insert before markers in case we are inserting where |
| 2968 | the buffer's mark is, and the user's next command is Meta-y. */ | 2979 | the buffer's mark is, and the user's next command is Meta-y. */ |
| 2969 | if (chars_in_decoding_buf) | 2980 | if (chars_in_decoding_buf) |
| 2970 | insert_from_string_before_markers (p->decoding_buf, 0, nchars, 0); | 2981 | insert_from_string_before_markers (p->decoding_buf, 0, 0, |
| 2982 | nchars, nbytes, 0); | ||
| 2971 | else | 2983 | else |
| 2972 | insert_before_markers (chars, nchars); | 2984 | insert_1_both (chars, nchars, nbytes, 0, 1, 1); |
| 2973 | set_marker_both (p->mark, p->buffer, PT, PT_BYTE); | 2985 | set_marker_both (p->mark, p->buffer, PT, PT_BYTE); |
| 2974 | 2986 | ||
| 2975 | update_mode_lines++; | 2987 | update_mode_lines++; |
| @@ -3006,7 +3018,7 @@ read_process_output (proc, channel) | |||
| 3006 | #ifdef VMS | 3018 | #ifdef VMS |
| 3007 | start_vms_process_read (vs); | 3019 | start_vms_process_read (vs); |
| 3008 | #endif | 3020 | #endif |
| 3009 | return nchars; | 3021 | return nbytes; |
| 3010 | } | 3022 | } |
| 3011 | 3023 | ||
| 3012 | DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p, | 3024 | DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p, |
| @@ -3104,7 +3116,7 @@ send_process (proc, buf, len, object) | |||
| 3104 | buf = temp_buf; | 3116 | buf = temp_buf; |
| 3105 | } | 3117 | } |
| 3106 | 3118 | ||
| 3107 | if (XSTRING (XPROCESS (proc)->encoding_buf)->size < require) | 3119 | if (XSTRING (XPROCESS (proc)->encoding_buf)->size_byte < require) |
| 3108 | { | 3120 | { |
| 3109 | XPROCESS (proc)->encoding_buf = make_uninit_string (require); | 3121 | XPROCESS (proc)->encoding_buf = make_uninit_string (require); |
| 3110 | 3122 | ||
| @@ -3118,7 +3130,7 @@ send_process (proc, buf, len, object) | |||
| 3118 | } | 3130 | } |
| 3119 | object = XPROCESS (proc)->encoding_buf; | 3131 | object = XPROCESS (proc)->encoding_buf; |
| 3120 | len = encode_coding (coding, buf, XSTRING (object)->data, | 3132 | len = encode_coding (coding, buf, XSTRING (object)->data, |
| 3121 | len, XSTRING (object)->size, &dummy); | 3133 | len, XSTRING (object)->size_byte, &dummy); |
| 3122 | buf = XSTRING (object)->data; | 3134 | buf = XSTRING (object)->data; |
| 3123 | if (temp_buf) | 3135 | if (temp_buf) |
| 3124 | xfree (temp_buf); | 3136 | xfree (temp_buf); |
| @@ -3301,7 +3313,8 @@ Output from processes can arrive in between bunches.") | |||
| 3301 | Lisp_Object proc; | 3313 | Lisp_Object proc; |
| 3302 | CHECK_STRING (string, 1); | 3314 | CHECK_STRING (string, 1); |
| 3303 | proc = get_process (process); | 3315 | proc = get_process (process); |
| 3304 | send_process (proc, XSTRING (string)->data, XSTRING (string)->size, string); | 3316 | send_process (proc, XSTRING (string)->data, |
| 3317 | XSTRING (string)->size_byte, string); | ||
| 3305 | return Qnil; | 3318 | return Qnil; |
| 3306 | } | 3319 | } |
| 3307 | 3320 | ||