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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [mac/] [tkMacAppInit.c] - Blame information for rev 1765

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

powered by: WebSVN 2.1.0

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