tkAppInit.cc

Go to the documentation of this file.
00001 /* 
00002  * tkAppInit.c --
00003  *
00004  *  Provides a default version of the Tcl_AppInit procedure for
00005  *  use in wish and similar Tk-based applications.
00006  *
00007  * Copyright (c) 1993 The Regents of the University of California.
00008  * Copyright (c) 1994 Sun Microsystems, Inc.
00009  *
00010  * See the file "license.terms" for information on usage and redistribution
00011  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00012  *
00013  * SCCS: @(#) tkAppInit.c 1.21 96/03/26 16:47:07
00014  */
00015 
00016 #include <tk.h>
00017 #include "config.h"
00018 
00019 extern init_misc();
00020 
00021 extern "C" {
00022 
00023 #ifdef TK_TEST
00024 EXTERN int      Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
00025 #endif /* TK_TEST */
00026 
00027 /*
00028  *----------------------------------------------------------------------
00029  *
00030  * main --
00031  *
00032  *  This is the main program for the application.
00033  *
00034  * Results:
00035  *  None: Tk_Main never returns here, so this procedure never
00036  *  returns either.
00037  *
00038  * Side effects:
00039  *  Whatever the application does.
00040  *
00041  *----------------------------------------------------------------------
00042  */
00043 
00044 int
00045 main(int argc, char** argv)
00046 {
00047     Tk_Main(argc, argv, Tcl_AppInit);
00048     return 0;           /* Needed only to prevent compiler warning. */
00049 }
00050 
00051 
00052 #include "bitmap/play.xbm"
00053 #include "bitmap/stop.xbm"
00054 #include "bitmap/rewind.xbm"
00055 #include "bitmap/ff.xbm"
00056 
00057 void loadbitmaps(Tcl_Interp* tcl)
00058 {
00059     Tk_DefineBitmap(tcl, Tk_GetUid("play"),
00060             play_bits, play_width, play_height);
00061     Tk_DefineBitmap(tcl, Tk_GetUid("stop"),
00062             stop_bits, stop_width, stop_height);
00063 
00064     Tk_DefineBitmap(tcl, Tk_GetUid("rewind"),
00065             rewind_bits, rewind_width, rewind_height);
00066     Tk_DefineBitmap(tcl, Tk_GetUid("ff"),
00067             ff_bits, ff_width, ff_height);
00068 }
00069 
00070 
00071 
00072 /*
00073  *----------------------------------------------------------------------
00074  *
00075  * Tcl_AppInit --
00076  *
00077  *  This procedure performs application-specific initialization.
00078  *  Most applications, especially those that incorporate additional
00079  *  packages, will have their own version of this procedure.
00080  *
00081  * Results:
00082  *  Returns a standard Tcl completion code, and leaves an error
00083  *  message in interp->result if an error occurs.
00084  *
00085  * Side effects:
00086  *  Depends on the startup script.
00087  *
00088  *----------------------------------------------------------------------
00089  */
00090 
00091 int
00092 Tcl_AppInit(Tcl_Interp *interp)
00093 {
00094     if (Tcl_Init(interp) == TCL_ERROR) {
00095     return TCL_ERROR;
00096     }
00097     if (Otcl_Init(interp) == TCL_ERROR) {
00098     return TCL_ERROR;
00099     }
00100     if (Tk_Init(interp) == TCL_ERROR) {
00101     return TCL_ERROR;
00102     }
00103 
00104     Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
00105 #ifdef TK_TEST
00106     if (Tktest_Init(interp) == TCL_ERROR) {
00107     return TCL_ERROR;
00108     }
00109     Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
00110             (Tcl_PackageInitProc *) NULL);
00111 #endif /* TK_TEST */
00112 
00113 
00114     /*
00115      * Call the init procedures for included packages.  Each call should
00116      * look like this:
00117      *
00118      * if (Mod_Init(interp) == TCL_ERROR) {
00119      *     return TCL_ERROR;
00120      * }
00121      *
00122      * where "Mod" is the name of the module.
00123      */
00124 #ifdef HAVE_LIBTCLDBG
00125     if (Dbg_Init(interp) == TCL_ERROR) {
00126     return TCL_ERROR;
00127     }
00128 #endif
00129 
00130     Tcl::init(interp, "ns");
00131     Tcl::instance().tkmain(Tk_MainWindow(interp));
00132     extern EmbeddedTcl et_ns_lib, et_tk;
00133     et_tk.load();
00134     et_ns_lib.load();
00135     init_misc();
00136     loadbitmaps(interp);
00137 
00138 
00139     /*
00140      * Call Tcl_CreateCommand for application-specific commands, if
00141      * they weren't already created by the init procedures called above.
00142      */
00143 
00144     /*
00145      * Specify a user-specific startup file to invoke if the application
00146      * is run interactively.  Typically the startup file is "~/.apprc"
00147      * where "app" is the name of the application.  If this line is deleted
00148      * then no user-specific startup file will be run under any conditions.
00149      */
00150 
00151     Tcl_SetVar(interp, "tcl_rcFileName", "~/.ns.tcl", TCL_GLOBAL_ONLY);
00152 
00153     return TCL_OK;
00154 }
00155 
00156 abort()
00157 {
00158     Tcl& tcl = Tcl::instance();
00159     tcl.evalc("[Simulator instance] flush-trace");
00160 #ifdef abort
00161 #undef abort
00162     abort();
00163 #else
00164     exit(1);
00165 #endif /*abort*/
00166     /*NOTREACHED*/
00167 }
00168 
00169 }

Generated on Tue Mar 6 16:47:52 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6