Re: [Cgdb-devel] cgdb and readline
Brought to you by:
bobbybrasko,
crouchingturbo
From: Peter K. <pe...@ko...> - 2003-02-20 03:22:01
|
I was just searching through the readline info pages and I found this entry: Alternate Interface ------------------- An alternate interface is available to plain `readline()'. Some applications need to interleave keyboard I/O with file, device, or wind= ow system I/O, typically by using a main loop to `select()' on various file descriptors. To accomodate this need, readline can also be invoked as a `callback' function from an event loop. There are functions available = to make this easy. - Function: void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler) Set up the terminal for readline I/O and display the initial expan= ded value of PROMPT. Save the value of LHANDLER to use as a function = to call when a complete line of input has been entered. The function takes the text of the line as an argument. - Function: void rl_callback_read_char (void) Whenever an application determines that keyboard input is availabl= e, it should call `rl_callback_read_char()', which will read the next character from the current input source. If that character comple= tes the line, `rl_callback_read_char' will invoke the LHANDLER function saved by `rl_callback_handler_install' to process the line. `EOF'= is indicated by calling LHANDLER with a `NULL' line. - Function: void rl_callback_handler_remove (void) Restore the terminal to its initial state and remove the line hand= ler. This may be called from within a callback as well as independently. That seems to be exactly what we need doesn't it? I'm not sure how we would integrate this into our main loop, but at least its a good start. - Peter On Wed, Feb 19, 2003 at 10:12:36PM -0500, Bob Rossi wrote: > Hey guys, >=20 > Look at this small example. It reads a line at a time and prints it. >=20 > #include <readline/readline.h> > #include <readline/history.h> > #include <stdlib.h> >=20 > /* Gets called when the user hits '\t' */ > int rl_complete (int ignore, int invoking_key) { > fprintf(stderr, "complete\n"); > return 0; > } >=20 > int main(int argc, char **argv){ > static char *line; > while(1) { > line =3D readline("PROMPT:"); > fprintf(stderr, "LINE=3D(%s)\n", line); > } > return 0; > } >=20 > I am trying to integrate readline into cgdb and ran into a problem. > Readline has a function called 'readline' that gets a line of input from > stdin. This is great, however, it is a blocking call ( It reads a whole > line and then returns). This is not good, since cgdb should also be able > to receive input if the user is in cgdb mode.=20 >=20 > For example, the users types 'info sour' and the ESC 'j' ( to go down a l= ine )=20 > and then 'i' ( to get back into gdb mode ) and then 'e<CR>'.=20 >=20 > How would we get readline to give up control? Or feed it a char at a > time? I don't know how to resolve this problem. >=20 > By the way, currently cgdb sits in a select loop reading from stdin, > gdb's stdout, and the debugged programs stdout (tty). How could we make > readline be a part of this? >=20 > Any suggestions? >=20 > Thanks, > Bobby --=20 Peter D. Kovacs <pe...@ko...> |