| 1 | /* |
|---|
| 2 | * tkAppInit.c -- |
|---|
| 3 | * |
|---|
| 4 | * Provides a default version of the Tcl_AppInit procedure for |
|---|
| 5 | * use in wish and similar Tk-based applications. |
|---|
| 6 | * |
|---|
| 7 | * Copyright (c) 1993 The Regents of the University of California. |
|---|
| 8 | * Copyright (c) 1994-1997 Sun Microsystems, Inc. |
|---|
| 9 | * |
|---|
| 10 | * See the file "license.terms" for information on usage and redistribution |
|---|
| 11 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #include "tk.h" |
|---|
| 15 | #include "locale.h" |
|---|
| 16 | #ifdef WIN32 |
|---|
| 17 | #include <windows.h> |
|---|
| 18 | #else |
|---|
| 19 | #include "tol/tol_init.h" |
|---|
| 20 | #endif |
|---|
| 21 | |
|---|
| 22 | // Tcl_SetStartupScript |
|---|
| 23 | #if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION <= 5 |
|---|
| 24 | //#include "tclIntDecls.h" |
|---|
| 25 | #endif |
|---|
| 26 | |
|---|
| 27 | static int g_argc = 0; |
|---|
| 28 | static char **g_argv = NULL; |
|---|
| 29 | |
|---|
| 30 | static |
|---|
| 31 | void SetupArgv( Tcl_Interp *interp ) |
|---|
| 32 | { |
|---|
| 33 | Tcl_Obj *argvPtr = Tcl_NewListObj(0, NULL); |
|---|
| 34 | int i; |
|---|
| 35 | for( i = 1; i < g_argc; i++ ) |
|---|
| 36 | { |
|---|
| 37 | Tcl_DString ds; |
|---|
| 38 | Tcl_ExternalToUtfDString(NULL, g_argv[i], -1, &ds); |
|---|
| 39 | Tcl_ListObjAppendElement(NULL, argvPtr, |
|---|
| 40 | Tcl_NewStringObj(Tcl_DStringValue(&ds), |
|---|
| 41 | Tcl_DStringLength(&ds))); |
|---|
| 42 | Tcl_DStringFree(&ds); |
|---|
| 43 | } |
|---|
| 44 | Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY); |
|---|
| 45 | Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewIntObj(g_argc-1), TCL_GLOBAL_ONLY); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | #ifdef TK_TEST |
|---|
| 49 | extern int Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp)); |
|---|
| 50 | #endif /* TK_TEST */ |
|---|
| 51 | |
|---|
| 52 | /* |
|---|
| 53 | *---------------------------------------------------------------------- |
|---|
| 54 | * |
|---|
| 55 | * main -- |
|---|
| 56 | * |
|---|
| 57 | * This is the main program for the application. |
|---|
| 58 | * |
|---|
| 59 | * Results: |
|---|
| 60 | * None: Tk_Main never returns here, so this procedure never |
|---|
| 61 | * returns either. |
|---|
| 62 | * |
|---|
| 63 | * Side effects: |
|---|
| 64 | * Whatever the application does. |
|---|
| 65 | * |
|---|
| 66 | *---------------------------------------------------------------------- |
|---|
| 67 | */ |
|---|
| 68 | |
|---|
| 69 | #ifdef WIN32 |
|---|
| 70 | #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") |
|---|
| 71 | #endif |
|---|
| 72 | |
|---|
| 73 | int |
|---|
| 74 | main(argc, argv) |
|---|
| 75 | int argc; /* Number of command-line arguments. */ |
|---|
| 76 | char **argv; /* Values of command-line arguments. */ |
|---|
| 77 | { |
|---|
| 78 | /* |
|---|
| 79 | * The following #if block allows you to change the AppInit |
|---|
| 80 | * function by using a #define of TCL_LOCAL_APPINIT instead |
|---|
| 81 | * of rewriting this entire file. The #if checks for that |
|---|
| 82 | * #define and uses Tcl_AppInit if it doesn't exist. |
|---|
| 83 | */ |
|---|
| 84 | |
|---|
| 85 | #ifndef TK_LOCAL_APPINIT |
|---|
| 86 | #define TK_LOCAL_APPINIT Tcl_AppInit |
|---|
| 87 | #endif |
|---|
| 88 | extern int TK_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp)); |
|---|
| 89 | |
|---|
| 90 | //HWND hwnd = GetConsoleWindow(); |
|---|
| 91 | //ShowWindow(hwnd, 0); |
|---|
| 92 | |
|---|
| 93 | /* |
|---|
| 94 | * The following #if block allows you to change how Tcl finds the startup |
|---|
| 95 | * script, prime the library or encoding paths, fiddle with the argv, |
|---|
| 96 | * etc., without needing to rewrite Tk_Main() |
|---|
| 97 | */ |
|---|
| 98 | |
|---|
| 99 | #ifdef TK_LOCAL_MAIN_HOOK |
|---|
| 100 | extern int TK_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv)); |
|---|
| 101 | TK_LOCAL_MAIN_HOOK(&argc, &argv); |
|---|
| 102 | #endif |
|---|
| 103 | |
|---|
| 104 | g_argc = argc; |
|---|
| 105 | g_argv = argv; |
|---|
| 106 | #ifndef WIN32 |
|---|
| 107 | const char * version = TOLVersion(); |
|---|
| 108 | #endif |
|---|
| 109 | Tk_Main( 1, argv, TK_LOCAL_APPINIT); |
|---|
| 110 | return 0; /* Needed only to prevent compiler warning. */ |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | /* |
|---|
| 114 | *---------------------------------------------------------------------- |
|---|
| 115 | * |
|---|
| 116 | * Tcl_AppInit -- |
|---|
| 117 | * |
|---|
| 118 | * This procedure performs application-specific initialization. |
|---|
| 119 | * Most applications, especially those that incorporate additional |
|---|
| 120 | * packages, will have their own version of this procedure. |
|---|
| 121 | * |
|---|
| 122 | * Results: |
|---|
| 123 | * Returns a standard Tcl completion code, and leaves an error |
|---|
| 124 | * message in the interp's result if an error occurs. |
|---|
| 125 | * |
|---|
| 126 | * Side effects: |
|---|
| 127 | * Depends on the startup script. |
|---|
| 128 | * |
|---|
| 129 | *---------------------------------------------------------------------- |
|---|
| 130 | */ |
|---|
| 131 | |
|---|
| 132 | int |
|---|
| 133 | Tcl_AppInit(interp) |
|---|
| 134 | Tcl_Interp *interp; /* Interpreter for application. */ |
|---|
| 135 | { |
|---|
| 136 | if (Tcl_Init(interp) == TCL_ERROR) { |
|---|
| 137 | return TCL_ERROR; |
|---|
| 138 | } |
|---|
| 139 | if (Tk_Init(interp) == TCL_ERROR) { |
|---|
| 140 | return TCL_ERROR; |
|---|
| 141 | } |
|---|
| 142 | // Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | /* |
|---|
| 146 | * Call the init procedures for included packages. Each call should |
|---|
| 147 | * look like this: |
|---|
| 148 | * |
|---|
| 149 | * if (Mod_Init(interp) == TCL_ERROR) { |
|---|
| 150 | * return TCL_ERROR; |
|---|
| 151 | * } |
|---|
| 152 | * |
|---|
| 153 | * where "Mod" is the name of the module. |
|---|
| 154 | */ |
|---|
| 155 | |
|---|
| 156 | /* |
|---|
| 157 | * Call Tcl_CreateCommand for application-specific commands, if |
|---|
| 158 | * they weren't already created by the init procedures called above. |
|---|
| 159 | */ |
|---|
| 160 | |
|---|
| 161 | /* |
|---|
| 162 | * Specify a user-specific startup file to invoke if the application |
|---|
| 163 | * is run interactively. Typically the startup file is "~/.apprc" |
|---|
| 164 | * where "app" is the name of the application. If this line is deleted |
|---|
| 165 | * then no user-specific startup file will be run under any conditions. |
|---|
| 166 | */ |
|---|
| 167 | |
|---|
| 168 | SetupArgv( interp ); |
|---|
| 169 | #if defined(WIN32) |
|---|
| 170 | Tcl_VarEval( interp, "lappend", " auto_path", " [file join", |
|---|
| 171 | " [file dir [file dir ", Tcl_GetNameOfExecutable(), |
|---|
| 172 | " ] ] lib ]", NULL ); |
|---|
| 173 | if ( !Tcl_PkgRequire( interp, "TolbaseApp", TOLBASE_VERSION, 1) ) |
|---|
| 174 | { |
|---|
| 175 | printf( "%s\n", Tcl_GetStringResult( interp ) ); |
|---|
| 176 | Tcl_Exit( -1 ); |
|---|
| 177 | } |
|---|
| 178 | //Tcl_PkgRequire( interp, "TolbaseApp", TOLBASE_VERSION, 1); |
|---|
| 179 | #else |
|---|
| 180 | const char* argv0 = Tcl_GetNameOfExecutable(); |
|---|
| 181 | Tcl_VarEval( interp, "file join ", |
|---|
| 182 | "[ file dir [expr {[file type {", argv0, "}] eq {link} ? [file readlink {", argv0, "}] : {", argv0 ,"}} ] ] tolbase.tcl", NULL ); |
|---|
| 183 | Tcl_Obj *objPath = Tcl_GetObjResult( interp ); |
|---|
| 184 | Tcl_SetStartupScript( Tcl_GetObjResult( interp ), NULL ); |
|---|
| 185 | #endif |
|---|
| 186 | return TCL_OK; |
|---|
| 187 | } |
|---|