[LCP]Interrupting readline

Matthew Vanecek linux4us at earthlink.net
Mon Jul 16 03:32:02 UTC 2001


On 15 Jul 2001 07:23:52 -0500, Robert Wuest wrote:
> Hi all,
> 
> I can't figure out how to get out of readline once it is called, except
> to press enter or one more key.  I want exit the loop if the user hits
> control-c, but readline insists on an enter.  I have the basic readline
> loop :
> 
> int done = 0;
> 
> int cli(void)
> {
> .
> .
> 	// install cli_int on SIGINT
> .
>     do {
>         rbuffer = readline("spgmr08: ");
>         if ( rbuffer) {
>             if ( rbuffer[0] ) {
>                 add_history( rbuffer );
>                 proc_line(rbuffer);      // process input
>             }
>             free (rbuffer);
>         } else {                        // EOF on empty line
>             done = 1;
>         }
>     } while ( !done );
> .
> .
> .
> }
> 
> And an interrupt handler, which is being called properly (I see
> "interrupt" on stdout)
> 
> void cli_int(int i)	// cli interrupt handler
> {
>     printf( "interrupt\n");
>     rl_done = 1;
>     done = 1;
> }
> 
> 
> Bash handles this no problem, and I've looked at the bash code, but
> can't seem to duplicate it.
> 
> If I set rl_done (as shown above) readline waits for one more key, any
> key.  That's not what I want.
> 
> Calling rl_named_function("accept-line")();  in the handler doesn't work
> either.
> 

How about setting up a signal handler to catch the ^C?  man sigaction,
signal, et al.  Or is that how you are already calling cli_int?
--
Matthew Vanecek
perl -e 'print
$i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
********************************************************************************
For 93 million miles, there is nothing between the sun and my shadow
except me.
I'm always getting in the way of something...




More information about the linuxCprogramming mailing list