home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activetcltk / ActiveTcl8.3.4.1-8.win32-ix86.exe / ActiveTcl8.3.4.1-win32-ix86 / lib / tk8.3 / tkAppInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-22  |  4.2 KB  |  151 lines

  1. /* 
  2.  * tkAppInit.c --
  3.  *
  4.  *    Provides a default version of the Tcl_AppInit procedure for
  5.  *    use in wish and similar Tk-based applications.
  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 "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  *
  13.  * RCS: @(#) $Id: tkAppInit.c,v 1.5 1999/12/02 02:05:39 redman Exp $
  14.  */
  15.  
  16. #include "tk.h"
  17. #include "locale.h"
  18.  
  19. /*
  20.  * The following variable is a special hack that is needed in order for
  21.  * Sun shared libraries to be used for Tcl.
  22.  */
  23.  
  24. extern int matherr();
  25. int *tclDummyMathPtr = (int *) matherr;
  26.  
  27. #ifdef TK_TEST
  28. extern int        Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  29. extern int        Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  30. #endif /* TK_TEST */
  31.  
  32. /*
  33.  *----------------------------------------------------------------------
  34.  *
  35.  * main --
  36.  *
  37.  *    This is the main program for the application.
  38.  *
  39.  * Results:
  40.  *    None: Tk_Main never returns here, so this procedure never
  41.  *    returns either.
  42.  *
  43.  * Side effects:
  44.  *    Whatever the application does.
  45.  *
  46.  *----------------------------------------------------------------------
  47.  */
  48.  
  49. int
  50. main(argc, argv)
  51.     int argc;            /* Number of command-line arguments. */
  52.     char **argv;        /* Values of command-line arguments. */
  53. {
  54.     /*
  55.      * The following #if block allows you to change the AppInit
  56.      * function by using a #define of TCL_LOCAL_APPINIT instead
  57.      * of rewriting this entire file.  The #if checks for that
  58.      * #define and uses Tcl_AppInit if it doesn't exist.
  59.      */
  60.     
  61. #ifndef TK_LOCAL_APPINIT
  62. #define TK_LOCAL_APPINIT Tcl_AppInit    
  63. #endif
  64.     extern int TK_LOCAL_APPINIT _ANSI_ARGS_((Tcl_Interp *interp));
  65.     
  66.     /*
  67.      * The following #if block allows you to change how Tcl finds the startup
  68.      * script, prime the library or encoding paths, fiddle with the argv,
  69.      * etc., without needing to rewrite Tk_Main()
  70.      */
  71.     
  72. #ifdef TK_LOCAL_MAIN_HOOK
  73.     extern int TK_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv));
  74.     TK_LOCAL_MAIN_HOOK(&argc, &argv);
  75. #endif
  76.  
  77.     Tk_Main(argc, argv, TK_LOCAL_APPINIT);
  78.     return 0;            /* Needed only to prevent compiler warning. */
  79. }
  80.  
  81. /*
  82.  *----------------------------------------------------------------------
  83.  *
  84.  * Tcl_AppInit --
  85.  *
  86.  *    This procedure performs application-specific initialization.
  87.  *    Most applications, especially those that incorporate additional
  88.  *    packages, will have their own version of this procedure.
  89.  *
  90.  * Results:
  91.  *    Returns a standard Tcl completion code, and leaves an error
  92.  *    message in the interp's result if an error occurs.
  93.  *
  94.  * Side effects:
  95.  *    Depends on the startup script.
  96.  *
  97.  *----------------------------------------------------------------------
  98.  */
  99.  
  100. int
  101. Tcl_AppInit(interp)
  102.     Tcl_Interp *interp;        /* Interpreter for application. */
  103. {
  104.     if (Tcl_Init(interp) == TCL_ERROR) {
  105.     return TCL_ERROR;
  106.     }
  107.     if (Tk_Init(interp) == TCL_ERROR) {
  108.     return TCL_ERROR;
  109.     }
  110.     Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
  111. #ifdef TK_TEST
  112.     if (Tcltest_Init(interp) == TCL_ERROR) {
  113.     return TCL_ERROR;
  114.     }
  115.     Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
  116.             (Tcl_PackageInitProc *) NULL);
  117.     if (Tktest_Init(interp) == TCL_ERROR) {
  118.     return TCL_ERROR;
  119.     }
  120.     Tcl_StaticPackage(interp, "Tktest", Tktest_Init,
  121.             (Tcl_PackageInitProc *) NULL);
  122. #endif /* TK_TEST */
  123.  
  124.  
  125.     /*
  126.      * Call the init procedures for included packages.  Each call should
  127.      * look like this:
  128.      *
  129.      * if (Mod_Init(interp) == TCL_ERROR) {
  130.      *     return TCL_ERROR;
  131.      * }
  132.      *
  133.      * where "Mod" is the name of the module.
  134.      */
  135.  
  136.     /*
  137.      * Call Tcl_CreateCommand for application-specific commands, if
  138.      * they weren't already created by the init procedures called above.
  139.      */
  140.  
  141.     /*
  142.      * Specify a user-specific startup file to invoke if the application
  143.      * is run interactively.  Typically the startup file is "~/.apprc"
  144.      * where "app" is the name of the application.  If this line is deleted
  145.      * then no user-specific startup file will be run under any conditions.
  146.      */
  147.  
  148.     Tcl_SetVar(interp, "tcl_rcFileName", "~/.wishrc", TCL_GLOBAL_ONLY);
  149.     return TCL_OK;
  150. }
  151.