1/* 2 * tclAppInit.c -- 3 * 4 * Provides a default version of the main program and Tcl_AppInit 5 * procedure for Tcl applications (without Tk). 6 * 7 * Copyright (c) 1993 The Regents of the University of California. 8 * Copyright (c) 1994-1997 Sun Microsystems, Inc. 9 * 10 * See the file "tcl-license.terms" for information on usage and redistribution 11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 12 * 13 * SCCS: @(#) tclAppInit.c 1.20 97/03/24 14:29:43 14 */ 15 16/* include tclInt.h for access to namespace API */ 17#include "tclInt.h" 18 19#include "xotcl.h" 20 21#if defined(VISUAL_CC) 22# include <windows.h> 23# include <locale.h> 24#endif 25#include <stdio.h> 26 27#if TCL_MAJOR_VERSION < 7 28 #error Tcl distribution TOO OLD 29#endif 30 31/* 32 * The following variable is a special hack that is needed in order for 33 * Sun shared libraries to be used for Tcl. 34 */ 35 36#ifdef NEED_MATHERR 37extern int matherr(); 38int *tclDummyMathPtr = (int *) matherr; 39#endif 40 41/* 42 *---------------------------------------------------------------------- 43 * 44 * main -- 45 * 46 * This is the main program for the application. 47 * 48 * Results: 49 * None: Tcl_Main never returns here, so this procedure never 50 * returns either. 51 * 52 * Side effects: 53 * Whatever the application does. 54 * 55 *---------------------------------------------------------------------- 56 */ 57 58#if TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION < 4 59 60extern int main(); 61int *tclDummyMainPtr = (int *) main; 62 63#else 64 65int 66main(argc, argv) 67 int argc; /* Number of command-line arguments. */ 68 char **argv; /* Values of command-line arguments. */ 69{ 70#if defined(VISUAL_CC) 71 setlocale(LC_ALL, "C"); 72#endif 73 Tcl_Main(argc, argv, Tcl_AppInit); 74 return 0; /* Needed only to prevent compiler warning. */ 75} 76 77#endif 78 79 80/* 81 *---------------------------------------------------------------------- 82 * 83 * Tcl_AppInit -- 84 * 85 * This procedure performs application-specific initialization. 86 * Most applications, especially those that incorporate additional 87 * packages, will have their own version of this procedure. 88 * 89 * Results: 90 * Returns a standard Tcl completion code, and leaves an error 91 * message in interp->result if an error occurs. 92 * 93 * Side effects: 94 * Depends on the startup script. 95 * 96 *---------------------------------------------------------------------- 97 */ 98 99int 100Tcl_AppInit(interp) 101 Tcl_Interp *interp; /* Interpreter for application. */ 102{ 103 if (Tcl_Init(interp) == TCL_ERROR) { 104 return TCL_ERROR; 105 } 106 107 /* 108 * Call the init procedures for included packages. Each call should 109 * look like this: 110 * 111 * if (Mod_Init(interp) == TCL_ERROR) { 112 * return TCL_ERROR; 113 * } 114 * 115 * where "Mod" is the name of the module. 116 117 if (Xotcl_Init(interp) == TCL_ERROR) { 118 return TCL_ERROR; 119 } 120 121 Tcl_StaticPackage(interp, "XOTcl", Xotcl_Init, 0); 122 */ 123 124 if (Tcl_PkgRequire(interp, "XOTcl", XOTCLVERSION, 1) == NULL) { 125 return TCL_ERROR; 126 } 127 128 /* 129 * This is xotclsh, so import all xotcl commands by 130 * default into the global namespace. 131 */ 132 133 if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp), 134 "::xotcl::*", /* allowOverwrite */ 1) != TCL_OK) { 135 return TCL_ERROR; 136 } 137 /* 138 * Call Tcl_CreateCommand for application-specific commands, if 139 * they weren't already created by the init procedures called above. 140 */ 141 142 /* 143 * Specify a user-specific startup file to invoke if the application 144 * is run interactively. Typically the startup file is "~/.apprc" 145 * where "app" is the name of the application. If this line is deleted 146 * then no user-specific startup file will be run under any conditions. 147 */ 148 149 Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); 150 return TCL_OK; 151} 152