| 1 | #include <tcl.h> |
|---|
| 2 | #include "toltcl.h" |
|---|
| 3 | |
|---|
| 4 | #if !defined(WIN32) |
|---|
| 5 | #include "tol/tol_init.h" |
|---|
| 6 | #endif |
|---|
| 7 | |
|---|
| 8 | static int g_argc = 0; |
|---|
| 9 | static char **g_argv = NULL; |
|---|
| 10 | |
|---|
| 11 | static |
|---|
| 12 | void SetupArgv( Tcl_Interp *interp ) |
|---|
| 13 | { |
|---|
| 14 | Tcl_Obj *argvPtr = Tcl_NewListObj(0, NULL); |
|---|
| 15 | int i; |
|---|
| 16 | for( i = 1; i < g_argc; i++ ) |
|---|
| 17 | { |
|---|
| 18 | Tcl_DString ds; |
|---|
| 19 | Tcl_ExternalToUtfDString(NULL, g_argv[i], -1, &ds); |
|---|
| 20 | Tcl_ListObjAppendElement(NULL, argvPtr, |
|---|
| 21 | Tcl_NewStringObj(Tcl_DStringValue(&ds), |
|---|
| 22 | Tcl_DStringLength(&ds))); |
|---|
| 23 | Tcl_DStringFree(&ds); |
|---|
| 24 | } |
|---|
| 25 | Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY); |
|---|
| 26 | Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewIntObj(g_argc-1), TCL_GLOBAL_ONLY); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | int AppInit(Tcl_Interp *interp) |
|---|
| 30 | { |
|---|
| 31 | if( Tcl_Init(interp) == TCL_ERROR ) |
|---|
| 32 | { |
|---|
| 33 | return TCL_ERROR; |
|---|
| 34 | } |
|---|
| 35 | SetupArgv( interp ); |
|---|
| 36 | Tcl_VarEval( interp, "lappend", " auto_path", " [file join", |
|---|
| 37 | " [file dir [file dir ", Tcl_GetNameOfExecutable(), |
|---|
| 38 | " ] ] lib ]", NULL ); |
|---|
| 39 | if ( !Tcl_PkgRequire( interp, "TolshApp", TOLTCL_VERSION, 1) ) |
|---|
| 40 | { |
|---|
| 41 | printf( "%s\n", Tcl_GetStringResult( interp ) ); |
|---|
| 42 | Tcl_Exit( -1 ); |
|---|
| 43 | } |
|---|
| 44 | return TCL_OK; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | int main(int argc, char *argv[]) |
|---|
| 48 | { |
|---|
| 49 | g_argc = argc; |
|---|
| 50 | g_argv = argv; |
|---|
| 51 | const char * version = TOLVersion(); |
|---|
| 52 | Tcl_Main( 1, argv, AppInit ); |
|---|
| 53 | return 0; |
|---|
| 54 | } |
|---|