aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorKim F. Storm2004-08-19 13:57:17 +0000
committerKim F. Storm2004-08-19 13:57:17 +0000
commitb89a415ab18b6ed14f70518d8bd336d1f3364c9c (patch)
tree0fd65515ba3c3b9110ab3a5c158b7b613e0c6dd2 /src/process.c
parent6ba0f14c1f1df33480fff61a7d0b9f7c49ac286c (diff)
downloademacs-b89a415ab18b6ed14f70518d8bd336d1f3364c9c.tar.gz
emacs-b89a415ab18b6ed14f70518d8bd336d1f3364c9c.zip
* process.c (wait_reading_process_input): Clean up.
Add wait_for_cell, wait_proc, and just_wait_proc args to avoid overloading `read_kbd' and `do_display' args. Change read_kbd arg to int. All callers changed.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c160
1 files changed, 66 insertions, 94 deletions
diff --git a/src/process.c b/src/process.c
index ae9741ac478..ae4d366a694 100644
--- a/src/process.c
+++ b/src/process.c
@@ -3777,13 +3777,12 @@ Return non-nil iff we received any output before the timeout expired. */)
3777 else 3777 else
3778 seconds = NILP (process) ? -1 : 0; 3778 seconds = NILP (process) ? -1 : 0;
3779 3779
3780 if (NILP (process))
3781 XSETFASTINT (process, 0);
3782
3783 return 3780 return
3784 (wait_reading_process_input (seconds, useconds, process, 3781 (wait_reading_process_input (seconds, useconds, 0, 0,
3782 Qnil,
3783 !NILP (process) ? XPROCESS (process) : NULL,
3785 NILP (just_this_one) ? 0 : 3784 NILP (just_this_one) ? 0 :
3786 !INTEGERP (just_this_one) ? -1 : -2) 3785 !INTEGERP (just_this_one) ? 1 : -1)
3787 ? Qt : Qnil); 3786 ? Qt : Qnil);
3788} 3787}
3789 3788
@@ -4010,28 +4009,32 @@ wait_reading_process_input_1 ()
4010 1 to return when input is available, or 4009 1 to return when input is available, or
4011 -1 meaning caller will actually read the input, so don't throw to 4010 -1 meaning caller will actually read the input, so don't throw to
4012 the quit handler, or 4011 the quit handler, or
4013 a cons cell, meaning wait until its car is non-nil 4012
4014 (and gobble terminal input into the buffer if any arrives), or 4013 DO_DISPLAY != 0 means redisplay should be done to show subprocess
4015 a process object, meaning wait until something arrives from that
4016 process. The return value is true iff we read some input from
4017 that process.
4018
4019 If READ_KBD is a process object, DO_DISPLAY < 0 means handle only
4020 output from that process (suspending output from other processes)
4021 and DO_DISPLAY == -2 specifically means don't run any timers either.
4022 Otherwise, != 0 means redisplay should be done to show subprocess
4023 output that arrives. 4014 output that arrives.
4024 4015
4025 If READ_KBD is a pointer to a struct Lisp_Process, then the 4016 If WAIT_FOR_CELL is a cons cell, wait until its car is non-nil
4026 function returns true iff we received input from that process 4017 (and gobble terminal input into the buffer if any arrives).
4027 before the timeout elapsed. 4018
4019 If WAIT_PROC is specified, wait until something arrives from that
4020 process. The return value is true iff we read some input from
4021 that process.
4022
4023 If JUST_WAIT_PROC is non-nil, handle only output from WAIT_PROC
4024 (suspending output from other processes). A negative value
4025 means don't run any timers either.
4026
4027 If WAIT_PROC is specified, then the function returns true iff we
4028 received input from that process before the timeout elapsed.
4028 Otherwise, return true iff we received input from any process. */ 4029 Otherwise, return true iff we received input from any process. */
4029 4030
4030int 4031int
4031wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) 4032wait_reading_process_input (time_limit, microsecs, read_kbd, do_display,
4032 int time_limit, microsecs; 4033 wait_for_cell, wait_proc, just_wait_proc)
4033 Lisp_Object read_kbd; 4034 int time_limit, microsecs, read_kbd, do_display;
4034 int do_display; 4035 Lisp_Object wait_for_cell;
4036 struct Lisp_Process *wait_proc;
4037 int just_wait_proc;
4035{ 4038{
4036 register int channel, nfds; 4039 register int channel, nfds;
4037 SELECT_TYPE Available; 4040 SELECT_TYPE Available;
@@ -4041,39 +4044,19 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4041 Lisp_Object proc; 4044 Lisp_Object proc;
4042 EMACS_TIME timeout, end_time; 4045 EMACS_TIME timeout, end_time;
4043 int wait_channel = -1; 4046 int wait_channel = -1;
4044 struct Lisp_Process *wait_proc = 0;
4045 int just_wait_proc = 0;
4046 int got_some_input = 0; 4047 int got_some_input = 0;
4047 /* Either nil or a cons cell, the car of which is of interest and 4048 /* Either nil or a cons cell, the car of which is of interest and
4048 may be changed outside of this routine. */ 4049 may be changed outside of this routine. */
4049 Lisp_Object wait_for_cell = Qnil;
4050 int saved_waiting_for_user_input_p = waiting_for_user_input_p; 4050 int saved_waiting_for_user_input_p = waiting_for_user_input_p;
4051 4051
4052 FD_ZERO (&Available); 4052 FD_ZERO (&Available);
4053 FD_ZERO (&Connecting); 4053 FD_ZERO (&Connecting);
4054 4054
4055 /* If read_kbd is a process to watch, set wait_proc and wait_channel 4055 /* If wait_proc is a process to watch, set wait_channel accordingly. */
4056 accordingly. */ 4056 if (wait_proc != NULL)
4057 if (PROCESSP (read_kbd)) 4057 wait_channel = XINT (wait_proc->infd);
4058 {
4059 wait_proc = XPROCESS (read_kbd);
4060 wait_channel = XINT (wait_proc->infd);
4061 XSETFASTINT (read_kbd, 0);
4062 if (do_display < 0)
4063 {
4064 just_wait_proc = do_display;
4065 do_display = 0;
4066 }
4067 }
4068 4058
4069 /* If waiting for non-nil in a cell, record where. */ 4059 waiting_for_user_input_p = read_kbd;
4070 if (CONSP (read_kbd))
4071 {
4072 wait_for_cell = read_kbd;
4073 XSETFASTINT (read_kbd, 0);
4074 }
4075
4076 waiting_for_user_input_p = XINT (read_kbd);
4077 4060
4078 /* Since we may need to wait several times, 4061 /* Since we may need to wait several times,
4079 compute the absolute time to return at. */ 4062 compute the absolute time to return at. */
@@ -4101,7 +4084,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4101 /* If calling from keyboard input, do not quit 4084 /* If calling from keyboard input, do not quit
4102 since we want to return C-g as an input character. 4085 since we want to return C-g as an input character.
4103 Otherwise, do pending quit if requested. */ 4086 Otherwise, do pending quit if requested. */
4104 if (XINT (read_kbd) >= 0) 4087 if (read_kbd >= 0)
4105 QUIT; 4088 QUIT;
4106#ifdef SYNC_INPUT 4089#ifdef SYNC_INPUT
4107 else if (interrupt_input_pending) 4090 else if (interrupt_input_pending)
@@ -4139,7 +4122,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4139 the wait is supposed to be short, 4122 the wait is supposed to be short,
4140 and those callers cannot handle running arbitrary Lisp code here. */ 4123 and those callers cannot handle running arbitrary Lisp code here. */
4141 if (NILP (wait_for_cell) 4124 if (NILP (wait_for_cell)
4142 && just_wait_proc != -2) 4125 && just_wait_proc >= 0)
4143 { 4126 {
4144 EMACS_TIME timer_delay; 4127 EMACS_TIME timer_delay;
4145 4128
@@ -4167,7 +4150,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4167 while (!detect_input_pending ()); 4150 while (!detect_input_pending ());
4168 4151
4169 /* If there is unread keyboard input, also return. */ 4152 /* If there is unread keyboard input, also return. */
4170 if (XINT (read_kbd) != 0 4153 if (read_kbd != 0
4171 && requeued_events_pending_p ()) 4154 && requeued_events_pending_p ())
4172 break; 4155 break;
4173 4156
@@ -4195,7 +4178,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4195 It is important that we do this before checking for process 4178 It is important that we do this before checking for process
4196 activity. If we get a SIGCHLD after the explicit checks for 4179 activity. If we get a SIGCHLD after the explicit checks for
4197 process activity, timeout is the only way we will know. */ 4180 process activity, timeout is the only way we will know. */
4198 if (XINT (read_kbd) < 0) 4181 if (read_kbd < 0)
4199 set_waiting_for_input (&timeout); 4182 set_waiting_for_input (&timeout);
4200 4183
4201 /* If status of something has changed, and no input is 4184 /* If status of something has changed, and no input is
@@ -4275,8 +4258,10 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4275 4258
4276 /* Wait till there is something to do */ 4259 /* Wait till there is something to do */
4277 4260
4278 if (just_wait_proc) 4261 if (wait_proc && just_wait_proc)
4279 { 4262 {
4263 if (XINT (wait_proc->infd) < 0) /* Terminated */
4264 break;
4280 FD_SET (XINT (wait_proc->infd), &Available); 4265 FD_SET (XINT (wait_proc->infd), &Available);
4281 check_connect = check_delay = 0; 4266 check_connect = check_delay = 0;
4282 } 4267 }
@@ -4287,7 +4272,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4287 } 4272 }
4288 else 4273 else
4289 { 4274 {
4290 if (! XINT (read_kbd)) 4275 if (! read_kbd)
4291 Available = non_keyboard_wait_mask; 4276 Available = non_keyboard_wait_mask;
4292 else 4277 else
4293 Available = input_wait_mask; 4278 Available = input_wait_mask;
@@ -4304,12 +4289,12 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4304 { 4289 {
4305 clear_waiting_for_input (); 4290 clear_waiting_for_input ();
4306 redisplay_preserve_echo_area (11); 4291 redisplay_preserve_echo_area (11);
4307 if (XINT (read_kbd) < 0) 4292 if (read_kbd < 0)
4308 set_waiting_for_input (&timeout); 4293 set_waiting_for_input (&timeout);
4309 } 4294 }
4310 4295
4311 no_avail = 0; 4296 no_avail = 0;
4312 if (XINT (read_kbd) && detect_input_pending ()) 4297 if (read_kbd && detect_input_pending ())
4313 { 4298 {
4314 nfds = 0; 4299 nfds = 0;
4315 no_avail = 1; 4300 no_avail = 1;
@@ -4429,7 +4414,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4429 And on hpux, since we turn off polling in wait_reading_process_input, 4414 And on hpux, since we turn off polling in wait_reading_process_input,
4430 it might never get read at all if we don't spend much time 4415 it might never get read at all if we don't spend much time
4431 outside of wait_reading_process_input. */ 4416 outside of wait_reading_process_input. */
4432 if (XINT (read_kbd) && interrupt_input 4417 if (read_kbd && interrupt_input
4433 && keyboard_bit_set (&Available) 4418 && keyboard_bit_set (&Available)
4434 && input_polling_used ()) 4419 && input_polling_used ())
4435 kill (getpid (), SIGALRM); 4420 kill (getpid (), SIGALRM);
@@ -4439,7 +4424,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4439 /* If there is any, return immediately 4424 /* If there is any, return immediately
4440 to give it higher priority than subprocesses */ 4425 to give it higher priority than subprocesses */
4441 4426
4442 if (XINT (read_kbd) != 0) 4427 if (read_kbd != 0)
4443 { 4428 {
4444 int old_timers_run = timers_run; 4429 int old_timers_run = timers_run;
4445 struct buffer *old_buffer = current_buffer; 4430 struct buffer *old_buffer = current_buffer;
@@ -4464,7 +4449,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4464 } 4449 }
4465 4450
4466 /* If there is unread keyboard input, also return. */ 4451 /* If there is unread keyboard input, also return. */
4467 if (XINT (read_kbd) != 0 4452 if (read_kbd != 0
4468 && requeued_events_pending_p ()) 4453 && requeued_events_pending_p ())
4469 break; 4454 break;
4470 4455
@@ -4475,7 +4460,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4475 That would causes delays in pasting selections, for example. 4460 That would causes delays in pasting selections, for example.
4476 4461
4477 (We used to do this only if wait_for_cell.) */ 4462 (We used to do this only if wait_for_cell.) */
4478 if (XINT (read_kbd) == 0 && detect_input_pending ()) 4463 if (read_kbd == 0 && detect_input_pending ())
4479 { 4464 {
4480 swallow_events (do_display); 4465 swallow_events (do_display);
4481#if 0 /* Exiting when read_kbd doesn't request that seems wrong, though. */ 4466#if 0 /* Exiting when read_kbd doesn't request that seems wrong, though. */
@@ -4494,7 +4479,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4494 In that case, there really is no input and no SIGIO, 4479 In that case, there really is no input and no SIGIO,
4495 but select says there is input. */ 4480 but select says there is input. */
4496 4481
4497 if (XINT (read_kbd) && interrupt_input 4482 if (read_kbd && interrupt_input
4498 && keyboard_bit_set (&Available) && ! noninteractive) 4483 && keyboard_bit_set (&Available) && ! noninteractive)
4499 kill (getpid (), SIGIO); 4484 kill (getpid (), SIGIO);
4500#endif 4485#endif
@@ -4504,7 +4489,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4504 4489
4505 /* If checking input just got us a size-change event from X, 4490 /* If checking input just got us a size-change event from X,
4506 obey it now if we should. */ 4491 obey it now if we should. */
4507 if (XINT (read_kbd) || ! NILP (wait_for_cell)) 4492 if (read_kbd || ! NILP (wait_for_cell))
4508 do_pending_window_change (0); 4493 do_pending_window_change (0);
4509 4494
4510 /* Check for data from a process. */ 4495 /* Check for data from a process. */
@@ -4679,7 +4664,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
4679 /* If calling from keyboard input, do not quit 4664 /* If calling from keyboard input, do not quit
4680 since we want to return C-g as an input character. 4665 since we want to return C-g as an input character.
4681 Otherwise, do pending quit if requested. */ 4666 Otherwise, do pending quit if requested. */
4682 if (XINT (read_kbd) >= 0) 4667 if (read_kbd >= 0)
4683 { 4668 {
4684 /* Prevent input_pending from remaining set if we quit. */ 4669 /* Prevent input_pending from remaining set if we quit. */
4685 clear_input_pending (); 4670 clear_input_pending ();
@@ -5326,7 +5311,6 @@ send_process (proc, buf, len, object)
5326 that may allow the program 5311 that may allow the program
5327 to finish doing output and read more. */ 5312 to finish doing output and read more. */
5328 { 5313 {
5329 Lisp_Object zero;
5330 int offset = 0; 5314 int offset = 0;
5331 5315
5332#ifdef BROKEN_PTY_READ_AFTER_EAGAIN 5316#ifdef BROKEN_PTY_READ_AFTER_EAGAIN
@@ -5361,11 +5345,10 @@ send_process (proc, buf, len, object)
5361 else if (STRINGP (object)) 5345 else if (STRINGP (object))
5362 offset = buf - SDATA (object); 5346 offset = buf - SDATA (object);
5363 5347
5364 XSETFASTINT (zero, 0);
5365#ifdef EMACS_HAS_USECS 5348#ifdef EMACS_HAS_USECS
5366 wait_reading_process_input (0, 20000, zero, 0); 5349 wait_reading_process_input (0, 20000, 0, 0, Qnil, NULL, 0);
5367#else 5350#else
5368 wait_reading_process_input (1, 0, zero, 0); 5351 wait_reading_process_input (1, 0, 0, 0, Qnil, NULL, 0);
5369#endif 5352#endif
5370 5353
5371 if (BUFFERP (object)) 5354 if (BUFFERP (object))
@@ -6887,10 +6870,9 @@ Lisp_Object QCtype;
6887 1 to return when input is available, or 6870 1 to return when input is available, or
6888 -1 means caller will actually read the input, so don't throw to 6871 -1 means caller will actually read the input, so don't throw to
6889 the quit handler. 6872 the quit handler.
6890 a cons cell, meaning wait until its car is non-nil 6873
6891 (and gobble terminal input into the buffer if any arrives), or 6874 see full version for other parameters. We know that wait_proc will
6892 We know that read_kbd will never be a Lisp_Process, since 6875 always be NULL, since `subprocesses' isn't defined.
6893 `subprocesses' isn't defined.
6894 6876
6895 do_display != 0 means redisplay should be done to show subprocess 6877 do_display != 0 means redisplay should be done to show subprocess
6896 output that arrives. 6878 output that arrives.
@@ -6898,27 +6880,17 @@ Lisp_Object QCtype;
6898 Return true iff we received input from any process. */ 6880 Return true iff we received input from any process. */
6899 6881
6900int 6882int
6901wait_reading_process_input (time_limit, microsecs, read_kbd, do_display) 6883wait_reading_process_input (time_limit, microsecs, read_kbd, do_display,
6902 int time_limit, microsecs; 6884 wait_for_cell, wait_proc, just_wait_proc)
6903 Lisp_Object read_kbd; 6885 int time_limit, microsecs, read_kbd, do_display;
6904 int do_display; 6886 Lisp_Object wait_for_cell;
6887 struct Lisp_Process *wait_proc;
6888 int just_wait_proc;
6905{ 6889{
6906 register int nfds; 6890 register int nfds;
6907 EMACS_TIME end_time, timeout; 6891 EMACS_TIME end_time, timeout;
6908 SELECT_TYPE waitchannels; 6892 SELECT_TYPE waitchannels;
6909 int xerrno; 6893 int xerrno;
6910 /* Either nil or a cons cell, the car of which is of interest and
6911 may be changed outside of this routine. */
6912 Lisp_Object wait_for_cell;
6913
6914 wait_for_cell = Qnil;
6915
6916 /* If waiting for non-nil in a cell, record where. */
6917 if (CONSP (read_kbd))
6918 {
6919 wait_for_cell = read_kbd;
6920 XSETFASTINT (read_kbd, 0);
6921 }
6922 6894
6923 /* What does time_limit really mean? */ 6895 /* What does time_limit really mean? */
6924 if (time_limit || microsecs) 6896 if (time_limit || microsecs)
@@ -6941,7 +6913,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
6941 /* If calling from keyboard input, do not quit 6913 /* If calling from keyboard input, do not quit
6942 since we want to return C-g as an input character. 6914 since we want to return C-g as an input character.
6943 Otherwise, do pending quit if requested. */ 6915 Otherwise, do pending quit if requested. */
6944 if (XINT (read_kbd) >= 0) 6916 if (read_kbd >= 0)
6945 QUIT; 6917 QUIT;
6946 6918
6947 /* Exit now if the cell we're waiting for became non-nil. */ 6919 /* Exit now if the cell we're waiting for became non-nil. */
@@ -6992,7 +6964,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
6992 while (!detect_input_pending ()); 6964 while (!detect_input_pending ());
6993 6965
6994 /* If there is unread keyboard input, also return. */ 6966 /* If there is unread keyboard input, also return. */
6995 if (XINT (read_kbd) != 0 6967 if (read_kbd != 0
6996 && requeued_events_pending_p ()) 6968 && requeued_events_pending_p ())
6997 break; 6969 break;
6998 6970
@@ -7010,12 +6982,12 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
7010 6982
7011 /* Cause C-g and alarm signals to take immediate action, 6983 /* Cause C-g and alarm signals to take immediate action,
7012 and cause input available signals to zero out timeout. */ 6984 and cause input available signals to zero out timeout. */
7013 if (XINT (read_kbd) < 0) 6985 if (read_kbd < 0)
7014 set_waiting_for_input (&timeout); 6986 set_waiting_for_input (&timeout);
7015 6987
7016 /* Wait till there is something to do. */ 6988 /* Wait till there is something to do. */
7017 6989
7018 if (! XINT (read_kbd) && NILP (wait_for_cell)) 6990 if (! read_kbd && NILP (wait_for_cell))
7019 FD_ZERO (&waitchannels); 6991 FD_ZERO (&waitchannels);
7020 else 6992 else
7021 FD_SET (0, &waitchannels); 6993 FD_SET (0, &waitchannels);
@@ -7026,11 +6998,11 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
7026 { 6998 {
7027 clear_waiting_for_input (); 6999 clear_waiting_for_input ();
7028 redisplay_preserve_echo_area (15); 7000 redisplay_preserve_echo_area (15);
7029 if (XINT (read_kbd) < 0) 7001 if (read_kbd < 0)
7030 set_waiting_for_input (&timeout); 7002 set_waiting_for_input (&timeout);
7031 } 7003 }
7032 7004
7033 if (XINT (read_kbd) && detect_input_pending ()) 7005 if (read_kbd && detect_input_pending ())
7034 { 7006 {
7035 nfds = 0; 7007 nfds = 0;
7036 FD_ZERO (&waitchannels); 7008 FD_ZERO (&waitchannels);
@@ -7066,13 +7038,13 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
7066 kill (getpid (), SIGIO); 7038 kill (getpid (), SIGIO);
7067#endif 7039#endif
7068#ifdef SIGIO 7040#ifdef SIGIO
7069 if (XINT (read_kbd) && interrupt_input && (waitchannels & 1)) 7041 if (read_kbd && interrupt_input && (waitchannels & 1))
7070 kill (getpid (), SIGIO); 7042 kill (getpid (), SIGIO);
7071#endif 7043#endif
7072 7044
7073 /* Check for keyboard input */ 7045 /* Check for keyboard input */
7074 7046
7075 if ((XINT (read_kbd) != 0) 7047 if (read_kbd
7076 && detect_input_pending_run_timers (do_display)) 7048 && detect_input_pending_run_timers (do_display))
7077 { 7049 {
7078 swallow_events (do_display); 7050 swallow_events (do_display);
@@ -7081,7 +7053,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
7081 } 7053 }
7082 7054
7083 /* If there is unread keyboard input, also return. */ 7055 /* If there is unread keyboard input, also return. */
7084 if (XINT (read_kbd) != 0 7056 if (read_kbd
7085 && requeued_events_pending_p ()) 7057 && requeued_events_pending_p ())
7086 break; 7058 break;
7087 7059