tclAppInit.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.9 $
00022 // $Date: 2006/09/26 21:29:35 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/tcl/tclAppInit.cpp,v $
00024 
00025 
00026 /* 
00027  * tclAppInit.c --
00028  *
00029  *      Provides a default version of the main program and Tcl_AppInit
00030  *      procedure for Tcl applications (without Tk).
00031  *
00032  * Copyright (c) 1993 The Regents of the University of California.
00033  * Copyright (c) 1994-1997 Sun Microsystems, Inc.
00034  * Copyright (c) 1998-1999 by Scriptics Corporation.
00035  *
00036  * See the file "license.terms" for information on usage and redistribution
00037  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00038  *
00039  * RCS: @(#) $Id: tclAppInit.cpp,v 1.9 2006/09/26 21:29:35 fmk Exp $
00040  */
00041 
00042 extern "C" {
00043 #include <tcl.h>
00044 //#include <tk.h>
00045 }
00046 
00047 #include "commands.h"
00048 
00049 /*
00050  * The following variable is a special hack that is needed in order for
00051  * Sun shared libraries to be used for Tcl.
00052  */
00053 
00054 #ifdef _UNIX
00055 //extern "C" int matherr();
00056 //int *tclDummyMathPtr = (int *) matherr;
00057 #endif
00058 
00059 
00060 #ifdef TCL_TEST
00061 
00062 extern "C" {
00063 #include "tclInt.h"
00064 }
00065 
00066 extern int              Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00067 extern int              Procbodytest_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));
00068 extern int              TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00069 extern int              Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00070 #ifdef TCL_THREADS
00071 extern int              TclThread_Init _ANSI_ARGS_((Tcl_Interp *interp));
00072 #endif
00073 
00074 #endif /* TCL_TEST */
00075 
00076 #ifdef TCL_XT_TEST
00077 extern void             XtToolkitInitialize _ANSI_ARGS_((void));
00078 extern int              Tclxttest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00079 #endif
00080 
00081 
00082 
00083 #include <FileStream.h>
00084 #include <SimulationInformation.h>
00085 extern SimulationInformation simulationInfo;
00086 extern char *simulationInfoOutputFilename;
00087 
00088 
00089 
00090 
00091 /*
00092  *----------------------------------------------------------------------
00093  *
00094  * main --
00095  *
00096  *      This is the main program for the application.
00097  *
00098  * Results:
00099  *      None: Tcl_Main never returns here, so this procedure never
00100  *      returns either.
00101  *
00102  * Side effects:
00103  *      Whatever the application does.
00104  *
00105  *----------------------------------------------------------------------
00106  */
00107 
00108 extern void g3TclMain(int argc, char **argv, Tcl_AppInitProc *appInitProc, int rank, int np);
00109 
00110 int
00111 main(int argc, char **argv)
00112 {
00113     /*
00114      * The following #if block allows you to change the AppInit
00115      * function by using a #define of TCL_LOCAL_APPINIT instead
00116      * of rewriting this entire file.  The #if checks for that
00117      * #define and uses Tcl_AppInit if it doesn't exist.
00118      */
00119 
00120 #ifndef TCL_LOCAL_APPINIT
00121 #define TCL_LOCAL_APPINIT Tcl_AppInit    
00122 #endif
00123 
00124   /* fmk - comment out the following block to get to compile 
00125     extern "C" int TCL_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp));
00126   fmk - end commented block */
00127 
00128     /*
00129      * The following #if block allows you to change how Tcl finds the startup
00130      * script, prime the library or encoding paths, fiddle with the argv,
00131      * etc., without needing to rewrite Tcl_Main()
00132      */
00133 
00134 #ifdef TCL_LOCAL_MAIN_HOOK
00135     extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv));
00136 #endif
00137 
00138 #ifdef TCL_XT_TEST
00139     XtToolkitInitialize();
00140 #endif
00141 
00142 #ifdef TCL_LOCAL_MAIN_HOOK
00143     TCL_LOCAL_MAIN_HOOK(&argc, &argv);
00144 #endif
00145 
00146     g3TclMain(argc, argv, TCL_LOCAL_APPINIT, 0, 1);
00147 
00148     return 0;                   /* Needed only to prevent compiler warning. */
00149 }
00150 
00151 /*
00152  *----------------------------------------------------------------------
00153  *
00154  * Tcl_AppInit --
00155  *
00156  *      This procedure performs application-specific initialization.
00157  *      Most applications, especially those that incorporate additional
00158  *      packages, will have their own version of this procedure.
00159  *
00160  * Results:
00161  *      Returns a standard Tcl completion code, and leaves an error
00162  *      message in the interp's result if an error occurs.
00163  *
00164  * Side effects:
00165  *      Depends on the startup script.
00166  *
00167  *----------------------------------------------------------------------
00168  */
00169 
00170 
00171 
00172 int Tcl_AppInit(Tcl_Interp *interp)
00173 {
00174     if (Tcl_Init(interp) == TCL_ERROR) {
00175         return TCL_ERROR;
00176     }
00177 
00178 #ifdef TCL_TEST
00179 #ifdef TCL_XT_TEST
00180      if (Tclxttest_Init(interp) == TCL_ERROR) {
00181          return TCL_ERROR;
00182      }
00183 #endif
00184     if (Tcltest_Init(interp) == TCL_ERROR) {
00185         return TCL_ERROR;
00186     }
00187     Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
00188             (Tcl_PackageInitProc *) NULL);
00189     if (TclObjTest_Init(interp) == TCL_ERROR) {
00190         return TCL_ERROR;
00191     }
00192 #ifdef TCL_THREADS
00193     if (TclThread_Init(interp) == TCL_ERROR) {
00194         return TCL_ERROR;
00195     }
00196 #endif
00197     if (Procbodytest_Init(interp) == TCL_ERROR) {
00198         return TCL_ERROR;
00199     }
00200     Tcl_StaticPackage(interp, "procbodytest", Procbodytest_Init,
00201             Procbodytest_SafeInit);
00202 #endif /* TCL_TEST */
00203 
00204     /*
00205      * Call the init procedures for included packages.  Each call should
00206      * look like this:
00207      *
00208      * if (Mod_Init(interp) == TCL_ERROR) {
00209      *     return TCL_ERROR;
00210      * }
00211      *
00212      * where "Mod" is the name of the module.
00213      */
00214 
00215     /*
00216      * Call Tcl_CreateCommand for application-specific commands, if
00217      * they weren't already created by the init procedures called above.
00218      */
00219 
00220     if (g3AppInit(interp) < 0)
00221         return TCL_ERROR;
00222 
00223     /*
00224      * Specify a user-specific startup file to invoke if the application
00225      * is run interactively.  Typically the startup file is "~/.apprc"
00226      * where "app" is the name of the application.  If this line is deleted
00227      * then no user-specific startup file will be run under any conditions.
00228      */
00229 
00230     Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
00231     return TCL_OK;
00232 }
00233 
00234 
00235 
00236 int OpenSeesExit(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
00237 {
00238         
00239   if (simulationInfoOutputFilename != 0) {
00240     simulationInfo.end();
00241     FileStream simulationInfoOutputFile;
00242     simulationInfoOutputFile.setFile(simulationInfoOutputFilename);
00243     simulationInfoOutputFile.open();
00244     simulationInfoOutputFile << simulationInfo;
00245     simulationInfoOutputFile.close();
00246   }
00247 
00248   Tcl_Exit(0);
00249   return 0;
00250 }
00251 

Generated on Mon Oct 23 15:05:30 2006 for OpenSees by doxygen 1.5.0