@@ -1,10 +1,10 @@ /* ================================================================== - FILE: "/home/joze/src/tclreadline/tclreadline.c" - LAST MODIFICATION: "Tue Aug 31 03:22:55 1999 (joze)" + FILE: "/diska/home/joze/src/tclreadline/tclreadline.c" + LAST MODIFICATION: "Wed Sep 1 18:58:04 1999 (joze)" (C) 1998, 1999 by Johannes Zellner, $Id$ --- tclreadline -- gnu readline for tcl @@ -34,10 +34,16 @@ #include #define READLINE_LIBRARY #include #include +/** + * this prototype is missing + * in readline.h + */ +void rl_extend_line_buffer(int len); + #include "tclreadline.h" #define MALLOC(size) Tcl_Alloc((int) size) #define FREE(ptr) if (ptr) { Tcl_Free((char*) ptr); ptr = 0; } @@ -63,11 +69,13 @@ char* stripright(char* in); char* stripwhite(char* in); char* TclReadlineQuote(char* text, char* quotechars); int TclReadlineCmd(ClientData clientData, Tcl_Interp* interp, int argc, char** argv); -void TclReadlineDataAvailableHandler(ClientData clientData, int mask); +int TclReadlineEventHook(void); +void TclReadlineReadHandler(ClientData clientData, int mask); +void TclReadlineWriteHandler(ClientData clientData, int mask); void TclReadlineLineCompleteHandler(char* ptr); int Tclreadline_SafeInit(Tcl_Interp* interp); int Tclreadline_Init(Tcl_Interp* interp); char *TclReadlineFilenameQuotingFunction( char *text, int match_type, char* quote_ptr); @@ -166,17 +174,22 @@ if (c == 'r' && strncmp(argv[1], "read", length) == 0) { char* expansion = (char*) NULL; int status; +#if 1 tclrl_line_complete = LINE_PENDING; tclrl_state = TCL_OK; rl_callback_handler_install(argc == 3 ? argv[2] : "%", TclReadlineLineCompleteHandler); Tcl_CreateFileHandler(0, TCL_READABLE, - TclReadlineDataAvailableHandler, (ClientData) NULL); + TclReadlineReadHandler, (ClientData) NULL); + /* + Tcl_CreateFileHandler(1, TCL_WRITABLE, + TclReadlineWriteHandler, (ClientData) NULL); + */ /** * Main Loop. * XXX each modification of the global variables * which terminates the main loop must call @@ -183,12 +196,14 @@ * rl_callback_handler_remove() to leave * readline in a defined state. XXX */ while (LINE_PENDING == tclrl_line_complete && TCL_OK == tclrl_state && !rl_done) { - Tcl_DoOneEvent(0); + Tcl_DoOneEvent(TCL_ALL_EVENTS); /* + Tcl_DoOneEvent(0); + fprintf (stderr, "(TclReadlineCmd) \n"); rl_inhibit_completion = 0; */ } Tcl_DeleteFileHandler(0); @@ -197,10 +212,14 @@ if ((LINE_EOF == tclrl_line_complete) && tclrl_eof_string) { Tcl_Eval(interp, tclrl_eof_string); return tclrl_state; } +#else + rl_event_hook = TclReadlineEventHook; + tclrl_line = readline(argc == 3 ? argv[2] : "%"); +#endif status = history_expand(tclrl_line, &expansion); if (status >= 1) { #if 0 Tcl_Channel channel = Tcl_MakeFileChannel(stdout, TCL_WRITABLE); @@ -306,18 +325,51 @@ (char*) NULL); return TCL_ERROR; } +int TclReadlineEventHook(void) +{ + Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT); + /* + TCL_DONT_WAIT + TCL_WINDOW_EVENTS + TCL_FILE_EVENTS + TCL_TIMER_EVENTS + TCL_IDLE_EVENTS + TCL_ALL_EVENTS + */ +} void -TclReadlineDataAvailableHandler(ClientData clientData, int mask) +TclReadlineReadHandler(ClientData clientData, int mask) { #if 0 - fprintf(stderr, "(TclReadlineDataAvailableHandler) mask = %d\n", mask); + fprintf(stderr, "(TclReadlineReadHandler) mask = %d\n", mask); #endif if (mask & TCL_READABLE) { - rl_callback_read_char(); + /* + fprintf(stderr, "(TclReadlineReadHandler) mask = readable\n"); + rl_event_hook = TclReadlineEventHook; + while (!rl_done) { + */ + rl_callback_read_char(); + /* + } + fflush(stdin); + */ + } +} + +void +TclReadlineWriteHandler(ClientData clientData, int mask) +{ + if (mask & TCL_WRITABLE) { + /* + fprintf(stderr, "(TclReadlineReadHandler) mask = writable\n"); + */ + fflush(stdout); + rl_redisplay(); } } void TclReadlineLineCompleteHandler(char* ptr)