source: tol/tolbase/generic/tolbase.c @ 59323be

1941-docker-image-to-testdevel
Last change on this file since 59323be was 59323be, checked in by Jorge Pérez <josp.jorge@…>, 11 years ago

fixes #1903, nos apoyamos en un script auxiliar para que tk se inicialice en modo no interactivo, para ello hacemos uso de la función Tcl_SetStartupScript, por ahora WIN32 sigue como antes pero hay que validar como responde cuando se invoca con argumentos por linea de comandos, cambiamos /bin/sh por /bin/bash

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@7119 be4846ae-f051-483a-831f-b64e7d08527f

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