1/* 2 * tclXinit.c -- 3 * 4 * Extended Tcl initialzation and initialization utilitied. 5 *----------------------------------------------------------------------------- 6 * Copyright 1991-1999 Karl Lehenbauer and Mark Diekhans. 7 * 8 * Permission to use, copy, modify, and distribute this software and its 9 * documentation for any purpose and without fee is hereby granted, provided 10 * that the above copyright notice appear in all copies. Karl Lehenbauer and 11 * Mark Diekhans make no representations about the suitability of this 12 * software for any purpose. It is provided "as is" without express or 13 * implied warranty. 14 *----------------------------------------------------------------------------- 15 * $Id: tclXinit.c,v 1.4 2005/03/24 05:11:15 hobbs Exp $ 16 *----------------------------------------------------------------------------- 17 */ 18 19#include "tclExtdInt.h" 20 21/* 22 * Tcl procedure to search for an init for TclX startup file. 23 */ 24 25static char initScript[] = "if {[info proc ::tclx::Init]==\"\"} {\n\ 26 namespace eval ::tclx {}\n\ 27 proc ::tclx::Init {} {\n" 28#ifdef MAC_TCL 29" source -rsrc tclx.tcl\n" 30#else 31" global tclx_library\n\ 32 tcl_findLibrary tclx " PACKAGE_VERSION " " FULL_VERSION " tclx.tcl TCLX_LIBRARY tclx_library\n" 33#endif 34" }\n\ 35}\n\ 36::tclx::Init"; 37 38/* 39 * Prototypes of internal functions. 40 */ 41static int Tclxcmd_Init _ANSI_ARGS_((Tcl_Interp *interp)); 42 43 44/*----------------------------------------------------------------------------- 45 * Tclx_Init -- 46 * 47 * Initialize all Extended Tcl commands, set auto_path and source the 48 * Tcl init file. 49 *----------------------------------------------------------------------------- 50 */ 51int 52Tclx_Init (interp) 53 Tcl_Interp *interp; 54{ 55 if (Tclx_SafeInit(interp) != TCL_OK) { 56 return TCL_ERROR; 57 } 58 59 if ((Tcl_EvalEx(interp, initScript, -1, 60 TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT) != TCL_OK) 61 || (TclX_LibraryInit(interp) != TCL_OK)) { 62 Tcl_AddErrorInfo(interp, "\n (in TclX_Init)"); 63 return TCL_ERROR; 64 } 65 66 return TCL_OK; 67} 68 69 70/*----------------------------------------------------------------------------- 71 * Tclx_SafeInit -- 72 * 73 * Initialize safe Extended Tcl commands. 74 *----------------------------------------------------------------------------- 75 */ 76int 77Tclx_SafeInit (interp) 78 Tcl_Interp *interp; 79{ 80 if ( 81#ifdef USE_TCL_STUBS 82 (Tcl_InitStubs(interp, "8.0", 0) == NULL) 83#else 84 (Tcl_PkgRequire(interp, "Tcl", "8.0", 0) == NULL) 85#endif 86 || (Tclxcmd_Init(interp) != TCL_OK) 87 || (Tcl_PkgProvide(interp, "Tclx", PACKAGE_VERSION) != TCL_OK) 88 ) { 89 Tcl_AddErrorInfo (interp, "\n (in TclX_SafeInit)"); 90 return TCL_ERROR; 91 } 92 93 return TCL_OK; 94} 95 96/*----------------------------------------------------------------------------- 97 * Tclxcmd_Init -- 98 * 99 * Add the Extended Tcl commands to the specified interpreter (except for 100 * the library commands that override that standard Tcl procedures). This 101 * does no other startup. 102 *----------------------------------------------------------------------------- 103 */ 104static int 105Tclxcmd_Init (interp) 106 Tcl_Interp *interp; 107{ 108 /* 109 * These are ok in safe interps. 110 */ 111 TclX_SetAppInfo(TRUE, "TclX", "Extended Tcl", 112 PACKAGE_VERSION, TCLX_PATCHLEVEL); 113 114 TclX_BsearchInit (interp); 115 TclX_FstatInit (interp); 116 TclX_FlockInit (interp); 117 TclX_FilescanInit (interp); 118 TclX_GeneralInit (interp); 119 TclX_IdInit (interp); 120 TclX_KeyedListInit (interp); 121 TclX_LgetsInit (interp); 122 TclX_ListInit (interp); 123 TclX_MathInit (interp); 124 TclX_ProfileInit (interp); 125 TclX_SelectInit (interp); 126 TclX_StringInit (interp); 127 128 if (!Tcl_IsSafe(interp)) { 129 /* 130 * Add these only in trusted interps. 131 */ 132 TclX_ChmodInit (interp); 133 TclX_CmdloopInit (interp); 134 TclX_DebugInit (interp); 135 TclX_DupInit (interp); 136 TclX_FcntlInit (interp); 137 TclX_FilecmdsInit (interp); 138 TclX_FstatInit (interp); 139 TclX_MsgCatInit (interp); 140 TclX_ProcessInit (interp); 141 TclX_SignalInit (interp); 142 TclX_OsCmdsInit (interp); 143 TclX_PlatformCmdsInit (interp); 144 TclX_SocketInit (interp); 145 TclX_ServerInit (interp); 146 } 147 148 return TCL_OK; 149} 150