         TCLX_PATCHES

These patches to TclX8.1.0 form the beginning of Stubs-support
for TclX. Implemented are:
- TclX_Main and TkX_Main should become macro's, which call
  new functions TclX_MainEx() and TkX_MainEx(). This is
  necessary to link the stub-enabled shared libraries
  directly with executables using back-linking.
  (In Tk8.1.0, Tk_MainEx is introduced for the same reason)
- The function Tcl_InitStubs() should be called in TclX_MainEx(),
  TclX_Init(), TkX_MainEx() and TkX_Init().
- A few other fixes, such as header-file ordering in tclXfilescan.c
  and a (char *) cast. Those two fixes are necessary only in
  combination with the 8.1.0 plus-patch, and have no
  other side-effects.

Still missing:
- libtclx8.1.0.so should be linked with libtclstub8.1.a.
- TclX should export its own stub-table, and provide its
  own stub-library (libtclxstub8.1.0.a) to be picked up by
  libtkx8.1.0.so
- libtkx8.1.0.so should be linked with libtclstub8.1.a,
  libtclxstub8.1.0.a and libtkstub8.1.a

This partial implementation is sufficient for me at this
moment. Later it will be implemented further.

                     Jan Nijtmans     Jan.Nijtmans@wxs.nl

==========================================================
*** unix/Common.mk.in.orig      Mon May 10 22:27:46 1999
--- unix/Common.mk.in   Mon May 10 22:28:47 1999
***************
*** 91,97 ****
  TCL_DEFS             = @TCL_DEFS@
  TCL_LIBS             = @TCL_LIBS@
  TCL_EXEC_PREFIX      = @TCL_EXEC_PREFIX@
! TCL_SHLIB_CFLAGS     = @TCL_SHLIB_CFLAGS@
  TCL_LD_FLAGS         = @TCL_LD_FLAGS@
  TCL_DL_LIBS          = @TCL_DL_LIBS@
  TCL_SHLIB_LD         = @TCL_SHLIB_LD@
--- 91,97 ----
  TCL_DEFS             = @TCL_DEFS@
  TCL_LIBS             = @TCL_LIBS@
  TCL_EXEC_PREFIX      = @TCL_EXEC_PREFIX@
! TCL_SHLIB_CFLAGS     = @TCL_SHLIB_CFLAGS@ -DUSE_TCL_STUBS
  TCL_LD_FLAGS         = @TCL_LD_FLAGS@
  TCL_DL_LIBS          = @TCL_DL_LIBS@
  TCL_SHLIB_LD         = @TCL_SHLIB_LD@
*** tcl/generic/tclExtend.h.orig        Mon May 10 22:35:47 1999
--- tcl/generic/tclExtend.h     Mon May 10 22:40:56 1999
***************
*** 112,117 ****
--- 112,126 ----
                         char           **argv,
                         Tcl_AppInitProc *appInitProc));

+ EXTERN void
+ TclX_MainEx _ANSI_ARGS_((Tcl_Interp *interp,
+                          int              argc,
+                          char           **argv,
+                          Tcl_AppInitProc *appInitProc));
+
+ #define TclX_Main(argc, argv, appInitProc) \
+       TclX_MainEx(Tcl_CreateInterp(), argc, argv, appInitProc)
+
  EXTERN int
  Tclx_Init _ANSI_ARGS_((Tcl_Interp *interp));

***************
*** 119,127 ****
  Tclx_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));

  EXTERN int
- Tclx_InitStandAlone _ANSI_ARGS_((Tcl_Interp *interp));
-
- EXTERN int
  Tclxcmd_Init _ANSI_ARGS_((Tcl_Interp *interp));

  EXTERN int
--- 128,133 ----
***************
*** 285,299 ****
  Tkx_Init _ANSI_ARGS_((Tcl_Interp  *interp));

  EXTERN int
- Tkx_InitStandAlone _ANSI_ARGS_((Tcl_Interp *interp));
-
- EXTERN int
  Tkx_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));

  EXTERN void
  TkX_Main _ANSI_ARGS_((int               argc,
                        char            **argv,
                        Tcl_AppInitProc  *appInitProc));

  /*
   * These are for Windows only.
--- 291,311 ----
  Tkx_Init _ANSI_ARGS_((Tcl_Interp  *interp));

  EXTERN int
  Tkx_SafeInit _ANSI_ARGS_((Tcl_Interp *interp));

  EXTERN void
  TkX_Main _ANSI_ARGS_((int               argc,
                        char            **argv,
                        Tcl_AppInitProc  *appInitProc));
+
+ EXTERN void
+ TkX_MainEx _ANSI_ARGS_((Tcl_Interp *interp,
+                         int               argc,
+                         char            **argv,
+                         Tcl_AppInitProc  *appInitProc));
+
+ #define TkX_Main(argc, argv, appInitProc) \
+       TkX_MainEx(Tcl_CreateInterp(), argc, argv, appInitProc)

  /*
   * These are for Windows only.
*** tcl/generic/tclXfilescan.c.orig     Mon May 10 22:11:47 1999
--- tcl/generic/tclXfilescan.c  Mon May 10 22:14:28 1999
***************
*** 17,24 ****
   *-----------------------------------------------------------------------------
   */

! #include "tclExtdInt.h"
  #include "tclRegexp.h"

  /*
   * A scan context describes a collection of match patterns and commands,
--- 17,25 ----
   *-----------------------------------------------------------------------------
   */

! #include "tcl.h"
  #include "tclRegexp.h"
+ #include "tclExtdInt.h"

  /*
   * A scan context describes a collection of match patterns and commands,
*** tcl/generic/tclXinit.c.orig Mon May 10 21:57:37 1999
--- tcl/generic/tclXinit.c      Mon May 10 22:04:54 1999
***************
*** 322,331 ****
  InitSetup (interp)
      Tcl_Interp *interp;
  {
!     if (Tcl_PkgRequire (interp, "Tcl", TCL_VERSION, 1) == NULL) {
        return TCL_ERROR;
      }
!     if (Tcl_PkgProvide (interp, "Tclx", TCLX_VERSION) != TCL_OK) {
        return TCL_ERROR;
      }

--- 322,331 ----
  InitSetup (interp)
      Tcl_Interp *interp;
  {
!     if (Tcl_InitStubs (interp, TCL_VERSION, 1) == NULL) {
        return TCL_ERROR;
      }
!     if (Tcl_PkgProvideEx (interp, "Tclx", TCLX_VERSION, NULL) != TCL_OK) {
        return TCL_ERROR;
      }

*** tcl/generic/tclXlib.c.orig  Mon May 10 21:50:47 1999
--- tcl/generic/tclXlib.c       Mon May 10 21:52:44 1999
***************
*** 207,213 ****
          goto posixError;
      channel = NULL;

!     oldScriptFile = iPtr->scriptFile;
      iPtr->scriptFile = fileName;
      result = Tcl_GlobalEval (interp, cmdBuf.string);
      iPtr->scriptFile = oldScriptFile;
--- 207,213 ----
          goto posixError;
      channel = NULL;

!     oldScriptFile = (char *) iPtr->scriptFile;
      iPtr->scriptFile = fileName;
      result = Tcl_GlobalEval (interp, cmdBuf.string);
      iPtr->scriptFile = oldScriptFile;
*** tcl/generic/tclXshell.c.orig        Mon May 10 22:41:27 1999
--- tcl/generic/tclXshell.c     Mon May 10 22:46:26 1999
***************
*** 202,208 ****
      TclX_ErrorExit (interp, 255, NULL);
  }

-
  /*-----------------------------------------------------------------------------
   * TclX_Main --
   *
--- 202,207 ----
***************
*** 219,239 ****
   *   Does not return.
   *-----------------------------------------------------------------------------
   */
  void
  TclX_Main (argc, argv, appInitProc)
      int               argc;
      char            **argv;
      Tcl_AppInitProc  *appInitProc;
  {
!     Tcl_Interp *interp;
      char *evalStr;

!     Tcl_FindExecutable (argv [0]);

!     /*
!      * Create a basic Tcl interpreter.
!      */
!     interp = Tcl_CreateInterp();

      /*
       * Do command line parsing.  This does not return on an error.  Information
--- 218,265 ----
   *   Does not return.
   *-----------------------------------------------------------------------------
   */
+
+ #undef TclX_Main
+
  void
  TclX_Main (argc, argv, appInitProc)
      int               argc;
      char            **argv;
      Tcl_AppInitProc  *appInitProc;
  {
!     TclX_MainEx(Tcl_CreateInterp(), argc, argv, appInitProc);
! }
!
!
! /*-----------------------------------------------------------------------------
!  * TclX_MainEx --
!  *
!  *   This function runs the TclX shell, including parsing the command line and
!  * calling the Tcl_AppInit function at the approriate place.  It either enters
!  * interactive command mode or evaulates a script or command from the command
!  * line.
!  *
!  * Parameters:
!  *   o interp - Interpreter
!  *   o argc, argv - Arguments passed to main for the command line.
!  *   o appInitProc - Application-specific initialization procedure to call
!  *     after most initialization but before starting to execute commands.
!  * Notes:
!  *   Does not return.
!  *-----------------------------------------------------------------------------
!  */
! void
! TclX_MainEx (interp, argc, argv, appInitProc)
!     Tcl_Interp        *interp;
!     int               argc;
!     char            **argv;
!     Tcl_AppInitProc  *appInitProc;
! {
      char *evalStr;

!     Tcl_InitStubs(interp, TCL_VERSION, 1);

!     Tcl_FindExecutable (argv [0]);

      /*
       * Do command line parsing.  This does not return on an error.  Information
*** tkXinit.c.orig      Mon May 10 22:19:38 1999
--- tkXinit.c   Mon May 10 22:21:16 1999
***************
*** 36,41 ****
--- 36,44 ----
  InitSetup (interp)
      Tcl_Interp  *interp;
  {
+     if (Tcl_InitStubs (interp, TCL_VERSION, 1) == NULL) {
+       return TCL_ERROR;
+     }
      if (Tcl_PkgRequire (interp, "Tk", TK_VERSION, 1) == NULL) {
        return TCL_ERROR;
      }
*** tk/generic/tkXshell.c.orig  Mon May 10 22:49:01 1999
--- tk/generic/tkXshell.c       Mon May 10 22:52:38 1999
***************
*** 72,77 ****
--- 72,79 ----
   *----------------------------------------------------------------------
   */

+ #undef TkX_Main
+
  void
  TkX_Main(argc, argv, appInitProc)
      int argc;                         /* Number of arguments. */
***************
*** 81,94 ****
                                         * initialization but before starting
                                         * to execute commands. */
  {
      char *args, *msg, *fileName;
      char buf[20];
      int code;
      size_t length;
      Tcl_Channel inChannel, outChannel, errChannel;
-     Tcl_Interp *interp;
      int tty;

      TclX_SetAppInfo (TRUE,
                       "wishx",
                       "Extended Wish",
--- 83,129 ----
                                         * initialization but before starting
                                         * to execute commands. */
  {
+     TkX_MainEx(Tcl_CreateInterp(), argc, argv, appInitProc);
+ }
+
+ /*
+  *----------------------------------------------------------------------
+  *
+  * TkX_MainEx --
+  *
+  *    Main program for Wish and most other Tk-based applications.
+  *
+  * Results:
+  *    None. This procedure never returns (it exits the process when
+  *    it's done.
+  *
+  * Side effects:
+  *    This procedure initializes the Tk world and then starts
+  *    interpreting commands;  almost anything could happen, depending
+  *    on the script being interpreted.
+  *
+  *----------------------------------------------------------------------
+  */
+
+ void
+ TkX_MainEx(interp, argc, argv, appInitProc)
+     Tcl_Interp *interp;                 /* Interpreter */
+     int argc;                         /* Number of arguments. */
+     char **argv;                      /* Array of argument strings. */
+     Tcl_AppInitProc *appInitProc;     /* Application-specific initialization
+                                        * procedure to call after most
+                                        * initialization but before starting
+                                        * to execute commands. */
+ {
      char *args, *msg, *fileName;
      char buf[20];
      int code;
      size_t length;
      Tcl_Channel inChannel, outChannel, errChannel;
      int tty;

+     Tcl_InitStubs(interp, TCL_VERSION, 1);
+
      TclX_SetAppInfo (TRUE,
                       "wishx",
                       "Extended Wish",
***************
*** 96,102 ****
                       TCLX_PATCHLEVEL);

      Tcl_FindExecutable(argv[0]);
-     interp = Tcl_CreateInterp();
  #ifdef TCL_MEM_DEBUG
      Tcl_InitMemory(interp);
  #endif
--- 131,136 ----
