OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [win/] [tixWinMain.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixWinMain.c --
3
 *
4
 *      Main entry point for wish and other Tk-based applications.
5
 *
6
 * Copyright (c) 1996, Expert Interface Technologies
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 *
12
 */
13
 
14
#include <tk.h>
15
#include <tixInt.h>
16
#define WIN32_LEAN_AND_MEAN
17
#include <windows.h>
18
#undef WIN32_LEAN_AND_MEAN
19
#include <malloc.h>
20
#include <locale.h>
21
 
22
#ifdef ITCL_2
23
#include "itcl.h"
24
#include "itk.h"
25
#endif
26
 
27
/*
28
 * The following declarations refer to internal Tk routines.  These
29
 * interfaces are available for use, but are not supported.
30
 */
31
 
32
EXTERN void             TkConsoleCreate _ANSI_ARGS_((void));
33
EXTERN int              TkConsoleInit _ANSI_ARGS_((Tcl_Interp *interp));
34
 
35
/*
36
 * Forward declarations for procedures defined later in this file:
37
 */
38
 
39
static void             WishPanic _ANSI_ARGS_(TCL_VARARGS(char *,format));
40
 
41
 
42
/*
43
 *----------------------------------------------------------------------
44
 *
45
 * WinMain --
46
 *
47
 *      Main entry point from Windows.
48
 *
49
 * Results:
50
 *      Returns false if initialization fails, otherwise it never
51
 *      returns.
52
 *
53
 * Side effects:
54
 *      Just about anything, since from here we call arbitrary Tcl code.
55
 *
56
 *----------------------------------------------------------------------
57
 */
58
 
59
int APIENTRY
60
WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
61
    HINSTANCE hInstance;
62
    HINSTANCE hPrevInstance;
63
    LPSTR lpszCmdLine;
64
    int nCmdShow;
65
{
66
    char **argv, **argvlist, *p;
67
    int argc, size, i;
68
    char buffer[MAX_PATH];
69
 
70
    Tcl_SetPanicProc(WishPanic);
71
 
72
    /*
73
     * Increase the application queue size from default value of 8.
74
     * At the default value, cross application SendMessage of WM_KILLFOCUS
75
     * will fail because the handler will not be able to do a PostMessage!
76
     * This is only needed for Windows 3.x, since NT dynamically expands
77
     * the queue.
78
     */
79
    SetMessageQueue(64);
80
 
81
    /*
82
     * Precompute an overly pessimistic guess at the number of arguments
83
     * in the command line by counting non-space spans.  Note that we
84
     * have to allow room for the executable name and the trailing NULL
85
     * argument.
86
     */
87
 
88
    for (size = 3, p = lpszCmdLine; *p != '\0'; p++) {
89
        if (isspace(*p)) {
90
            size++;
91
            while (isspace(*p)) {
92
                p++;
93
            }
94
            if (*p == '\0') {
95
                break;
96
            }
97
        }
98
    }
99
    argvlist = (char **) ckalloc((unsigned) (size * sizeof(char *)));
100
    argv = argvlist;
101
 
102
    /*
103
     * Parse the Windows command line string.  If an argument begins with a
104
     * double quote, then spaces are considered part of the argument until the
105
     * next double quote.  The argument terminates at the second quote.  Note
106
     * that this is different from the usual Unix semantics.
107
     */
108
 
109
    for (i = 1, p = lpszCmdLine; *p != '\0'; i++) {
110
        while (isspace(*p)) {
111
            p++;
112
        }
113
        if (*p == '\0') {
114
            break;
115
        }
116
        if (*p == '"') {
117
            p++;
118
            argv[i] = p;
119
            while ((*p != '\0') && (*p != '"')) {
120
                p++;
121
            }
122
        } else {
123
            argv[i] = p;
124
            while (*p != '\0' && !isspace(*p)) {
125
                p++;
126
            }
127
        }
128
        if (*p != '\0') {
129
            *p = '\0';
130
            p++;
131
        }
132
    }
133
    argv[i] = NULL;
134
    argc = i;
135
 
136
    /*
137
     * Since Windows programs don't get passed the command name as the
138
     * first argument, we need to fetch it explicitly.
139
     */
140
 
141
    GetModuleFileName(NULL, buffer, sizeof(buffer));
142
    argv[0] = buffer;
143
 
144
    Tk_Main(argc, argv, Tcl_AppInit);
145
    return 1;
146
}
147
 
148
 
149
/*
150
 *----------------------------------------------------------------------
151
 *
152
 * Tcl_AppInit --
153
 *
154
 *      This procedure performs application-specific initialization.
155
 *      Most applications, especially those that incorporate additional
156
 *      packages, will have their own version of this procedure.
157
 *
158
 * Results:
159
 *      Returns a standard Tcl completion code, and leaves an error
160
 *      message in interp->result if an error occurs.
161
 *
162
 * Side effects:
163
 *      Depends on the startup script.
164
 *
165
 *----------------------------------------------------------------------
166
 */
167
 
168
int
169
Tcl_AppInit(interp)
170
    Tcl_Interp *interp;         /* Interpreter for application. */
171
{
172
    /*
173
     * Set up the default locale to be standard "C" locale so parsing
174
     * is performed correctly.
175
     */
176
    setlocale(LC_ALL, "C");
177
 
178
    /*
179
     * Increase the application queue size from default value of 8.
180
     * At the default value, cross application SendMessage of WM_KILLFOCUS
181
     * will fail because the handler will not be able to do a PostMessage!
182
     * This is only needed for Windows 3.x, since NT dynamically expands
183
     * the queue.
184
     */
185
    SetMessageQueue(64);
186
 
187
    /*
188
     * Create the console channels and install them as the standard
189
     * channels.  All I/O will be discarded until TkConsoleInit is
190
     * called to attach the console to a text widget.
191
     */
192
 
193
    TkConsoleCreate();
194
 
195
    if (Tcl_Init(interp) == TCL_ERROR) {
196
        if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) {
197
            MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY),
198
                "Tcl Init Error", MB_OK|MB_ICONSTOP);
199
        } else {
200
            MessageBox(NULL, interp->result, "Tcl Init Error",
201
                MB_OK|MB_ICONSTOP );
202
        }
203
        return TCL_ERROR;
204
    }
205
 
206
    if (Tk_Init(interp) == TCL_ERROR) {
207
        if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) {
208
            MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY),
209
                "Tk Init Error", MB_OK|MB_ICONSTOP);
210
        } else {
211
            MessageBox(NULL, interp->result, "Tk Init Error",
212
                MB_OK|MB_ICONSTOP);
213
        }
214
        return TCL_ERROR;
215
    }
216
    Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
217
 
218
#ifdef ITCL_2
219
    if (Itcl_Init(interp) == TCL_ERROR) {
220
        if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) {
221
            MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY),
222
                "Itcl Init Error", MB_OK|MB_ICONSTOP);
223
        } else {
224
            MessageBox(NULL, interp->result, "Itcl Init Error",
225
                MB_OK|MB_ICONSTOP);
226
        }
227
        return TCL_ERROR;
228
    }
229
    Tcl_StaticPackage(interp, "Itcl", Itcl_Init, (Tcl_PackageInitProc *) NULL);
230
 
231
    if (Itk_Init(interp) == TCL_ERROR) {
232
        if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) {
233
            MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY),
234
                "Itk Init Error", MB_OK|MB_ICONSTOP);
235
        } else {
236
            MessageBox(NULL, interp->result, "Itk Init Error",
237
                MB_OK|MB_ICONSTOP);
238
        }
239
        return TCL_ERROR;
240
    }
241
    Tcl_StaticPackage(interp, "Itk", Itk_Init, (Tcl_PackageInitProc *) NULL);
242
#endif
243
 
244
    if (Tix_Init(interp) == TCL_ERROR) {
245
        if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) {
246
            MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY),
247
                "Tix Init Error", MB_OK|MB_ICONSTOP);
248
        } else {
249
            MessageBox(NULL, interp->result, "Tix Init Error",
250
                MB_OK|MB_ICONSTOP);
251
        }
252
        return TCL_ERROR;
253
    }
254
    Tcl_StaticPackage(interp, "Tix", Tix_Init, (Tcl_PackageInitProc *) NULL);
255
 
256
    /*
257
     * Initialize the console only if we are running as an interactive
258
     * application.
259
     */
260
 
261
    if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
262
            == 0) {
263
        if (TkConsoleInit(interp) == TCL_ERROR) {
264
            return TCL_ERROR;
265
        }
266
    }
267
 
268
    Tcl_SetVar(interp, "tcl_rcFileName", "~/wishrc.tcl", TCL_GLOBAL_ONLY);
269
    return TCL_OK;
270
}
271
 
272
/*
273
 *----------------------------------------------------------------------
274
 *
275
 * WishPanic --
276
 *
277
 *      Display a message and exit.
278
 *
279
 * Results:
280
 *      None.
281
 *
282
 * Side effects:
283
 *      Exits the program.
284
 *
285
 *----------------------------------------------------------------------
286
 */
287
 
288
void
289
WishPanic TCL_VARARGS_DEF(char *,arg1)
290
{
291
    va_list argList;
292
    char buf[1024];
293
    char *format;
294
 
295
    format = TCL_VARARGS_START(char *,arg1,argList);
296
    vsprintf(buf, format, argList);
297
 
298
    MessageBeep(MB_ICONEXCLAMATION);
299
    MessageBox(NULL, buf, "Fatal Error in Wish",
300
        MB_ICONSTOP | MB_OK | MB_TASKMODAL | MB_SETFOREGROUND);
301
    ExitProcess(1);
302
}
303
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.