slang-users mailing list

[2014 Date Index] [2014 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Does SLang_input_pending() block on receiving the abort character?


Hi Nate,

> I'm looking through the docs and played with the listing in section 6.5
> of the S-Lang C Programmer's Guide.  The listing is written so that it
> would appear that SLang_input_pending() passes the abort character to
> SLang_getkey() so that the test of SL_UserBreak_Error would result in
> the Ctl-G message being printed.  However, I am seeing the timeout
> message instead as from this run:

The example is flawed.  I will go through the relevant lines step by
step and explain what is happening:

   int abort_char = 7;  /* For MSDOS, use 34 as scan code */
   unsigned int ch;

   if (-1 == SLang_init_tty (abort_char, 0, 1))

/* Here, the terminal will get initialized such that Ctrl-G (ascii 7) will cause
 * a SIGINT to be sent to the process.
 */

   SLang_set_abort_signal (NULL);

/* The above call will cause slang to install a default SIGINT
 * handler.  The default is to set the global variable SLKeyBoard_Quit
 * to 1, and if SLang_Ignore_User_Abort is 0, it will also call
 * SLang_set_error(SL_USER_BREAK).
 */

   while (1)
     {
	fputs ("\nPress any key.  To quit, press Ctrl-G: ", stdout);
	fflush (stdout);

	if (SLang_input_pending (50) == 0)  /* 50/10 seconds */
	  {
	     fputs ("Waited too long! Bye\n", stdout);
	     break;
	  }

/* On Unix, SLang_input_pending is a wrapper around the select
 * system call using the specified time-out.  If while waiting for
 * input, Ctrl-G is pressed, the process will be sent a SIGINT, which
 * will interrupt the select system call and trigger the signal handler.
 * Rather than restart the select system call, SLang_input_pending
 * will return prematurely but with a value of 0 since there is no
 * input to be read.  This will cause the "Waited too long!" message
 * to appear.
 *
 * So the example has a bug and that part should probably rewritten as follows:
 */

	if ((SLang_input_pending (50) == 0)
	    && (SLKeyBoard_Quit == 0))
	  {
	     fputs ("Waited too long! Bye\n", stdout);
	     break;
	  }

/* I hope this explains things a bit. I will update the example in the
 * documentation.  --John
 */



[2014 date index] [2014 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]