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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [mac/] [tkMacAppInit.c] - Diff between revs 579 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/*
/*
 * tkMacAppInit.c --
 * tkMacAppInit.c --
 *
 *
 *      Provides a version of the Tcl_AppInit procedure for the example shell.
 *      Provides a version of the Tcl_AppInit procedure for the example shell.
 *
 *
 * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
 * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 *
 *
 * See the file "license.terms" for information on usage and redistribution
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 *
 * RCS: @(#) $Id: tkMacAppInit.c,v 1.1.1.1 2002-01-16 10:25:55 markom Exp $
 * RCS: @(#) $Id: tkMacAppInit.c,v 1.1.1.1 2002-01-16 10:25:55 markom Exp $
 */
 */
 
 
#include <Gestalt.h>
#include <Gestalt.h>
#include <ToolUtils.h>
#include <ToolUtils.h>
#include <Fonts.h>
#include <Fonts.h>
#include <Dialogs.h>
#include <Dialogs.h>
#include <SegLoad.h>
#include <SegLoad.h>
#include <Traps.h>
#include <Traps.h>
#include <Appearance.h>
#include <Appearance.h>
 
 
#include "tk.h"
#include "tk.h"
#include "tkInt.h"
#include "tkInt.h"
#include "tkMacInt.h"
#include "tkMacInt.h"
#include "tclMac.h"
#include "tclMac.h"
 
 
#ifdef TK_TEST
#ifdef TK_TEST
EXTERN int              Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
#endif /* TK_TEST */
#endif /* TK_TEST */
 
 
#ifdef TCL_TEST
#ifdef TCL_TEST
EXTERN int              Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              Procbodytest_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              Procbodytest_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
#endif /* TCL_TEST */
#endif /* TCL_TEST */
 
 
Tcl_Interp *gStdoutInterp = NULL;
Tcl_Interp *gStdoutInterp = NULL;
 
 
int     TkMacConvertEvent _ANSI_ARGS_((EventRecord *eventPtr));
int     TkMacConvertEvent _ANSI_ARGS_((EventRecord *eventPtr));
 
 
/*
/*
 * Prototypes for functions the ANSI library needs to link against.
 * Prototypes for functions the ANSI library needs to link against.
 */
 */
short                   InstallConsole _ANSI_ARGS_((short fd));
short                   InstallConsole _ANSI_ARGS_((short fd));
void                    RemoveConsole _ANSI_ARGS_((void));
void                    RemoveConsole _ANSI_ARGS_((void));
long                    WriteCharsToConsole _ANSI_ARGS_((char *buff, long n));
long                    WriteCharsToConsole _ANSI_ARGS_((char *buff, long n));
long                    ReadCharsFromConsole _ANSI_ARGS_((char *buff, long n));
long                    ReadCharsFromConsole _ANSI_ARGS_((char *buff, long n));
extern char *           __ttyname _ANSI_ARGS_((long fildes));
extern char *           __ttyname _ANSI_ARGS_((long fildes));
short                   SIOUXHandleOneEvent _ANSI_ARGS_((EventRecord *event));
short                   SIOUXHandleOneEvent _ANSI_ARGS_((EventRecord *event));
 
 
/*
/*
 * Prototypes for functions from the tkConsole.c file.
 * Prototypes for functions from the tkConsole.c file.
 */
 */
 
 
EXTERN void             TkConsoleCreate _ANSI_ARGS_((void));
EXTERN void             TkConsoleCreate _ANSI_ARGS_((void));
EXTERN int              TkConsoleInit _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN int              TkConsoleInit _ANSI_ARGS_((Tcl_Interp *interp));
EXTERN void             TkConsolePrint _ANSI_ARGS_((Tcl_Interp *interp,
EXTERN void             TkConsolePrint _ANSI_ARGS_((Tcl_Interp *interp,
                            int devId, char *buffer, long size));
                            int devId, char *buffer, long size));
/*
/*
 * Forward declarations for procedures defined later in this file:
 * Forward declarations for procedures defined later in this file:
 */
 */
 
 
static int              MacintoshInit _ANSI_ARGS_((void));
static int              MacintoshInit _ANSI_ARGS_((void));
static int              SetupMainInterp _ANSI_ARGS_((Tcl_Interp *interp));
static int              SetupMainInterp _ANSI_ARGS_((Tcl_Interp *interp));


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * main --
 * main --
 *
 *
 *      Main program for Wish.
 *      Main program for Wish.
 *
 *
 * Results:
 * Results:
 *      None. This procedure never returns (it exits the process when
 *      None. This procedure never returns (it exits the process when
 *      it's done
 *      it's done
 *
 *
 * Side effects:
 * Side effects:
 *      This procedure initializes the wish world and then
 *      This procedure initializes the wish world and then
 *      calls Tk_Main.
 *      calls Tk_Main.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
main(
main(
    int argc,                           /* Number of arguments. */
    int argc,                           /* Number of arguments. */
    char **argv)                        /* Array of argument strings. */
    char **argv)                        /* Array of argument strings. */
{
{
    char *newArgv[2];
    char *newArgv[2];
 
 
    if (MacintoshInit()  != TCL_OK) {
    if (MacintoshInit()  != TCL_OK) {
        Tcl_Exit(1);
        Tcl_Exit(1);
    }
    }
 
 
    argc = 1;
    argc = 1;
    newArgv[0] = "Wish";
    newArgv[0] = "Wish";
    newArgv[1] = NULL;
    newArgv[1] = NULL;
    Tk_Main(argc, newArgv, Tcl_AppInit);
    Tk_Main(argc, newArgv, Tcl_AppInit);
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * Tcl_AppInit --
 * Tcl_AppInit --
 *
 *
 *      This procedure performs application-specific initialization.
 *      This procedure performs application-specific initialization.
 *      Most applications, especially those that incorporate additional
 *      Most applications, especially those that incorporate additional
 *      packages, will have their own version of this procedure.
 *      packages, will have their own version of this procedure.
 *
 *
 * Results:
 * Results:
 *      Returns a standard Tcl completion code, and leaves an error
 *      Returns a standard Tcl completion code, and leaves an error
 *      message in interp->result if an error occurs.
 *      message in interp->result if an error occurs.
 *
 *
 * Side effects:
 * Side effects:
 *      Depends on the startup script.
 *      Depends on the startup script.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
Tcl_AppInit(
Tcl_AppInit(
    Tcl_Interp *interp)         /* Interpreter for application. */
    Tcl_Interp *interp)         /* Interpreter for application. */
{
{
    if (Tcl_Init(interp) == TCL_ERROR) {
    if (Tcl_Init(interp) == TCL_ERROR) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    if (Tk_Init(interp) == TCL_ERROR) {
    if (Tk_Init(interp) == TCL_ERROR) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
    Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
 
 
    /*
    /*
     * Call the init procedures for included packages.  Each call should
     * Call the init procedures for included packages.  Each call should
     * look like this:
     * look like this:
     *
     *
     * if (Mod_Init(interp) == TCL_ERROR) {
     * if (Mod_Init(interp) == TCL_ERROR) {
     *     return TCL_ERROR;
     *     return TCL_ERROR;
     * }
     * }
     *
     *
     * where "Mod" is the name of the module.
     * where "Mod" is the name of the module.
     */
     */
 
 
#ifdef TCL_TEST
#ifdef TCL_TEST
    if (Tcltest_Init(interp) == TCL_ERROR) {
    if (Tcltest_Init(interp) == TCL_ERROR) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
    Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
            (Tcl_PackageInitProc *) NULL);
            (Tcl_PackageInitProc *) NULL);
    if (TclObjTest_Init(interp) == TCL_ERROR) {
    if (TclObjTest_Init(interp) == TCL_ERROR) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    if (Procbodytest_Init(interp) == TCL_ERROR) {
    if (Procbodytest_Init(interp) == TCL_ERROR) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init,
    Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init,
            Procbodytest_SafeInit);
            Procbodytest_SafeInit);
#endif /* TCL_TEST */
#endif /* TCL_TEST */
 
 
#ifdef TK_TEST
#ifdef TK_TEST
    if (Tktest_Init(interp) == TCL_ERROR) {
    if (Tktest_Init(interp) == TCL_ERROR) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
    Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
            (Tcl_PackageInitProc *) NULL);
            (Tcl_PackageInitProc *) NULL);
#endif /* TK_TEST */
#endif /* TK_TEST */
 
 
    /*
    /*
     * Call Tcl_CreateCommand for application-specific commands, if
     * Call Tcl_CreateCommand for application-specific commands, if
     * they weren't already created by the init procedures called above.
     * they weren't already created by the init procedures called above.
     * Each call would look like this:
     * Each call would look like this:
     *
     *
     * Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL);
     * Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL);
     */
     */
 
 
    SetupMainInterp(interp);
    SetupMainInterp(interp);
 
 
    /*
    /*
     * Specify a user-specific startup script to invoke if the application
     * Specify a user-specific startup script to invoke if the application
     * is run interactively.  On the Mac we can specifiy either a TEXT resource
     * is run interactively.  On the Mac we can specifiy either a TEXT resource
     * which contains the script or the more UNIX like file location
     * which contains the script or the more UNIX like file location
     * may also used.  (I highly recommend using the resource method.)
     * may also used.  (I highly recommend using the resource method.)
     */
     */
 
 
    Tcl_SetVar(interp, "tcl_rcRsrcName", "tclshrc", TCL_GLOBAL_ONLY);
    Tcl_SetVar(interp, "tcl_rcRsrcName", "tclshrc", TCL_GLOBAL_ONLY);
    /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); */
    /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); */
 
 
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * MacintoshInit --
 * MacintoshInit --
 *
 *
 *      This procedure calls Mac specific initilization calls.  Most of
 *      This procedure calls Mac specific initilization calls.  Most of
 *      these calls must be made as soon as possible in the startup
 *      these calls must be made as soon as possible in the startup
 *      process.
 *      process.
 *
 *
 * Results:
 * Results:
 *      Returns TCL_OK if everything went fine.  If it didn't the
 *      Returns TCL_OK if everything went fine.  If it didn't the
 *      application should probably fail.
 *      application should probably fail.
 *
 *
 * Side effects:
 * Side effects:
 *      Inits the application.
 *      Inits the application.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static int
static int
MacintoshInit()
MacintoshInit()
{
{
    int i;
    int i;
    long result, mask = 0x0700;                 /* mask = system 7.x */
    long result, mask = 0x0700;                 /* mask = system 7.x */
 
 
#if GENERATING68K && !GENERATINGCFM
#if GENERATING68K && !GENERATINGCFM
    SetApplLimit(GetApplLimit() - (TK_MAC_68K_STACK_GROWTH));
    SetApplLimit(GetApplLimit() - (TK_MAC_68K_STACK_GROWTH));
#endif
#endif
    MaxApplZone();
    MaxApplZone();
    for (i = 0; i < 4; i++) {
    for (i = 0; i < 4; i++) {
        (void) MoreMasters();
        (void) MoreMasters();
    }
    }
 
 
    /*
    /*
     * Tk needs us to set the qd pointer it uses.  This is needed
     * Tk needs us to set the qd pointer it uses.  This is needed
     * so Tk doesn't have to assume the availablity of the qd global
     * so Tk doesn't have to assume the availablity of the qd global
     * variable.  Which in turn allows Tk to be used in code resources.
     * variable.  Which in turn allows Tk to be used in code resources.
     */
     */
    tcl_macQdPtr = &qd;
    tcl_macQdPtr = &qd;
 
 
    /*
    /*
     * If appearance is present, then register Tk as an Appearance client
     * If appearance is present, then register Tk as an Appearance client
     * This means that the mapping from non-Appearance to Appearance cdefs
     * This means that the mapping from non-Appearance to Appearance cdefs
     * will be done for Tk regardless of the setting in the Appearance
     * will be done for Tk regardless of the setting in the Appearance
     * control panel.
     * control panel.
     */
     */
 
 
     if (TkMacHaveAppearance()) {
     if (TkMacHaveAppearance()) {
         RegisterAppearanceClient();
         RegisterAppearanceClient();
     }
     }
 
 
    InitGraf(&tcl_macQdPtr->thePort);
    InitGraf(&tcl_macQdPtr->thePort);
    InitFonts();
    InitFonts();
    InitWindows();
    InitWindows();
    InitMenus();
    InitMenus();
    InitDialogs((long) NULL);
    InitDialogs((long) NULL);
    InitCursor();
    InitCursor();
 
 
    /*
    /*
     * Make sure we are running on system 7 or higher
     * Make sure we are running on system 7 or higher
     */
     */
 
 
    if ((NGetTrapAddress(_Gestalt, ToolTrap) ==
    if ((NGetTrapAddress(_Gestalt, ToolTrap) ==
            NGetTrapAddress(_Unimplemented, ToolTrap))
            NGetTrapAddress(_Unimplemented, ToolTrap))
            || (((Gestalt(gestaltSystemVersion, &result) != noErr)
            || (((Gestalt(gestaltSystemVersion, &result) != noErr)
            || (result < mask)))) {
            || (result < mask)))) {
        panic("Tcl/Tk requires System 7 or higher.");
        panic("Tcl/Tk requires System 7 or higher.");
    }
    }
 
 
    /*
    /*
     * Make sure we have color quick draw
     * Make sure we have color quick draw
     * (this means we can't run on 68000 macs)
     * (this means we can't run on 68000 macs)
     */
     */
 
 
    if (((Gestalt(gestaltQuickdrawVersion, &result) != noErr)
    if (((Gestalt(gestaltQuickdrawVersion, &result) != noErr)
            || (result < gestalt32BitQD13))) {
            || (result < gestalt32BitQD13))) {
        panic("Tk requires Color QuickDraw.");
        panic("Tk requires Color QuickDraw.");
    }
    }
 
 
 
 
    FlushEvents(everyEvent, 0);
    FlushEvents(everyEvent, 0);
    SetEventMask(everyEvent);
    SetEventMask(everyEvent);
 
 
 
 
    Tcl_MacSetEventProc(TkMacConvertEvent);
    Tcl_MacSetEventProc(TkMacConvertEvent);
    TkConsoleCreate();
    TkConsoleCreate();
 
 
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * SetupMainInterp --
 * SetupMainInterp --
 *
 *
 *      This procedure calls initalization routines require a Tcl
 *      This procedure calls initalization routines require a Tcl
 *      interp as an argument.  This call effectively makes the passed
 *      interp as an argument.  This call effectively makes the passed
 *      iterpreter the "main" interpreter for the application.
 *      iterpreter the "main" interpreter for the application.
 *
 *
 * Results:
 * Results:
 *      Returns TCL_OK if everything went fine.  If it didn't the
 *      Returns TCL_OK if everything went fine.  If it didn't the
 *      application should probably fail.
 *      application should probably fail.
 *
 *
 * Side effects:
 * Side effects:
 *      More initilization.
 *      More initilization.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static int
static int
SetupMainInterp(
SetupMainInterp(
    Tcl_Interp *interp)
    Tcl_Interp *interp)
{
{
    /*
    /*
     * Initialize the console only if we are running as an interactive
     * Initialize the console only if we are running as an interactive
     * application.
     * application.
     */
     */
 
 
    TkMacInitAppleEvents(interp);
    TkMacInitAppleEvents(interp);
    TkMacInitMenus(interp);
    TkMacInitMenus(interp);
 
 
    if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
    if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
            == 0) {
            == 0) {
        if (TkConsoleInit(interp) == TCL_ERROR) {
        if (TkConsoleInit(interp) == TCL_ERROR) {
            goto error;
            goto error;
        }
        }
    }
    }
 
 
    /*
    /*
     * Attach the global interpreter to tk's expected global console
     * Attach the global interpreter to tk's expected global console
     */
     */
 
 
    gStdoutInterp = interp;
    gStdoutInterp = interp;
 
 
    return TCL_OK;
    return TCL_OK;
 
 
error:
error:
    panic(interp->result);
    panic(interp->result);
    return TCL_ERROR;
    return TCL_ERROR;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * InstallConsole, RemoveConsole, etc. --
 * InstallConsole, RemoveConsole, etc. --
 *
 *
 *      The following functions provide the UI for the console package.
 *      The following functions provide the UI for the console package.
 *      Users wishing to replace SIOUX with their own console package
 *      Users wishing to replace SIOUX with their own console package
 *      need only provide the four functions below in a library.
 *      need only provide the four functions below in a library.
 *
 *
 * Results:
 * Results:
 *      See SIOUX documentation for details.
 *      See SIOUX documentation for details.
 *
 *
 * Side effects:
 * Side effects:
 *      See SIOUX documentation for details.
 *      See SIOUX documentation for details.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
short
short
InstallConsole(short fd)
InstallConsole(short fd)
{
{
#pragma unused (fd)
#pragma unused (fd)
 
 
        return 0;
        return 0;
}
}
 
 
void
void
RemoveConsole(void)
RemoveConsole(void)
{
{
}
}
 
 
long
long
WriteCharsToConsole(char *buffer, long n)
WriteCharsToConsole(char *buffer, long n)
{
{
    TkConsolePrint(gStdoutInterp, TCL_STDOUT, buffer, n);
    TkConsolePrint(gStdoutInterp, TCL_STDOUT, buffer, n);
    return n;
    return n;
}
}
 
 
long
long
ReadCharsFromConsole(char *buffer, long n)
ReadCharsFromConsole(char *buffer, long n)
{
{
    return 0;
    return 0;
}
}
 
 
extern char *
extern char *
__ttyname(long fildes)
__ttyname(long fildes)
{
{
    static char *__devicename = "null device";
    static char *__devicename = "null device";
 
 
    if (fildes >= 0 && fildes <= 2) {
    if (fildes >= 0 && fildes <= 2) {
        return (__devicename);
        return (__devicename);
    }
    }
 
 
    return (0L);
    return (0L);
}
}
 
 
short
short
SIOUXHandleOneEvent(EventRecord *event)
SIOUXHandleOneEvent(EventRecord *event)
{
{
    return 0;
    return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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