Home | History | Annotate | Download | only in tcl
      1 /* -----------------------------------------------------------------------------
      2  * wish.i
      3  *
      4  * SWIG File for making wish
      5  * ----------------------------------------------------------------------------- */
      6 
      7 #ifdef AUTODOC
      8 %subsection "wish.i"
      9 %text %{
     10 This module provides the Tk_AppInit() function needed to build a
     11 new version of the wish executable.   Like tclsh.i, this file should
     12 not be used with dynamic loading.  To make an interface file work with
     13 both static and dynamic loading, put something like this in your
     14 interface file :
     15 
     16      #ifdef STATIC
     17      %include <wish.i>
     18      #endif
     19 
     20 A startup file may be specified by defining the symbol SWIG_RcFileName
     21 as follows (this should be included in a code-block) :
     22 
     23      #define SWIG_RcFileName    "~/.mywishrc"
     24 %}
     25 #endif
     26 
     27 %{
     28 
     29 
     30 /* Initialization code for wish */
     31 
     32 #include <tk.h>
     33 
     34 #ifndef SWIG_RcFileName
     35 char *SWIG_RcFileName = "~/.wishrc";
     36 #endif
     37 
     38 #ifdef MAC_TCL
     39 extern int	MacintoshInit _ANSI_ARGS_((void));
     40 extern int	SetupMainInterp _ANSI_ARGS_((Tcl_Interp *interp));
     41 #endif
     42 
     43 /*
     44  *----------------------------------------------------------------------
     45  *
     46  * Tcl_AppInit --
     47  *
     48  *	This procedure performs application-specific initialization.
     49  *	Most applications, especially those that incorporate additional
     50  *	packages, will have their own version of this procedure.
     51  *
     52  * Results:
     53  *	Returns a standard Tcl completion code, and leaves an error
     54  *	message in interp->result if an error occurs.
     55  *
     56  * Side effects:
     57  *	Depends on the startup script.
     58  *
     59  *----------------------------------------------------------------------
     60  */
     61 
     62 int Tcl_AppInit(Tcl_Interp *interp)
     63 {
     64 #ifndef MAC_TCL
     65     Tk_Window main;
     66     main = Tk_MainWindow(interp);
     67 #endif
     68     /*
     69      * Call the init procedures for included packages.  Each call should
     70      * look like this:
     71      *
     72      * if (Mod_Init(interp) == TCL_ERROR) {
     73      *     return TCL_ERROR;
     74      * }
     75      *
     76      * where "Mod" is the name of the module.
     77      */
     78 
     79     if (Tcl_Init(interp) == TCL_ERROR) {
     80 	return TCL_ERROR;
     81     }
     82 
     83     if (Tk_Init(interp) == TCL_ERROR) {
     84 	return TCL_ERROR;
     85     }
     86 
     87     /*
     88      * Call Tcl_CreateCommand for application-specific commands, if
     89      * they weren't already created by the init procedures called above.
     90      */
     91 
     92     if (SWIG_init(interp) == TCL_ERROR) {
     93       return TCL_ERROR;
     94     }
     95 
     96 #ifdef MAC_TCL
     97     SetupMainInterp(interp);
     98 #endif
     99 
    100     /*
    101      * Specify a user-specific startup file to invoke if the application
    102      * is run interactively.  Typically the startup file is "~/.apprc"
    103      * where "app" is the name of the application.  If this line is deleted
    104      * then no user-specific startup file will be run under any conditions.
    105      */
    106 
    107 #if TCL_MAJOR_VERSION >= 8 || TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION >= 5
    108    Tcl_SetVar(interp, (char *) "tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY);
    109 #else
    110    tcl_RcFileName = SWIG_RcFileName;
    111 #endif
    112 
    113 /* For Macintosh might also want this */
    114 
    115 #ifdef MAC_TCL
    116 #ifdef SWIG_RcRsrcName
    117     Tcl_SetVar(interp, (char *) "tcl_rcRsrcName",SWIG_RcRsrcName,TCL_GLOBAL_ONLY);
    118 #endif
    119 #endif
    120     return TCL_OK;
    121 }
    122 
    123 #if TK_MAJOR_VERSION >= 4
    124 int main(int argc, char **argv) {
    125 
    126 #ifdef MAC_TCL
    127   char *newArgv[2];
    128   if (MacintoshInit() != TCL_OK) {
    129       Tcl_Exit(1);
    130   }
    131   argc = 1;
    132   newArgv[0] = "Wish";
    133   newArgv[1] = NULL;
    134   argv = newArgv;
    135 #endif
    136   Tk_Main(argc, argv, Tcl_AppInit);
    137   return(0);
    138 }
    139 #else
    140 extern int main();
    141 #endif
    142 
    143 %}
    144 
    145 
    146 
    147