static char const rcsid[] = "@(#) $Id: main.c,v 1.6 2000/10/20 23:12:17 drh Exp $"; /* ** This file implements the main routine for a standalone Tcl/Tk shell. */ #include /* ** We will be linking against all of these extensions. */ extern int Blt_Init(Tcl_Interp*); extern int Img_Init(Tcl_Interp*); extern int Sqlite_Init(Tcl_Interp*); extern int Tkhtml_Init(Tcl_Interp*); extern int Tktable_Init(Tcl_Interp*); extern int Tlink_Init(Tcl_Interp*); extern int Winico_Init(Tcl_Interp*); extern int Zvfs_Init(Tcl_Interp*); extern int Zvfs_Mount(Tcl_Interp*, char*, char *); /* ** This is the event loop */ static char zWaitForever[] = "bind . {+if {\"%W\"==\".\"} exit}\n" "while 1 {vwait forever}" ; /* ** This routine runs first. */ int main(int argc, char **argv){ Tcl_Interp *interp; char *args; char buf[100]; /* Create a Tcl interpreter */ Tcl_FindExecutable(argv[0]); interp = Tcl_CreateInterp(); if( Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 1)==0 ){ return 1; } args = Tcl_Merge(argc-1, argv+1); Tcl_SetVar(interp, "argv", args, TCL_GLOBAL_ONLY); ckfree(args); sprintf(buf, "%d", argc-1); Tcl_SetVar(interp, "argc", buf, TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "argv0", argv[0], TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); /* We have to initialize the virtual filesystem before calling ** Tcl_Init(). Otherwise, Tcl_Init() will not be able to find ** its startup script files. */ Zvfs_Init(interp); Zvfs_Mount(interp, Tcl_GetNameOfExecutable(), "/zvfs"); Tcl_SetVar2(interp, "env", "TCL_LIBRARY", "/zvfs/tcl", TCL_GLOBAL_ONLY); Tcl_SetVar2(interp, "env", "TK_LIBRARY", "/zvfs/tk", TCL_GLOBAL_ONLY); /* Initialize Tcl and Tk */ Tk_InitConsoleChannels(interp); if( Tcl_Init(interp) ) return 1; if( Tk_Init(interp) ) return 1; Tcl_StaticPackage(interp,"Tk", Tk_Init, 0); Tk_CreateConsoleWindow(interp); /* Start up all extensions. */ #ifndef WITHOUT_BLT Blt_Init(interp); #endif #ifndef WITHOUT_IMG Img_Init(interp); #endif #ifndef WITHOUT_SQLITE Sqlite_Init(interp); #endif #ifndef WITHOUT_TKHTML Tkhtml_Init(interp); #endif #ifndef WITHOUT_TKTABLE Tktable_Init(interp); #endif #if !defined(WITHOUT_TLINK) && (defined(__WIN32__) || defined(_WIN32)) Tlink_Init(interp); #endif #if !defined(WITHOUT_WINICO) && (defined(__WIN32__) || defined(_WIN32)) Winico_Init(interp); #endif /* After all extensions are registered, start up the ** program by running /zvfs/main.tcl. */ Tcl_Eval(interp, "source /zvfs/main.tcl"); Tcl_Eval(interp, zWaitForever); return TCL_OK; }