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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itk/] [mac/] [tkMacAppInit.c] - Blame information for rev 1771

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

Line No. Rev Author Line
1 578 markom
/*
2
 * tkMacAppInit.c --
3
 *
4
 *      Provides a version of the Tcl_AppInit procedure for the example shell.
5
 *
6
 * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
7
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 * SCCS: @(#) tkMacAppInit.c 1.35 97/07/28 11:18:55
13
 */
14
 
15
#include <Gestalt.h>
16
#include <ToolUtils.h>
17
#include <Fonts.h>
18
#include <Dialogs.h>
19
#include <SegLoad.h>
20
#include <Traps.h>
21
#include <Appearance.h>
22
 
23
#include "tk.h"
24
#include "tkInt.h"
25
#include "tkMacInt.h"
26
#include "tclMac.h"
27
 
28
#include "itk.h"
29
 
30
/* include tclInt.h for access to namespace API */
31
#include "tclInt.h"
32
 
33
#ifdef TK_TEST
34
EXTERN int              Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
35
#endif /* TK_TEST */
36
 
37
#ifdef TCL_TEST
38
EXTERN int              TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
39
EXTERN int              Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
40
#endif /* TCL_TEST */
41
 
42
Tcl_Interp *gStdoutInterp = NULL;
43
 
44
int     TkMacConvertEvent _ANSI_ARGS_((EventRecord *eventPtr));
45
 
46
/*
47
 * Prototypes for functions the ANSI library needs to link against.
48
 */
49
short                   InstallConsole _ANSI_ARGS_((short fd));
50
void                    RemoveConsole _ANSI_ARGS_((void));
51
long                    WriteCharsToConsole _ANSI_ARGS_((char *buff, long n));
52
long                    ReadCharsFromConsole _ANSI_ARGS_((char *buff, long n));
53
extern char *           __ttyname _ANSI_ARGS_((long fildes));
54
short                   SIOUXHandleOneEvent _ANSI_ARGS_((EventRecord *event));
55
 
56
/*
57
 * Prototypes for functions from the tkConsole.c file.
58
 */
59
 
60
EXTERN void             TkConsoleCreate _ANSI_ARGS_((void));
61
EXTERN int              TkConsoleInit _ANSI_ARGS_((Tcl_Interp *interp));
62
EXTERN void             TkConsolePrint _ANSI_ARGS_((Tcl_Interp *interp,
63
                            int devId, char *buffer, long size));
64
/*
65
 * Forward declarations for procedures defined later in this file:
66
 */
67
 
68
static int              MacintoshInit _ANSI_ARGS_((void));
69
static int              SetupMainInterp _ANSI_ARGS_((Tcl_Interp *interp));
70
 
71
/*
72
 *----------------------------------------------------------------------
73
 *
74
 * main --
75
 *
76
 *      Main program for Wish.
77
 *
78
 * Results:
79
 *      None. This procedure never returns (it exits the process when
80
 *      it's done
81
 *
82
 * Side effects:
83
 *      This procedure initializes the wish world and then
84
 *      calls Tk_Main.
85
 *
86
 *----------------------------------------------------------------------
87
 */
88
 
89
void
90
main(
91
    int argc,                           /* Number of arguments. */
92
    char **argv)                        /* Array of argument strings. */
93
{
94
    char *newArgv[2];
95
 
96
    if (MacintoshInit()  != TCL_OK) {
97
        Tcl_Exit(1);
98
    }
99
 
100
    argc = 1;
101
    newArgv[0] = "itkwish";
102
    newArgv[1] = NULL;
103
    Tk_Main(argc, newArgv, Tcl_AppInit);
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 interp->result if an error occurs.
118
 *
119
 * Side effects:
120
 *      Depends on the startup script.
121
 *
122
 *----------------------------------------------------------------------
123
 */
124
 
125
int
126
Tcl_AppInit(
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
     * Call the init procedures for included packages.  Each call should
139
     * look like this:
140
     *
141
     * if (Mod_Init(interp) == TCL_ERROR) {
142
     *     return TCL_ERROR;
143
     * }
144
     *
145
     * where "Mod" is the name of the module.
146
     */
147
 
148
#ifdef TCL_TEST
149
    if (Tcltest_Init(interp) == TCL_ERROR) {
150
        return TCL_ERROR;
151
    }
152
    Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
153
            (Tcl_PackageInitProc *) NULL);
154
    if (TclObjTest_Init(interp) == TCL_ERROR) {
155
        return TCL_ERROR;
156
    }
157
#endif /* TCL_TEST */
158
 
159
#ifdef TK_TEST
160
    if (Tktest_Init(interp) == TCL_ERROR) {
161
        return TCL_ERROR;
162
    }
163
    Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
164
            (Tcl_PackageInitProc *) NULL);
165
#endif /* TK_TEST */
166
 
167
    /*
168
     * Call Tcl_CreateCommand for application-specific commands, if
169
     * they weren't already created by the init procedures called above.
170
     * Each call would look like this:
171
     *
172
     * Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL);
173
     */
174
    if (Itcl_Init(interp) == TCL_ERROR) {
175
        return TCL_ERROR;
176
    }
177
    if (Itk_Init(interp) == TCL_ERROR) {
178
        return TCL_ERROR;
179
    }
180
    Tcl_StaticPackage(interp, "Itcl", Itcl_Init, Itcl_SafeInit);
181
    Tcl_StaticPackage(interp, "Itk", Itk_Init, (Tcl_PackageInitProc *) NULL);
182
 
183
    /*
184
     *  This is itkwish, so import all [incr Tcl] commands by
185
     *  default into the global namespace.  Fix up the autoloader
186
     *  to do the same.
187
     */
188
    if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp),
189
            "::itk::*", /* allowOverwrite */ 1) != TCL_OK) {
190
        return TCL_ERROR;
191
    }
192
 
193
    if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp),
194
            "::itcl::*", /* allowOverwrite */ 1) != TCL_OK) {
195
        return TCL_ERROR;
196
    }
197
 
198
    if (Tcl_Eval(interp, "auto_mkindex_parser::slavehook { _%@namespace import -force ::itcl::* ::itk::* }") != TCL_OK) {
199
        return TCL_ERROR;
200
    }
201
 
202
    SetupMainInterp(interp);
203
 
204
    /*
205
     * Specify a user-specific startup script to invoke if the application
206
     * is run interactively.  On the Mac we can specifiy either a TEXT resource
207
     * which contains the script or the more UNIX like file location
208
     * may also used.  (I highly recommend using the resource method.)
209
     */
210
 
211
    Tcl_SetVar(interp, "tcl_rcRsrcName", "itkwishrc", TCL_GLOBAL_ONLY);
212
    /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.itkwishrc", TCL_GLOBAL_ONLY); */
213
 
214
    return TCL_OK;
215
}
216
 
217
/*
218
 *----------------------------------------------------------------------
219
 *
220
 * MacintoshInit --
221
 *
222
 *      This procedure calls Mac specific initilization calls.  Most of
223
 *      these calls must be made as soon as possible in the startup
224
 *      process.
225
 *
226
 * Results:
227
 *      Returns TCL_OK if everything went fine.  If it didn't the
228
 *      application should probably fail.
229
 *
230
 * Side effects:
231
 *      Inits the application.
232
 *
233
 *----------------------------------------------------------------------
234
 */
235
 
236
static int
237
MacintoshInit()
238
{
239
    int i;
240
    long result, mask = 0x0700;                 /* mask = system 7.x */
241
 
242
#if GENERATING68K && !GENERATINGCFM
243
    SetApplLimit(GetApplLimit() - (TK_MAC_68K_STACK_GROWTH));
244
#endif
245
    MaxApplZone();
246
    for (i = 0; i < 4; i++) {
247
        (void) MoreMasters();
248
    }
249
 
250
    /*
251
     * Tk needs us to set the qd pointer it uses.  This is needed
252
     * so Tk doesn't have to assume the availablity of the qd global
253
     * variable.  Which in turn allows Tk to be used in code resources.
254
     */
255
    tcl_macQdPtr = &qd;
256
 
257
    /*
258
     * If appearance is present, then register Tk as an Appearance client
259
     * This means that the mapping from non-Appearance to Appearance cdefs
260
     * will be done for Tk regardless of the setting in the Appearance
261
     * control panel.
262
     */
263
 
264
     if (TkMacHaveAppearance()) {
265
         RegisterAppearanceClient();
266
     }
267
 
268
    InitGraf(&tcl_macQdPtr->thePort);
269
    InitFonts();
270
    InitWindows();
271
    InitMenus();
272
    InitDialogs((long) NULL);
273
    InitCursor();
274
 
275
    /*
276
     * Make sure we are running on system 7 or higher
277
     */
278
 
279
    if ((NGetTrapAddress(_Gestalt, ToolTrap) ==
280
            NGetTrapAddress(_Unimplemented, ToolTrap))
281
            || (((Gestalt(gestaltSystemVersion, &result) != noErr)
282
            || (result < mask)))) {
283
        panic("Tcl/Tk requires System 7 or higher.");
284
    }
285
 
286
    /*
287
     * Make sure we have color quick draw
288
     * (this means we can't run on 68000 macs)
289
     */
290
 
291
    if (((Gestalt(gestaltQuickdrawVersion, &result) != noErr)
292
            || (result < gestalt32BitQD13))) {
293
        panic("Tk requires Color QuickDraw.");
294
    }
295
 
296
 
297
    FlushEvents(everyEvent, 0);
298
    SetEventMask(everyEvent);
299
 
300
 
301
    Tcl_MacSetEventProc(TkMacConvertEvent);
302
    TkConsoleCreate();
303
 
304
    return TCL_OK;
305
}
306
 
307
/*
308
 *----------------------------------------------------------------------
309
 *
310
 * SetupMainInterp --
311
 *
312
 *      This procedure calls initalization routines require a Tcl
313
 *      interp as an argument.  This call effectively makes the passed
314
 *      iterpreter the "main" interpreter for the application.
315
 *
316
 * Results:
317
 *      Returns TCL_OK if everything went fine.  If it didn't the
318
 *      application should probably fail.
319
 *
320
 * Side effects:
321
 *      More initilization.
322
 *
323
 *----------------------------------------------------------------------
324
 */
325
 
326
static int
327
SetupMainInterp(
328
    Tcl_Interp *interp)
329
{
330
    /*
331
     * Initialize the console only if we are running as an interactive
332
     * application.
333
     */
334
 
335
    TkMacInitAppleEvents(interp);
336
    TkMacInitMenus(interp);
337
 
338
    if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
339
            == 0) {
340
        if (TkConsoleInit(interp) == TCL_ERROR) {
341
            goto error;
342
        }
343
    }
344
 
345
    /*
346
     * Attach the global interpreter to tk's expected global console
347
     */
348
 
349
    gStdoutInterp = interp;
350
 
351
    return TCL_OK;
352
 
353
error:
354
    panic(interp->result);
355
    return TCL_ERROR;
356
}
357
 
358
/*
359
 *----------------------------------------------------------------------
360
 *
361
 * InstallConsole, RemoveConsole, etc. --
362
 *
363
 *      The following functions provide the UI for the console package.
364
 *      Users wishing to replace SIOUX with their own console package
365
 *      need only provide the four functions below in a library.
366
 *
367
 * Results:
368
 *      See SIOUX documentation for details.
369
 *
370
 * Side effects:
371
 *      See SIOUX documentation for details.
372
 *
373
 *----------------------------------------------------------------------
374
 */
375
 
376
short
377
InstallConsole(short fd)
378
{
379
#pragma unused (fd)
380
 
381
        return 0;
382
}
383
 
384
void
385
RemoveConsole(void)
386
{
387
}
388
 
389
long
390
WriteCharsToConsole(char *buffer, long n)
391
{
392
    TkConsolePrint(gStdoutInterp, TCL_STDOUT, buffer, n);
393
    return n;
394
}
395
 
396
long
397
ReadCharsFromConsole(char *buffer, long n)
398
{
399
    return 0;
400
}
401
 
402
extern char *
403
__ttyname(long fildes)
404
{
405
    static char *__devicename = "null device";
406
 
407
    if (fildes >= 0 && fildes <= 2) {
408
        return (__devicename);
409
    }
410
 
411
    return (0L);
412
}
413
 
414
short
415
SIOUXHandleOneEvent(EventRecord *event)
416
{
417
    return 0;
418
}

powered by: WebSVN 2.1.0

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