The GNU Readline library [http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html] provides a set of functions for use by applications that allow users to edit command lines as they are typed in. Most of the work in the readline library is done by the readline function. The C-code below will provide a tcl procedure readline which can be used as: readline prompt While editing the line all the standard readline functionality is available. A build of the extension for Win32 can be downloaded from [http://marknet.tk/downloads/tclreadline01.dll]. -- [[[MJ]]] [slebetman] notes that for the Win32 platform, readline is not necessary as native tclsh on Win32 already have line editing capability including history and history substitution (which I believe is due to DOSKEY). People usually want readline for Tcl when they are on Unix. [MJ] agrees that on Windows it is not necessary per se, but I like a consistent interface in my application regardless if it is run on Linux or Windows. Readline keyboard shortcuts have a tendency to stick in your fingers, which makes working with a Windows CLI application painful. [MJ] -- In the previous build an access violation occured on the free(line_read) this was caused by the fact that the dll linked to msvcr70.dll and msvcrt.dll at the same time. malloc was used from the one dll and free from the other resulting in a crash. The current dll at the url above only links to msvcrt.dll, solving the problem. ---- ''tclreadline.h'' #ifndef _TCLREADLINE_TCL_H #define _TCLREADLINE_TCL_H static int ReadlineCmd( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) ; #endif _TCLREADLINE_TCL_H ''tclreadline.c'' #include #include #include #include "tclreadline.h" __declspec(dllexport) int Tclreadline_Init(Tcl_Interp *interp) { if (Tcl_InitStubs(interp, TCL_VERSION, 0) == 0L) { return TCL_ERROR; } /* initialize history */ using_history (); /* Disable file completion as Tcl doesn't understand the windows file format with \ */ rl_bind_key ('\t', rl_insert); Tcl_CreateObjCommand(interp, "readline", ReadlineCmd, NULL, NULL); Tcl_PkgProvide(interp, "tclreadline", PKG_VERSION); return TCL_OK; } static int ReadlineCmd( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) { char * line_read; if(objc!=2) { Tcl_WrongNumArgs(interp,1,objv,"prompt"); return TCL_ERROR; } /* Get a line from the user. */ line_read = readline (Tcl_GetString(objv[1])); if (line_read!=NULL ) { if (*line_read) add_history (line_read); Tcl_SetObjResult(interp, Tcl_NewStringObj(line_read, -1)); free(line_read); return TCL_OK; } else { Tcl_SetObjResult(interp, Tcl_NewStringObj("EOF entered", -1)); return TCL_ERROR; } } ---- [Category Extension]