PLUGIN_PATCHES -   1/2/99

This patch modifies the Tcl plugin for Netscape and Internet Explorer
to take full benefit of the plus-patches. It should be applied by running
the "patch" program in the top-level directory of a clean plugin 2.0 release,
using the command "patch -p0 <PLUGIN_PATCHES\""

WARNING: This patch is highly experimental!!!! Especially the installation
is not implemented yet (so "make install" doesn't work correctly). If
you don't know what you are doing, please don't use this patch but
just use the binary distribution of the plugin.

                                        Jan Nijtmans 

*** config/plugin.cfg.orig	Fri Jan  1 22:02:40 1999
--- config/plugin.cfg	Fri Jan  1 22:05:03 1999
***************
*** 67,74 ****
  # plugin/javascript subtree for security reasons
  
  section trustedJavascriptURLs
!     allow http://sunscript.sun.com:80/plugin/javascript/*
! 
  
  # Other User Preferences. If you uncomment these, reload the plugin and
  # the changes will take effect immediately:
--- 67,74 ----
  # plugin/javascript subtree for security reasons
  
  section trustedJavascriptURLs
!     allow http://www.demailly.com:80/tcl/plugin/javascript/*
!     allow http://www.scriptics.com:80/plugin/javascript/*
  
  # Other User Preferences. If you uncomment these, reload the plugin and
  # the changes will take effect immediately:
*** generic/nptcl.c.orig	Fri Jan  1 22:49:07 1999
--- generic/nptcl.c	Fri Jan  1 23:31:26 1999
***************
*** 164,175 ****
       *         we have more workarounds to putback in plugmain.tcl and
       *         remoted.tcl
       */
!     static char initScript[] ="global plugin tcl_library tk_library\n\
  #  Get the parent of all the dirs:\n\
! set plugin(topdir) [file dirname $plugin(library)]\n\
! set tcl_library [file join $plugin(topdir) \"tcl\"]\n\
! #  Prevent init.tcl from adding random (build time) paths to the auto_path\n\
! catch {unset tcl_pkgPath}\n\
  # source the 'right' init.tcl\n\
  source [file join $tcl_library init.tcl]\n\
  #  Export this tcl_library through our env() so the\n\
--- 164,173 ----
       *         we have more workarounds to putback in plugmain.tcl and
       *         remoted.tcl
       */
!     static char initScript[] ="global plugin tcl_library tk_library tcl_version tk_version\n\
  #  Get the parent of all the dirs:\n\
! set plugin(topdir) [file dirname [file dirname $plugin(library)]]\n\
! set tcl_library [file join $plugin(topdir) \"tcl$tcl_version\"]\n\
  # source the 'right' init.tcl\n\
  source [file join $tcl_library init.tcl]\n\
  #  Export this tcl_library through our env() so the\n\
***************
*** 177,185 ****
  #set env(TCL_LIBRARY) $tcl_library\n\
  #  Update the auto_path so that we can find other scripts in\n\
  #  sub directories of $plugin(topdir) by auto-loading:\n\
! lappend auto_path $plugin(topdir)\n\
  #  Tk:\n\
! set tk_library [file join $plugin(topdir) \"tk\"]\n\
  #  Export this tk_library through our env() so the\n\
  #  remote process will eventually get it and work around Tk_Init\n\
  #  'feature' of preferring then env var over anything.\n\
--- 175,184 ----
  #set env(TCL_LIBRARY) $tcl_library\n\
  #  Update the auto_path so that we can find other scripts in\n\
  #  sub directories of $plugin(topdir) by auto-loading:\n\
! lappend auto_path $plugin(topdir) [file dirname $plugin(library)]\n\
  #  Tk:\n\
! set tk_library [file join $plugin(topdir) \"tk$tk_version\"]\n\
! lappend auto_path $tk_library\n\
  #  Export this tk_library through our env() so the\n\
  #  remote process will eventually get it and work around Tk_Init\n\
  #  'feature' of preferring then env var over anything.\n\
*** unix/Makefile.in.orig	Fri Jan  1 22:34:30 1999
--- unix/Makefile.in	Sat Jan  2 17:51:34 1999
***************
*** 239,246 ****
        npcmd.o npinterp.o nptoken.o npxtnotify.o tclMiscUtils.o
  
  # tcl & tk objects files (determined by configure)
! TCL_OBJECTS = @TCL_OBJECTS@
! TK_OBJECTS = @TK_OBJECTS@
  
  TARGETS = $(NSP_LIB_FILE) $(TCLSHP)
  
--- 239,246 ----
        npcmd.o npinterp.o nptoken.o npxtnotify.o tclMiscUtils.o
  
  # tcl & tk objects files (determined by configure)
! TCL_OBJECTS = -ltcl8.0
! TK_OBJECTS = -ltk8.0
  
  TARGETS = $(NSP_LIB_FILE) $(TCLSHP)
  
*** unix/configure.in.orig	Fri Jan  1 22:11:30 1999
--- unix/configure.in	Sat Jan  2 17:48:17 1999
***************
*** 31,37 ****
  #     (script or configure will be done when time permit too)
  
  
! TCLTK_EXPECTED_VERSION=8.0p2Plugin2
  AC_SUBST(TCLTK_EXPECTED_VERSION)
  
  # The patch level is computed automatically below. no changes should be needed.
--- 31,37 ----
  #     (script or configure will be done when time permit too)
  
  
! TCLTK_EXPECTED_VERSION=8.0.4
  AC_SUBST(TCLTK_EXPECTED_VERSION)
  
  # The patch level is computed automatically below. no changes should be needed.
***************
*** 100,105 ****
--- 100,109 ----
  fi
  
  if test ! -d "$MOZILLA_DIR"; then
+ 	MOZILLA_DIR=/usr/local/netscape
+ fi
+ 
+ if test ! -d "$MOZILLA_DIR"; then
      AC_MSG_ERROR(Mozilla home directory \"$MOZILLA_DIR\" doesn't exist: use configure --with-mozilla=MOZILLA_HOME - ie. --with-mozilla=$HOME/.netscape for a personal install)
  fi
  AC_MSG_RESULT(found. will install in \"$MOZILLA_DIR\")
***************
*** 107,114 ****
  AC_SUBST(MOZILLA_DIR)
  
  # Check for Tcl and Tk *build* directories
! AC_ARG_WITH(tcl, [  --with-tcl=DIR          use Tcl 8.0 build dir from DIR],
! 	TCL_BIN_DIR=$withval, TCL_BIN_DIR="$srcdir/../../tcl8.0/unix")
  if test ! -d $TCL_BIN_DIR; then
      AC_MSG_ERROR(Tcl directory $TCL_BIN_DIR doesn't exist: use configure --with-tcl=TCL_BUILD_DIR)
  fi
--- 111,118 ----
  AC_SUBST(MOZILLA_DIR)
  
  # Check for Tcl and Tk *build* directories
! AC_ARG_WITH(tcl, [  --with-tcl=DIR          use Tcl 8.0.4 build dir from DIR],
! 	TCL_BIN_DIR=$withval, TCL_BIN_DIR="$srcdir/../../tcl8.0.4/unix")
  if test ! -d $TCL_BIN_DIR; then
      AC_MSG_ERROR(Tcl directory $TCL_BIN_DIR doesn't exist: use configure --with-tcl=TCL_BUILD_DIR)
  fi
***************
*** 117,124 ****
      AC_MSG_ERROR(There's no Makefile in $TCL_BIN_DIR;  perhaps you didn't specify the Tcl *build* directory (not the toplevel Tcl directory) or you forgot to configure Tcl?)
  fi
  
! AC_ARG_WITH(tk, [  --with-tk=DIR           use Tk 8.0 build dir from DIR],
! 	TK_BIN_DIR=$withval, TK_BIN_DIR="$srcdir/../../tk8.0/unix")
  if test ! -d $TK_BIN_DIR; then
      AC_MSG_ERROR(Tk directory $TK_BIN_DIR doesn't exist: use configure --with-tk=TK_BUILD_DIR)
  fi
--- 121,128 ----
      AC_MSG_ERROR(There's no Makefile in $TCL_BIN_DIR;  perhaps you didn't specify the Tcl *build* directory (not the toplevel Tcl directory) or you forgot to configure Tcl?)
  fi
  
! AC_ARG_WITH(tk, [  --with-tk=DIR           use Tk 8.0.4 build dir from DIR],
! 	TK_BIN_DIR=$withval, TK_BIN_DIR="$srcdir/../../tk8.0.4/unix")
  if test ! -d $TK_BIN_DIR; then
      AC_MSG_ERROR(Tk directory $TK_BIN_DIR doesn't exist: use configure --with-tk=TK_BUILD_DIR)
  fi
***************
*** 127,132 ****
--- 131,142 ----
      AC_MSG_ERROR(There's no Makefile in $TK_BIN_DIR;  perhaps you didn't specify the Tk *build* directory (not the toplevel Tk directory) or you forgot to configure Tk?)
  fi
  
+ AC_ARG_ENABLE(stubs, [  --enable-stubs          enable stubs],
+     [tcl_ok=$enableval], [tcl_ok=no])
+ if test "$tcl_ok" != "no"; then
+     AC_DEFINE(TCL_USE_STUBS)
+     AC_DEFINE(TK_USE_STUBS)
+ fi
  
  #	Read in configuration information generated by Tcl for shared
  #	libraries, and arrange for it to be substituted into our
***************
*** 139,151 ****
  
  
  # Check that the correct version of Tcl is used
! # It is not easy (impossible?) to check for 8.0p1 *or higher*
  # and it is most likely that this version of the plugin will not
  # work without modifications with any version other the one it
  # was initially built on anyway... (specially it will not work
  # properly with 8.1)
  AC_MSG_CHECKING(Tcl version and patch level)
! FV="${TCL_VERSION}${TCL_PATCH_LEVEL}"
  EV="$TCLTK_EXPECTED_VERSION"
  if test "${FV}" != "${EV}" ; then
  	AC_MSG_ERROR(Version mismatch\n  You need to use Tcl '${EV}' to build the plugin - not '${FV}')
--- 149,161 ----
  
  
  # Check that the correct version of Tcl is used
! # It is not easy (impossible?) to check for 8.0.4 *or higher*
  # and it is most likely that this version of the plugin will not
  # work without modifications with any version other the one it
  # was initially built on anyway... (specially it will not work
  # properly with 8.1)
  AC_MSG_CHECKING(Tcl version and patch level)
! FV=`echo ${TCL_VERSION}${TCL_PATCH_LEVEL} |sed -e 's/+//g'`
  EV="$TCLTK_EXPECTED_VERSION"
  if test "${FV}" != "${EV}" ; then
  	AC_MSG_ERROR(Version mismatch\n  You need to use Tcl '${EV}' to build the plugin - not '${FV}')
***************
*** 161,167 ****
  
  # Check that the correct version of Tk is used (see above)
  AC_MSG_CHECKING(Tk version and patch level)
! FV="${TK_VERSION}${TK_PATCH_LEVEL}"
  # EV is the same
  if test "${FV}" != "${EV}" ; then
  	AC_MSG_ERROR(Version mismatch\n  You need to use Tk '${EV}' to build the plugin - not '${FV}')
--- 171,177 ----
  
  # Check that the correct version of Tk is used (see above)
  AC_MSG_CHECKING(Tk version and patch level)
! FV=`echo ${TK_VERSION}${TK_PATCH_LEVEL} |sed -e 's/+//g'`
  # EV is the same
  if test "${FV}" != "${EV}" ; then
  	AC_MSG_ERROR(Version mismatch\n  You need to use Tk '${EV}' to build the plugin - not '${FV}')
*** unix/npunixplatf.c.orig	Fri Jan  1 22:45:49 1999
--- unix/npunixplatf.c	Fri Jan  1 23:26:20 1999
***************
*** 92,98 ****
  "if {[info exists plugin(library)]} return\n\
  proc PlugChkDir {dir} {\n\
      global plugin\n\
!     set d [file join $dir tclplug $plugin(version) plugin]\n\
  #   puts \"trying \\\"$d\\\" [info level 1]\"\n\
      if {[file isdirectory $d]} {\n\
        set plugin(library) $d\n\
--- 92,98 ----
  "if {[info exists plugin(library)]} return\n\
  proc PlugChkDir {dir} {\n\
      global plugin\n\
!     set d [file join $dir plugin$plugin(version) plugin]\n\
  #   puts \"trying \\\"$d\\\" [info level 1]\"\n\
      if {[file isdirectory $d]} {\n\
        set plugin(library) $d\n\
***************
*** 125,133 ****
  if {[info exists env(MOZILLA_HOME)]} {\n\
      lappend dirlist $env(MOZILLA_HOME)\n\
  }\n\
! lappend dirlist /usr/local/lib/netscape\n\
! lappend dirlist /usr/local/netscape\n\
! lappend dirlist /opt/netscape\n\
  #lappend dirlist [file dirname [file dirname [info nameofexecutable]]]\n\
  #lappend dirlist [pwd]\n\
  # actual checking\n\
--- 125,132 ----
  if {[info exists env(MOZILLA_HOME)]} {\n\
      lappend dirlist $env(MOZILLA_HOME)\n\
  }\n\
! lappend dirlist /usr/local/lib\n\
! lappend dirlist /usr/lib\n\
  #lappend dirlist [file dirname [file dirname [info nameofexecutable]]]\n\
  #lappend dirlist [pwd]\n\
  # actual checking\n\
***************
*** 139,145 ****
      }\n\
  }\n\
  unset dir\n\
! return -code error \"Could not find tclplug/$plugin(version)/plugin\\\n\
        directory in TCL_PLUGIN_DIR nor any of those candidates : $dirlist\"\n\
  ";
  
--- 138,144 ----
      }\n\
  }\n\
  unset dir\n\
! return -code error \"Could not find plugin$plugin(version)\\\n\
        directory in TCL_PLUGIN_DIR nor any of those candidates : $dirlist\"\n\
  ";
  
*** unix/npxtnotify.c.orig	Sat Jan  2 17:24:50 1999
--- unix/npxtnotify.c	Sat Jan  2 17:47:12 1999
***************
*** 16,23 ****
--- 16,46 ----
  #include "np.h"
  #include "npxt.h"
  
+ typedef struct FakeInterp {
+     char *result;		/* If the last command returned a string
+ 				 * result, this points to it. */
+     void (*freeProc) _ANSI_ARGS_((char *blockPtr));
+ 				/* Zero means the string result is
+ 				 * statically allocated. TCL_DYNAMIC means
+ 				 * it was allocated with ckalloc and should
+ 				 * be freed with ckfree. Other values give
+ 				 * the address of procedure to invoke to
+ 				 * free the result. Tcl_Eval must free it
+ 				 * before executing next command. */
+     int errorLine;              /* When TCL_ERROR is returned, this gives
+                                  * the line number within the command where
+                                  * the error occurred (1 if first line). */
+     Tcl_GlobalStubTable *stub;	/* stub table */
+ } FakeInterp;
+ 
  static int count = 0 ;
  
+ static void SetTimer _ANSI_ARGS_ ((Tcl_Time *timePtr));
+ static void CreateFileHandler _ANSI_ARGS_ ((int fd, int mask,
+ 	Tcl_FileProc *proc, ClientData clientData));
+ static void DeleteFileHandler _ANSI_ARGS_((int fd));
+ static int WaitForEvent _ANSI_ARGS_ ((Tcl_Time *timePtr));
+ 
  /*
   * This structure is used to keep track of the notifier info for a 
   * a registered file.
***************
*** 208,213 ****
--- 231,238 ----
  static void
  InitNotifier(void)
  {
+     Tcl_GlobalStubTable *stub;
+ 
      /*
       * Only reinitialize if we are not in exit handling. The notifier
       * can get reinitialized after its own exit handler has run, because
***************
*** 238,243 ****
--- 263,282 ----
       */
  
      notifier.inputMask = XtIMAll;
+ 
+     /*
+      * register new interp functions
+      */
+ 
+ #ifdef TCL_STUB_MAGIC
+     stub = ((FakeInterp *) NpGetMainInterp())->stub;
+     if (stub->magic == TCL_STUB_MAGIC) {
+ 	stub->setTimer = SetTimer;
+ 	stub->createFileHandler = CreateFileHandler;
+ 	stub->deleteFileHandler = DeleteFileHandler;
+ 	stub->waitForEvent = WaitForEvent;
+     }
+ #endif
  }
  
  /*
***************
*** 298,305 ****
   *----------------------------------------------------------------------
   */
  
! void
! Tcl_SetTimer(timePtr)
      Tcl_Time *timePtr;		/* Timeout value, may be NULL. */
  {
      long timeout;
--- 337,344 ----
   *----------------------------------------------------------------------
   */
  
! static void
! SetTimer(timePtr)
      Tcl_Time *timePtr;		/* Timeout value, may be NULL. */
  {
      long timeout;
***************
*** 379,385 ****
  /*
   *----------------------------------------------------------------------
   *
!  * Tcl_CreateFileHandler --
   *
   *	This procedure registers a file handler with the Xt notifier.
   *
--- 418,424 ----
  /*
   *----------------------------------------------------------------------
   *
!  * CreateFileHandler --
   *
   *	This procedure registers a file handler with the Xt notifier.
   *
***************
*** 393,400 ****
   *----------------------------------------------------------------------
   */
  
! void
! Tcl_CreateFileHandler(fd, mask, proc, clientData)
      int fd;			/* Handle of stream to watch. */
      int mask;			/* OR'ed combination of TCL_READABLE,
  				 * TCL_WRITABLE, and TCL_EXCEPTION:
--- 432,439 ----
   *----------------------------------------------------------------------
   */
  
! static void
! CreateFileHandler(fd, mask, proc, clientData)
      int fd;			/* Handle of stream to watch. */
      int mask;			/* OR'ed combination of TCL_READABLE,
  				 * TCL_WRITABLE, and TCL_EXCEPTION:
***************
*** 494,501 ****
   *----------------------------------------------------------------------
   */
  
! void
! Tcl_DeleteFileHandler(fd)
      int fd;			/* Stream id for which to remove
  				 * callback procedure. */
  {
--- 533,540 ----
   *----------------------------------------------------------------------
   */
  
! static void
! DeleteFileHandler(fd)
      int fd;			/* Stream id for which to remove
  				 * callback procedure. */
  {
***************
*** 715,722 ****
   *----------------------------------------------------------------------
   */
  
! int
! Tcl_WaitForEvent(
      Tcl_Time *timePtr)		/* Maximum block time, or NULL. */
  {
      int timeout;
--- 754,761 ----
   *----------------------------------------------------------------------
   */
  
! static int
! WaitForEvent(
      Tcl_Time *timePtr)		/* Maximum block time, or NULL. */
  {
      int timeout;
