Mercurial > emacs
comparison src/process.c @ 20594:6e5a5afbe628
(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.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 05 Jan 1998 17:33:41 +0000 |
| parents | 5f17380c85f1 |
| children | ed9ed828415e |
comparison
equal
deleted
inserted
replaced
| 20593:d1699afbc43e | 20594:6e5a5afbe628 |
|---|---|
| 1087 CHECK_STRING (program, 2); | 1087 CHECK_STRING (program, 2); |
| 1088 | 1088 |
| 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); |
| 1101 for (i = 3; i < nargs; i++) | 1101 for (i = 3; i < nargs; i++) |
| 1102 { | 1102 { |
| 2708 | 2708 |
| 2709 read_process_output (proc, channel) | 2709 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. */ |
| 2717 #else | 2717 #else |
| 2718 char buf[1024]; | 2718 char buf[1024]; |
| 2722 register struct Lisp_Process *p = XPROCESS (proc); | 2722 register struct Lisp_Process *p = XPROCESS (proc); |
| 2723 register int opoint; | 2723 register int opoint; |
| 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(); |
| 2730 | 2731 |
| 2731 vs = get_vms_process_pointer (p->pid); | 2732 vs = get_vms_process_pointer (p->pid); |
| 2737 return -1; /* I/O error */ | 2738 return -1; /* I/O error */ |
| 2738 } | 2739 } |
| 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 */ |
| 2747 } | 2748 } |
| 2748 if (coding->carryover_size) | 2749 if (coding->carryover_size) |
| 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 } |
| 2759 #else /* not VMS */ | 2760 #else /* not VMS */ |
| 2760 | 2761 |
| 2762 /* The data carried over in the previous decoding should be | 2763 /* The data carried over in the previous decoding should be |
| 2763 prepended to the new data read to decode all together. */ | 2764 prepended to the new data read to decode all together. */ |
| 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'. */ |
| 2803 if (!EQ (p->decode_coding_system, coding->symbol)) | 2804 if (!EQ (p->decode_coding_system, coding->symbol)) |
| 2804 { | 2805 { |
| 2821 p->encode_coding_system = coding->symbol; | 2822 p->encode_coding_system = coding->symbol; |
| 2822 setup_coding_system (coding->symbol, | 2823 setup_coding_system (coding->symbol, |
| 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) |
| 2829 free (chars); | 2831 free (chars); |
| 2830 #endif | 2832 #endif |
| 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 |
| 2838 else if (chars_allocated) | 2840 else if (chars_allocated) |
| 2839 { | 2841 { |
| 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; |
| 2849 } | 2851 } |
| 2850 #endif | 2852 #endif |
| 2851 | 2853 |
| 2852 Vlast_coding_system_used = coding->symbol; | 2854 Vlast_coding_system_used = coding->symbol; |
| 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; | |
| 2853 | 2866 |
| 2854 outstream = p->filter; | 2867 outstream = p->filter; |
| 2855 if (!NILP (outstream)) | 2868 if (!NILP (outstream)) |
| 2856 { | 2869 { |
| 2857 /* We inhibit quit here instead of just catching it so that | 2870 /* We inhibit quit here instead of just catching it so that |
| 2858 hitting ^G when a filter happens to be running won't screw | 2871 hitting ^G when a filter happens to be running won't screw |
| 2859 it up. */ | 2872 it up. */ |
| 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 |
| 2866 is test them for EQness, and none of them should be a string. */ | 2880 is test them for EQness, and none of them should be a string. */ |
| 2867 odeactivate = Vdeactivate_mark; | 2881 odeactivate = Vdeactivate_mark; |
| 2886 | 2900 |
| 2887 /* For speed, if a search happens within this code, | 2901 /* For speed, if a search happens within this code, |
| 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 |
| 2901 /* If we saved the match data nonrecursively, restore it now. */ | 2912 /* If we saved the match data nonrecursively, restore it now. */ |
| 2902 restore_match_data (); | 2913 restore_match_data (); |
| 2965 Fwiden (); | 2976 Fwiden (); |
| 2966 | 2977 |
| 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++; |
| 2976 | 2988 |
| 2977 /* Make sure opoint and the old restrictions | 2989 /* Make sure opoint and the old restrictions |
| 3004 set_buffer_internal (old); | 3016 set_buffer_internal (old); |
| 3005 } | 3017 } |
| 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, |
| 3013 0, 0, 0, | 3025 0, 0, 0, |
| 3014 "Returns non-nil if emacs is waiting for input from the user.\n\ | 3026 "Returns non-nil if emacs is waiting for input from the user.\n\ |
| 3102 bcopy (coding->carryover, temp_buf, coding->carryover_size); | 3114 bcopy (coding->carryover, temp_buf, coding->carryover_size); |
| 3103 bcopy (buf, temp_buf + coding->carryover_size, len); | 3115 bcopy (buf, temp_buf + coding->carryover_size, len); |
| 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 |
| 3111 if (offset >= 0) | 3123 if (offset >= 0) |
| 3112 { | 3124 { |
| 3116 buf = offset + XSTRING (object)->data; | 3128 buf = offset + XSTRING (object)->data; |
| 3117 } | 3129 } |
| 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); |
| 3125 } | 3137 } |
| 3126 | 3138 |
| 3299 Lisp_Object process, string; | 3311 Lisp_Object process, string; |
| 3300 { | 3312 { |
| 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 |
| 3308 /* send a signal number SIGNO to PROCESS. | 3321 /* send a signal number SIGNO to PROCESS. |
| 3309 CURRENT_GROUP means send to the process group that currently owns | 3322 CURRENT_GROUP means send to the process group that currently owns |
