Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

tclAppInit.cc

Go to the documentation of this file.
00001 /* 
00002  * tclAppInit.c --
00003  *
00004  *      Provides a default version of the main program and Tcl_AppInit
00005  *      procedure for Tcl applications (without Tk).
00006  *
00007  * Copyright (C) 2000 USC/ISI
00008  * Copyright (c) 1993 The Regents of the University of California.
00009  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
00010  *
00011  * See the file "license.terms" for information on usage and redistribution
00012  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00013  *
00014  * SCCS: @(#) tclAppInit.c 1.17 96/03/26 12:45:29
00015  */
00016 
00017 #include "config.h"
00018 
00019 extern void init_misc(void);
00020 extern EmbeddedTcl et_ns_lib;
00021 extern EmbeddedTcl et_ns_ptypes;
00022 
00023 /* MSVC requires this global var declaration to be outside of 'extern "C"' */
00024 #ifdef MEMDEBUG_SIMULATIONS
00025 #include "mem-trace.h"
00026 MemTrace *globalMemTrace;
00027 #endif
00028 
00029 extern "C" {
00030 
00031 /*
00032  * The following variable is a special hack that is needed in order for
00033  * Sun shared libraries to be used for Tcl.
00034  */
00035 
00036 #ifdef TCL_TEST
00037 EXTERN int              Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00038 #endif /* TCL_TEST */
00039 
00040 /*
00041  *----------------------------------------------------------------------
00042  *
00043  * main --
00044  *
00045  *      This is the main program for the application.
00046  *
00047  * Results:
00048  *      None: Tcl_Main never returns here, so this procedure never
00049  *      returns either.
00050  *
00051  * Side effects:
00052  *      Whatever the application does.
00053  *
00054  *----------------------------------------------------------------------
00055  */
00056 
00057 int
00058 main(int argc, char **argv)
00059 {
00060     Tcl_Main(argc, argv, Tcl_AppInit);
00061     return 0;                   /* Needed only to prevent compiler warning. */
00062 }
00063 
00064 
00065 #if defined(linux) && defined(i386) && (defined(HAVE_FESETPRECISION) || defined(__GNUC__))
00066 #ifndef HAVE_FESETPRECISION
00067 /*
00068  * From:
00069  |  Floating-point environment <fenvwm.h>                                    |
00070  | Copyright (C) 1996, 1997, 1998, 1999                                      |
00071  |                     W. Metzenthen, 22 Parker St, Ormond, Vic 3163,        |
00072  |                     Australia.                                            |
00073  |                     E-mail   billm@melbpc.org.au                          |
00074  * used here with permission.
00075  */
00076 #define FE_FLTPREC       0x000
00077 #define FE_INVALIDPREC   0x100
00078 #define FE_DBLPREC       0x200
00079 #define FE_LDBLPREC      0x300
00080 /*
00081  * From:
00082  * fenvwm.c
00083  | Copyright (C) 1999                                                        |
00084  |                     W. Metzenthen, 22 Parker St, Ormond, Vic 3163,        |
00085  |                     Australia.  E-mail   billm@melbpc.org.au              |
00086  * used here with permission.
00087  */
00088 /*
00089   Set the precision to prec if it is a valid
00090   floating point precision macro.
00091   Returns 1 if precision set, 0 otherwise.
00092   */
00093 static inline int fesetprecision(int prec)
00094 {
00095   if ( !(prec & ~FE_LDBLPREC) && (prec != FE_INVALIDPREC) )
00096     {
00097       unsigned short cw;
00098       asm ("fnstcw %0":"=m" (cw));
00099       cw = (cw & ~FE_LDBLPREC) | (prec & FE_LDBLPREC);
00100       asm volatile ("fldcw %0" : /* Don't push these colons together */ : "m" (cw));
00101       return 1;
00102     }
00103   else
00104     return 0;
00105 }
00106 #endif /* !HAVE_FESETPRECISION */
00107 
00108 /*
00109  * Linux i386 uses 60-bit floats for calculation,
00110  * not 56-bit floats, giving different results.
00111  * Fix that.
00112  *
00113  * See <http://www.linuxsupportline.com/~billm/faq.html>
00114  * for why we do this fix.
00115  *
00116  * This function is derived from wmexcep
00117  *
00118  */
00119 static inline void
00120 fix_i386_linux_floats()
00121 {
00122         fesetprecision(FE_DBLPREC);
00123 }
00124 #else
00125 static inline void
00126 fix_i386_linux_floats()
00127 {}
00128 #endif
00129 
00130 
00131 /*
00132  *----------------------------------------------------------------------
00133  *
00134  * Tcl_AppInit --
00135  *
00136  *      This procedure performs application-specific initialization.
00137  *      Most applications, especially those that incorporate additional
00138  *      packages, will have their own version of this procedure.
00139  *
00140  * Results:
00141  *      Returns a standard Tcl completion code, and leaves an error
00142  *      message in interp->result if an error occurs.
00143  *
00144  * Side effects:
00145  *      Depends on the startup script.
00146  *
00147  *----------------------------------------------------------------------
00148  */
00149 
00150 int
00151 Tcl_AppInit(Tcl_Interp *interp)
00152 {
00153 #ifdef MEMDEBUG_SIMULATIONS
00154         extern MemTrace *globalMemTrace;
00155         globalMemTrace = new MemTrace;
00156 #endif
00157 
00158         fix_i386_linux_floats();
00159        
00160         if (Tcl_Init(interp) == TCL_ERROR ||
00161             Otcl_Init(interp) == TCL_ERROR)
00162                 return TCL_ERROR;
00163 
00164 #ifdef HAVE_LIBTCLDBG
00165         extern int Tcldbg_Init(Tcl_Interp *);   // hackorama
00166         if (Tcldbg_Init(interp) == TCL_ERROR) {
00167                 return TCL_ERROR;
00168         }
00169 #endif
00170 
00171         Tcl_SetVar(interp, "tcl_rcFileName", "~/.ns.tcl", TCL_GLOBAL_ONLY);
00172         Tcl::init(interp, "ns");
00173         init_misc();
00174         et_ns_ptypes.load();
00175         et_ns_lib.load();
00176 
00177 
00178 #ifdef TCL_TEST
00179         if (Tcltest_Init(interp) == TCL_ERROR) {
00180                 return TCL_ERROR;
00181         }
00182         Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
00183                           (Tcl_PackageInitProc *) NULL);
00184 #endif /* TCL_TEST */
00185 
00186         return TCL_OK;
00187 }
00188 
00189 #ifndef WIN32
00190 void
00191 abort()
00192 {
00193         Tcl& tcl = Tcl::instance();
00194         tcl.evalc("[Simulator instance] flush-trace");
00195 #ifdef abort
00196 #undef abort
00197         abort();
00198 #else
00199         exit(1);
00200 #endif /*abort*/
00201         /*NOTREACHED*/
00202 }
00203 #endif
00204 
00205 }
00206 
00207 

Generated on Tue Apr 20 12:14:34 2004 for NS2.26SourcesOriginal by doxygen 1.3.3