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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [mac/] [tclMacAppInit.c] - Blame information for rev 1782

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

Line No. Rev Author Line
1 578 markom
/*
2
 * tclMacAppInit.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: @(#) tclMacAppInit.c 1.20 97/07/28 11:03:58
13
 */
14
 
15
/* include tclInt.h for access to namespace API */
16
#include "tclInt.h"
17
 
18
#include "tclInt.h"
19
#include "tclPort.h"
20
#include "tclMac.h"
21
#include "tclMacInt.h"
22
 
23
#include "itcl.h"
24
 
25
#if defined(THINK_C)
26
#   include <console.h>
27
#elif defined(__MWERKS__)
28
#   include <SIOUX.h>
29
short InstallConsole _ANSI_ARGS_((short fd));
30
#endif
31
 
32
#ifdef TCL_TEST
33
EXTERN int              TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
34
EXTERN int              Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
35
#endif /* TCL_TEST */
36
 
37
/*
38
 * Forward declarations for procedures defined later in this file:
39
 */
40
 
41
static int              MacintoshInit _ANSI_ARGS_((void));
42
 
43
/*
44
 *----------------------------------------------------------------------
45
 *
46
 * main --
47
 *
48
 *      Main program for tclsh.  This file can be used as a prototype
49
 *      for other applications using the Tcl library.
50
 *
51
 * Results:
52
 *      None. This procedure never returns (it exits the process when
53
 *      it's done.
54
 *
55
 * Side effects:
56
 *      This procedure initializes the Macintosh world and then
57
 *      calls Tcl_Main.  Tcl_Main will never return except to exit.
58
 *
59
 *----------------------------------------------------------------------
60
 */
61
 
62
void
63
main(
64
    int argc,                           /* Number of arguments. */
65
    char **argv)                        /* Array of argument strings. */
66
{
67
    char *newArgv[2];
68
 
69
    if (MacintoshInit()  != TCL_OK) {
70
        Tcl_Exit(1);
71
    }
72
 
73
    argc = 1;
74
    newArgv[0] = "itclsh";
75
    newArgv[1] = NULL;
76
    Tcl_Main(argc, newArgv, Tcl_AppInit);
77
}
78
 
79
/*
80
 *----------------------------------------------------------------------
81
 *
82
 * Tcl_AppInit --
83
 *
84
 *      This procedure performs application-specific initialization.
85
 *      Most applications, especially those that incorporate additional
86
 *      packages, will have their own version of this procedure.
87
 *
88
 * Results:
89
 *      Returns a standard Tcl completion code, and leaves an error
90
 *      message in interp->result if an error occurs.
91
 *
92
 * Side effects:
93
 *      Depends on the startup script.
94
 *
95
 *----------------------------------------------------------------------
96
 */
97
 
98
int
99
Tcl_AppInit(
100
    Tcl_Interp *interp)         /* Interpreter for application. */
101
{
102
    if (Tcl_Init(interp) == TCL_ERROR) {
103
        return TCL_ERROR;
104
    }
105
 
106
#ifdef TCL_TEST
107
    if (Tcltest_Init(interp) == TCL_ERROR) {
108
        return TCL_ERROR;
109
    }
110
    Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
111
            (Tcl_PackageInitProc *) NULL);
112
    if (TclObjTest_Init(interp) == TCL_ERROR) {
113
        return TCL_ERROR;
114
    }
115
#endif /* TCL_TEST */
116
 
117
    /*
118
     * Call the init procedures for included packages.  Each call should
119
     * look like this:
120
     *
121
     * if (Mod_Init(interp) == TCL_ERROR) {
122
     *     return TCL_ERROR;
123
     * }
124
     *
125
     * where "Mod" is the name of the module.
126
     */
127
    if (Itcl_Init(interp) == TCL_ERROR) {
128
        return TCL_ERROR;
129
    }
130
    Tcl_StaticPackage(interp, "Itcl", Itcl_Init, Itcl_SafeInit);
131
 
132
    /*
133
     *  This is itclsh, so import all [incr Tcl] commands by
134
     *  default into the global namespace.  Fix up the autoloader
135
     *  to do the same.
136
     */
137
    if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp),
138
            "::itcl::*", /* allowOverwrite */ 1) != TCL_OK) {
139
        return TCL_ERROR;
140
    }
141
 
142
    if (Tcl_Eval(interp, "auto_mkindex_parser::slavehook { _%@namespace import -force ::itcl::* }") != TCL_OK) {
143
        return TCL_ERROR;
144
    }
145
 
146
    /*
147
     * Call Tcl_CreateCommand for application-specific commands, if
148
     * they weren't already created by the init procedures called above.
149
     * Each call would loo like this:
150
     *
151
     * Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL);
152
     */
153
 
154
    /*
155
     * Specify a user-specific startup script to invoke if the application
156
     * is run interactively.  On the Mac we can specifiy either a TEXT resource
157
     * which contains the script or the more UNIX like file location
158
     * may also used.  (I highly recommend using the resource method.)
159
     */
160
 
161
    Tcl_SetVar(interp, "tcl_rcRsrcName", "itclshrc", TCL_GLOBAL_ONLY);
162
    /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.itclshrc", TCL_GLOBAL_ONLY); */
163
 
164
    return TCL_OK;
165
}
166
 
167
/*
168
 *----------------------------------------------------------------------
169
 *
170
 * MacintoshInit --
171
 *
172
 *      This procedure calls initalization routines to set up a simple
173
 *      console on a Macintosh.  This is necessary as the Mac doesn't
174
 *      have a stdout & stderr by default.
175
 *
176
 * Results:
177
 *      Returns TCL_OK if everything went fine.  If it didn't the
178
 *      application should probably fail.
179
 *
180
 * Side effects:
181
 *      Inits the appropiate console package.
182
 *
183
 *----------------------------------------------------------------------
184
 */
185
 
186
static int
187
MacintoshInit()
188
{
189
#if GENERATING68K && !GENERATINGCFM
190
    SetApplLimit(GetApplLimit() - (TCL_MAC_68K_STACK_GROWTH));
191
#endif
192
    MaxApplZone();
193
 
194
#if defined(THINK_C)
195
 
196
    /* Set options for Think C console package */
197
    /* The console package calls the Mac init calls */
198
    console_options.pause_atexit = 0;
199
    console_options.title = "\pTcl Interpreter";
200
 
201
#elif defined(__MWERKS__)
202
 
203
    /* Set options for CodeWarrior SIOUX package */
204
    SIOUXSettings.autocloseonquit = true;
205
    SIOUXSettings.showstatusline = true;
206
    SIOUXSettings.asktosaveonclose = false;
207
    InstallConsole(0);
208
    SIOUXSetTitle("\pTcl Interpreter");
209
 
210
#elif defined(applec)
211
 
212
    /* Init packages used by MPW SIOW package */
213
    InitGraf((Ptr)&qd.thePort);
214
    InitFonts();
215
    InitWindows();
216
    InitMenus();
217
    TEInit();
218
    InitDialogs(nil);
219
    InitCursor();
220
 
221
#endif
222
 
223
    Tcl_MacSetEventProc((Tcl_MacConvertEventPtr) SIOUXHandleOneEvent);
224
 
225
    /* No problems with initialization */
226
    return TCL_OK;
227
}

powered by: WebSVN 2.1.0

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