#include #include #include #include #include "halcmd.h" Tcl_Interp *target_interp = NULL; static int pending_cr = 0; static void halError(Tcl_Interp *interp, int result) { Tcl_SetResult(interp, strerror(-result), TCL_VOLATILE); } static int refcount = 0; static void shutdown(void) { if(refcount > 0) { refcount --; if(refcount == 0) halcmd_shutdown(); } } static int init() { int result = 0; if(refcount == 0) { result = halcmd_startup(0); atexit(shutdown); } if(result == 0) { refcount ++; } return result; } static void halExit(ClientData d) { shutdown(); } static int halCmd(ClientData cd, Tcl_Interp *interp, int argc, const char **argv) { int result; Tcl_ResetResult(interp); if(argc < 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " command ...\"", NULL); return TCL_ERROR; } if(strcmp(argv[1], "--commands") == 0) { int i; Tcl_ResetResult(interp); for(i=0; i