Committing merge from trunk into branches/apreq-multipart
diff --git a/ChangeLog b/ChangeLog
index 7b36fc9..b1e3073 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,121 @@
+2012-04-07 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/packages/mod_rivet.[c|h]: One more change to an ap_log_error call suggested
+    by the compilation hardening flags
+
+2012-03-26 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/packages/entities.tcl: new package RivetEntities, replacement for tcllib
+    ::html::entities but with no extra dependecies (as a matter of fact it 
+    works without Rivet too)
+
+2012-03-13 Karl Lehenbauer <karl@apache.org>
+    * configure.ac: Default separate virtual interps to "no".
+    (--enable-virtual-interps-separation option implies disabled if not set.)
+    * rivet/packages/form/form.tcl: In the forms package, stop bleeding the 
+    raw value of radio buttons and checkboxes into the generated HTML.
+    * src/apache-2/mod_rivet.c: Rework ap_log_error calls to include the
+    mod_rivet module name.  Emit debug-level messages for successful
+    execution of GlobalInitScript and ServerInitScript.
+    * README.freebsd: Update to reflect the modern world.
+    * README.configure: Document how to regenerate the configure script, etc.
+    * tclconfig/depcomp, tclconfig/missing, tclconfig/config.guess,
+    tclconfig/config.sub, tclconfig/ltmain.sh: Update from newer libtools, etc.
+
+2012-03-08 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/rivet-tcl/,/rivet/packages/simpledb: various changes suggested by code profiler
+    (thanks to Harald Oehlmann)
+    * rivet/packages/tclrivetparse.tcl: wrong handling of swich cases made method 'parse'
+    unusable
+    * src/rivet.h: obsolete comment amended
+
+2012-01-16 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/rivet-tcl/tclIndex.tcl: regenerated with auto_mkindex.
+
+2012-01-15 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/rivet-tcl/parray_table.tcl: this file was erroneously introduced as
+    tablearray.tcl. Renamed.
+    * rivet/rivet-tcl/putsnnl.tcl: experimental putsnnl command rewritten to 
+    improve features and make it more flexible by adding option for padding 
+    with &nbsp; entities. 
+
+2012-01-10 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/rivet-tcl/parray_table.tcl: New command parray_table to print the
+    content of an array into an HTML table
+    * rivet/rivet-tcl/putsnnl.tcl: More consistent form for 'putsnnl'. If the
+    second argument is given and it's an integer then the string is at most <nchars>
+    characters long. If <nchars> > [string lenghth <output_string>] then the output
+    is still <nchars> wide. If <spaces> is a positive integer the string is printed 
+    right-aligned, if negative the string is left-aligned
+
+2011-12-26 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/rivet-tcl/putsnnl.tcl: Add new command 'putsnnl', a wrapper for
+    'puts -nonewline' with the extra optional feature of prepending the output 
+    with a definite number of spaces (it helps pretty printing of HTML)
+
+2011-12-09 Massimo Manghi <mxmanghi@apache.org>
+    * src/rivetPkgInit.c,src/parserPkgInit.c: libs now are fully based on stubs and
+    the tcl version parameter passed with Tcl_InitStubs is the same Tcl version their
+    linked against. Probably too strict, but a cautious point as we are moving towards
+    Tcl8.6 and Tcl9, which will probably require recompilation of the whole Tcl software
+
+2011-12-08 Massimo Manghi <mxmanghi@apache.org>
+    * trunk/: Final commit merging changes to scoping commands in the ::rivet namespace
+
+2011-12-07 Massimo Manghi <mxmanghi@apache.org>
+    * doc/examples, doc/convert_examples.tcl.in: Add ::rivet namespace to examples and
+    examples code converter
+    * doc/examples/*.rvt: removed unneeded sgml chars escaping
+    * doc/xml/install.xml: removed duplicated entry of a 'configure' switch
+
+2011-12-06 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/rivet-tcl/tablearray.tcl: new procedure 'tablearray' prints an array content
+    in an HTML <table> construct. Test procedure, we maybe want to have something more
+    general for printing also dictionaries.
+
+2011-12-06 Massimo Manghi <mxmanghi@apache.org>
+    * configure_ac: add new test on Tcl version using AX_VERSION_COMPARE.
+
+2011-12-06 Massimo Manghi <mxmanghi@apache.org>
+    * doc/xml/request.xml,doc/xml/install.xml: documenting new configure switches
+
+2011-12-05 Massimo Manghi <mxmanghi@apache.org>
+    * src/apache-2/mod_rivet.c: child init sets also the array module_conf to signal the
+    compilation flags --enable-rivet-commands-export and --enable-import-namespace-commands
+    for the benefit of init.tcl
+    * configure.ac: new macro created to handle --enable-rivet-commands-export and 
+    --enable-import-namespace-commands
+    * rivet/init.tcl: module_conf signals when commands have to be exported from ::rivet
+    and when they have to be implicitly imported into the global namespace for compatibility
+    with previous versions of Rivet.
+
+2011-11-21 Massimo Manghi <mxmanghi@apache.org>
+    * doc/xml/directives.xml,doc/xml/commands.xml: removed note about 'rivetlib' package
+    no more needed. Notes about ServerInitScript not having effect when virtual hosts
+    have their own private slave interpreters.
+
+2011-11-20 Massimo Manghi <mxmanghi@apache.org>
+    * doc/xml/commands.xml,doc/xml/install.xml: documentation for building Rivet updated.
+    * configure.ac: corrected help message for --disable-rivet-commands-export
+
+2011-11-20 Massimo Manghi <mxmanghi@apache.org>
+    * src/rivet.h: Macro definition for Rivet command objects has rolled back to 
+    its previous form and doesn't call Tcl_Export anymore. In case commands are
+    exported by calling Tcl_Export in rivetCore.c and rivetPkgInit.c
+    * tests/*: test suite reviewed for new tests
+
+2011-11-16 Massimo Manghi <mxmanghi@apache.org>
+    * src/apache-2/rivetCore.c: code rationalization. namespace reference will not be
+    passed to the RIVET_OBJ_COMMAND macro and commands are exported by calling Tcl_Export
+    on the whole command set in ::rivet. The whole process is controlled by the macro
+    symbol RIVET_NAMESPACE_EXPORT 
+    * src/rivet.h: only one RIVET_OBJ_COMMAND object exists now. Call to Rivet_WWWInit,
+    Rivet_CryptInit and Rivet_ListInit haved changed. Rivet namespace pointer in not
+    passed around anymore and it's handled only in rivetPkgInit.c
+    * src/rivetPkgInit.c: 
+
+2011-11-14 Massimo Manghi <mxmanghi@apache.org>
+    * configure.ac:  new switch --enable-rivet-commands-export to enable/disable 
+    commands in ::rivet namespace
+
 2011-11-12 Massimo Manghi <mxmanghi@apache.org>
     * src/apache-2/rivetCore.c: reindented to improve readability.
     * doc/xml/commands.xml: typo corrected
@@ -18,6 +136,13 @@
     changes done in the process of releasing the Debian package
     for 2.0.4 
 
+2011-09-26 Massimo Manghi <mxmanghi@apache.org>
+    * m4/ax_compare_version.m4: add macro for version comparison from the GNU macro archive
+
+2011-09-23 Massimo Manghi <mxmanghi@apache.org>
+    * src/apache-2/rivetCore.c,src/apache-2/TclWebapache.c: merging changes
+    made to fix bugs and requests to command 'makeurl', 'load_env' and 'load_headers'
+
 2011-09-07 Massimo Manghi <mxmanghi@apache.org>
     * doc/xml/commands.xml: Add existing undocumented commands 
         - import_keyvalue_pairs
@@ -53,7 +178,7 @@
 
 2011-05-09 Massimo Manghi <mxmanghi@apache.org>
     * src/apache-2/mod_rivet.c: fixed misleading error message displayed when rivet_abort_script fails
-    * 
+
 2011-05-05 Massimo Manghi <mxmanghi@apache.org>
     * configure.ac: APACHE_VERSION returns an error message for--with-apache-version=1. 
     * src/apache-1/: removed from trunk
@@ -64,6 +189,17 @@
     * configure.ac: doc/convert_examples.tcl is generated from template: added to AC_CONFIG_FILES 
     * debian/changelog,debian/control: changed to reflect improvement in the script for Debian
 
+2011-06-07 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/init.tcl: because of bug #3216070 of Tcl we cannot preload rivetlib, so it doesn't make
+    sense to import the rivet namespace, because we cannot have all the command set loaded in and
+    an import has to be done for them in the application scripts
+    * rivet/rivet-tcl/incr0.tcl: Tcl8.5 provides identical functionalities, so this command is
+    now aliased in the interpreter by the native incr command.
+    * rivet/rivet-tcl/tclIndex: recreated
+
+2011-04-06 Massimo Manghi <mxmanghi@apache.org>
+    * configure.ac: Added doc/convert_examples.tcl to files created from its .in template
+
 2011-04-03 Massimo Manghi <mxmanghi@apache.org>
     * doc/convert_examples.tcl.in,doc/convert_examples.tcl: Added script to convert code examples
     from their native form to a sgml escaped form.
@@ -78,9 +214,22 @@
     * doc/convert_examples.tcl: New procedure that check for changes in doc/examples and, if needed,
     creates/recreates the corrisponding file in doc/examples-sgml escaping characters
 
+2011-03-03 Massimo Manghi <mxmanghi@apache.org>
+    * rivet/rivet-tcl/*.tcl: all the commands in here moved into ::rivet namespace. File tclIndex
+    recreated
+    * doc/xml/directives.xml,doc/xml/commands.tcl: Documentation changed to reflect the new scoping of
+    the command set. Commands in rivet-tcl/ not yet documented have been briefly explained with some
+    examples.
+    * src/apache-2/mod_rivet.[c|h],src/apache-2/rivetCore.c: changes in trunk merged into the
+    rivet-namespace branch
+
 2011-03-01 Massimo Manghi <mxmanghi@apache.org>
     * src/apache-2/rivetCode.c: 'abort_code' command is now created through the RIVET_CMD_OBJ macro
 
+2011-02-18 Massimo Manghi <mxmanghi@apache.org>
+    * src/rivet.h,src/apache-2/rivetCore.c,src/rivetPkgInit.c: Core commands namespace is now '::rivet' and 
+    the package provided by the core module is "::rivet". Also package RivetLib was renamed as 'rivetlib'.
+
 2011-02-14 Karl Lehenbauer <karl@apache.org>
     * src/apache-2/mod_rivet.c: Only create root interpreter once, not twice.  
     In Rivet_CopyConfig cache_size and cache_free were getting copied twice.  
@@ -88,11 +237,41 @@
     * src/apache-2/rivetCore.c: Remove unused command var from Rivet_Upload.
     Remove unneeded loglevel var from Rivet_LogErrorCmd.
 
+2011-02-14 Massimo Manghi <mxmanghi@apache.org>
+    * src/apache-2/mod_rivet.[h|c],src/apache-2/rivetCore.c: Removed loading of RivetLib by default. Getting
+    RivetLib into the module keeps Apache to segfault in other calls. In order to gain access to commands
+    provided by RivetLib (formerly called Rivet) a 'package require RivetLib' must be in a Rivet script or
+    in one of the initialization script (e.g. ServerInitScript ChildInitScript or GlobalInitScript). Notice:
+    RivetLib exports the commands to the '::Rivet' namespace.
+    * src/rivetCrypt.c, src/rivetWWW.c, src/rivetList.c: they now export their commands to the '::Rivet'
+
 2011-02-11 Massimo Manghi <mxmanghi@apache.org>
     * src/apache-2/mod_rivet.[c|h]: new conf scripts rivet_abort_script and rivet_force_script. rivet_abort_script
     is run when an abort_page command is called in the page content generation
     * src/apache-2/rivetCode.c: add new command abort_code that returns the code passed to abort_page
 
+2011-02-08 Massimo Manghi <mxmanghi@apache.org>
+    * src/apache-2/rivetCore.c: call to Rivet_InitWWW to include into Rivet's core the commands provided in
+    src/rivetWWW.c
+    * src/apache-2/mod_rivet.c: the inclusion into the module of RivetLib through Tcl_PkgRequire proved
+    to cause segfaults in Rivet_ServerConf. The commands in rivetWWW.c are temporarily loaded by rivetCore.c
+    * src/apache-2/Makefile.am: build of mod_rivet.so includes also code from src/libWWW.o
+
+2011-02-07 Massimo Manghi <mxmanghi@apache.org>
+    * branches/rivet-namespace: new branch to experiment with the Rivet namespace and Rivet package 
+    * src/rivetPkgInit.c: Provides RivetLib package now when loaded by mod_rivet. Commands are now
+    in the ::Rivet namespace
+    * src/rivet.h: new macro RIVET_OBJ_CMD creates a command in the ::Rivet namespace
+    and puts the command object on the namespace export list
+    * src/apache-2/mod_rivet.h: the globals structure now holds a pointer to the Tcl_Namespace object
+    representing ::Rivet namespace
+    * src/apache-2/rivetCore.c: commands are now created with the RIVET_OBJ_CMD macro 
+    * rivet/init.tcl: provides package RivetTcl 2.1. This makes possible to consistently peek the 
+    init.tcl associated to the module. Command 'incr0' is now aliased by Tcl standard 'incr'
+    * rivet/apache-2/mod_rivet.c: Rivet_PerInterpInit loads package RivetTcl 2.1 and package RivetLib 1.2.
+    the latter ships the commands in rivetWWW.c rivetCrypt.c and rivetList.c
+    * rivet/rivet-tcl/tclIndex: Command 'incr0' removed (see init.tcl)
+
 2011-01-31 Massimo Manghi <mxmanghi@apache.org>
     * configure.ac: default value for directive SeparateVirtualInterps changed to 'yes'.
     * VERSION: version number set as 2.1.0r1 ('r' is for 'revision')
diff --git a/INSTALL b/INSTALL
index d86c466..7ef6b45 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,4 +1,4 @@
-			  Rivet 2.0 Installation
+			  Rivet 2.1 Installation
 			  ======================
 
 For more detailed instructions, see the docs/html/ directory.
@@ -16,7 +16,7 @@
 	    --with-apxs=/usr/bin/apxs 		\
 	    --with-tclsh=/usr/bin/tclsh8.5 	\
 	    --with-apache-version=2		\
-	    --with-rivet-target-dir=/usr/lib/rivet2.0 \
+	    --with-rivet-target-dir=/usr/lib/rivet2.1 \
 	    --enable-version-display
 
 2) if 'configure' was successful Rivet is ready for compilation
@@ -36,24 +36,24 @@
 Along with the usual 'configure' variables Rivet's configure script 
 handles other specific options. 
 
---with-tcl=DIR			Directory where tclConfig.sh is
-				stored. This is a shell script that
-				defines all the relevant symbols needed
-				to build Tcl related applications.
---with-apache-version=VER	Values are 1 or 2 depending
-				on the apache server you're 
-				builing the module for.
---with-apache=DIR		Apache server's root directory.
---with-apxs=FILE		Path to the apxs program to
-				be used in the compilation
-				process.
---with-apache-include=DIR	Apache's include files path.
---with-apr-config=FILE		Apache Portable Runtime 
-				metainformation program
+--with-tcl=DIR              Directory where tclConfig.sh is
+                            stored. This is a shell script that
+				            defines all the relevant symbols needed
+				            to build Tcl related applications.
+--with-apache-version=VER   Values are 1 or 2 depending
+				            on the apache server you're 
+                            builing the module for.
+--with-apache=DIR           Apache server's root directory.
+--with-apxs=FILE            Path to the apxs program to
+                            be used in the compilation
+                            process.
+--with-apache-include=DIR   Apache's include files path.
+--with-apr-config=FILE      Apache Portable Runtime 
+                            metainformation program
 --with-rivet-target-dir=DIR	Rivet library installation directory.
---enable-version-display	Apache signature shows Rivet 
-				version number in the form Rivet/2.0.x. 
-				Default=no
+--enable-version-display    Apache signature shows Rivet 
+                            version number in the form Rivet/2.0.x. 
+                            Default=no
 
 These are the basic Apache configuration directives that are needed:
 
@@ -74,7 +74,7 @@
 
 ./configure --with-apache-include=/usr/include/apr-1.0 		\
 	    --with-apache-version=2 --with-apxs=/usr/bin/apxs2 	\
-	    --with-tcl=/usr/lib/tcl8.4 --with-apache=/usr
+	    --with-tcl=/usr/lib/tcl8.6 --with-apache=/usr
 
 Here is another example reported by a user who successfully built 
 Rivet on Slackware 12.1
diff --git a/Makefile.in b/Makefile.in
index a515026..943d37b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -51,10 +51,8 @@
 	tclconfig/config.sub tclconfig/depcomp tclconfig/install-sh \
 	tclconfig/ltmain.sh tclconfig/missing
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/ltoptions.m4 \
-	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
-	$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
-	$(top_srcdir)/tclconfig/tcl.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
+	$(top_srcdir)/acinclude.m4 $(top_srcdir)/tclconfig/tcl.m4 \
 	$(top_srcdir)/tclconfig/libtool.m4 \
 	$(top_srcdir)/m4/ax_prefix_config_h.m4 \
 	$(top_srcdir)/configure.ac
@@ -87,9 +85,11 @@
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
 am__remove_distdir = \
-  { test ! -d "$(distdir)" \
-    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
-         && rm -fr "$(distdir)"; }; }
+  if test -d "$(distdir)"; then \
+    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+      && rm -rf "$(distdir)" \
+      || { sleep 5 && rm -rf "$(distdir)"; }; \
+  else :; fi
 am__relativize = \
   dir0=`pwd`; \
   sed_first='s,^\([^/]*\)/.*$$,\1,'; \
@@ -118,6 +118,8 @@
 DIST_ARCHIVES = $(distdir).tar.gz
 GZIP_ENV = --best
 distuninstallcheck_listfiles = find . -type f -print
+am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
+  | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
 distcleancheck_listfiles = find . -type f -print
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
@@ -188,6 +190,7 @@
 MATH_LIBS = @MATH_LIBS@
 MAX_POST = @MAX_POST@
 MKDIR_P = @MKDIR_P@
+MOD_RIVET_INCLUDES = @MOD_RIVET_INCLUDES@
 NM = @NM@
 NMEDIT = @NMEDIT@
 OBJDUMP = @OBJDUMP@
@@ -312,7 +315,7 @@
 	$(MAKE) $(AM_MAKEFLAGS) all-recursive
 
 .SUFFIXES:
-am--refresh:
+am--refresh: Makefile
 	@:
 $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
 	@for dep in $?; do \
@@ -348,10 +351,8 @@
 $(am__aclocal_m4_deps):
 
 config.h: stamp-h1
-	@if test ! -f $@; then \
-	  rm -f stamp-h1; \
-	  $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
-	else :; fi
+	@if test ! -f $@; then rm -f stamp-h1; else :; fi
+	@if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi
 
 stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
 	@rm -f stamp-h1
@@ -580,7 +581,11 @@
 	$(am__remove_distdir)
 
 dist-bzip2: distdir
-	tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+	tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
+	$(am__remove_distdir)
+
+dist-lzip: distdir
+	tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
 	$(am__remove_distdir)
 
 dist-lzma: distdir
@@ -588,7 +593,7 @@
 	$(am__remove_distdir)
 
 dist-xz: distdir
-	tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
+	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
 	$(am__remove_distdir)
 
 dist-tarZ: distdir
@@ -619,6 +624,8 @@
 	  bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
 	*.tar.lzma*) \
 	  lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\
+	*.tar.lz*) \
+	  lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
 	*.tar.xz*) \
 	  xz -dc $(distdir).tar.xz | $(am__untar) ;;\
 	*.tar.Z*) \
@@ -638,6 +645,7 @@
 	  && am__cwd=`pwd` \
 	  && $(am__cd) $(distdir)/_build \
 	  && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+	    $(AM_DISTCHECK_CONFIGURE_FLAGS) \
 	    $(DISTCHECK_CONFIGURE_FLAGS) \
 	  && $(MAKE) $(AM_MAKEFLAGS) \
 	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
@@ -666,8 +674,16 @@
 	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
 	  sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
 distuninstallcheck:
-	@$(am__cd) '$(distuninstallcheck_dir)' \
-	&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+	@test -n '$(distuninstallcheck_dir)' || { \
+	  echo 'ERROR: trying to run $@ with an empty' \
+	       '$$(distuninstallcheck_dir)' >&2; \
+	  exit 1; \
+	}; \
+	$(am__cd) '$(distuninstallcheck_dir)' || { \
+	  echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \
+	  exit 1; \
+	}; \
+	test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \
 	   || { echo "ERROR: files left after uninstall:" ; \
 	        if test -n "$(DESTDIR)"; then \
 	          echo "  (check DESTDIR support)"; \
@@ -698,10 +714,15 @@
 
 installcheck: installcheck-recursive
 install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-	  `test -z '$(STRIP)' || \
-	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
 mostlyclean-generic:
 
 clean-generic:
@@ -790,8 +811,8 @@
 .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
 	all all-am am--refresh check check-am clean clean-generic \
 	clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \
-	dist-gzip dist-lzma dist-shar dist-tarZ dist-xz dist-zip \
-	distcheck distclean distclean-generic distclean-hdr \
+	dist-gzip dist-lzip dist-lzma dist-shar dist-tarZ dist-xz \
+	dist-zip distcheck distclean distclean-generic distclean-hdr \
 	distclean-libtool distclean-local distclean-tags \
 	distcleancheck distdir distuninstallcheck dvi dvi-am html \
 	html-am info info-am install install-am install-data \
diff --git a/README b/README
index dd3bf2e..0147264 100644
--- a/README
+++ b/README
@@ -20,4 +20,16 @@
 to the client
 
  
+			    RIVET NAMESPACE
+			    ===============
+
+ - With the intruduction of the Rivet namespace the command set has been
+moved into '::rivet' and should now be fully qualified. Commands are exported
+though and can be imported in the global namespace, but whenever possible this
+is deprecated.  Putting the following code in the Server Conf should guarantee
+compatibility with existing scripts
+
+RivetServerConf	    ServerInitScript	"package require rivet"
+RivetServerConf	    ServerInitScript	"package require rivetlib"
+RivetServerConf	    ServerInitScript	"namespace import --force ::rivet::*"
 
diff --git a/README.configure b/README.configure
index eb8f3f4..e2565f4 100644
--- a/README.configure
+++ b/README.configure
@@ -8,87 +8,28 @@
 
 WHERE IS THE CONFIGURE SCRIPT?
 
-If you've checked out the source tree from CVS, you'll notice there's no
+If you've checked out the source tree from SVN, you'll notice there's no
 configure script, and no configure.in, and no Makefile.in, etc.
 
 You get to fiddle the autoconf stuff to create all that.
 
-VERSIONS
+This used to be hard but not so much anymore.
+
+Try
+
+	autoreconf -fi
+
+
+This runs aclocal, autoconf, automake and whatever else to properly
+generate config.h.in, aclocal.m4, */Makefile.in, etc.
 
 autoconf and stuff has evolved, and old versions won't work and will cause
 weird problems.
 
-autoconf 2.59
-automake 1.9
-aclocal 1.9
-autoheader 2.59
+You want to be at least at
 
-BUILDING IT
-
-First you gotta run "aclocal" to create the aclocal.m4 file.
-
-Then you can run "automake" to create the Makefile.in files from
-the Makefile.am automake source files.  NOTE that even though automake
-runs autoconf, you still have to run autoconf.
-
-Run "autoconf", make sure you're getting the right version by doing
-autoconf --version
-
-Run "autoheader" to generate the config.h.in
-
-Once all that is complete, you can probably run configure.
-
-
-AUTOMAKE
-
-Automake greatly simplifies the complexity of the Makefiles.  With automake
-we generate Makefile.am.  Automake will create the Makefile.in, which
-configure, as always, will use to generate the Makefile.
-
-Automake could be brought to TEA extensions to greatly simplify the
-complexity of their build definitions (configure macros, Makefiles, etc)
-
-LIBTOOL
-
-libtool super simplifies and standardizes building shared and static 
-libraries across tons of variants in operating system architecture
-around shared libraries, linking, etc.
-
-A libtool script is generated by running the configure script.  The libtool
-docs suggest shipping libtool.m4 in your package, else there's no guarantee
-aclocal, etc, are going to be able to find one on the local system that
-will work, should autoconf need to be run, etc.
-
-A recurring maintenance task for the Rivet team will be to freshen the
-libtool.m4.
-
-Libtool also offers substantial simplification to Tcl extension writers
-and maintainers.
-
-TCL.M4
-
-There's a bunch of stuff Tcl extensions (and Tcl, etc) need to know about
-systems and it's all set up to be handled by tcl.m4.
-
-We've hacked on tcl.m4 from the Tcl Extension Architecture (TEA 3.1)
-version.  Our changes should probably be folded back in.
-
-VERSIONS AND ENV VARS
-
-It appears that the autoconf tools are moving towards versions, where
-aclocal 1.9 can be run as aclocal-1.9.  This is good.
-
-FreeBSD ports, though, had already been doing this, so there this stuff
-is called, for instance, aclocal19.
-
-You might need to set up environment variables to tell the autoconf tools
-the names autoheader, autoconf, automake, and aclocal are installed under,
-something like this:
-
-export AUTOHEADER=autoheader259
-export AUTOCONF=autoconf259
-export AUTOMAKE=automake19
-export ACLOCAL=aclocal19
+autoconf 2.58
+automake 1.11
 
 
 CONFIG.GUESS AND FRIENDS
@@ -103,3 +44,5 @@
 This stuff is in the tclconfig directory, which isn't really the best
 name because it's grown to include a lot of autoconf-related stuff.
 
+But it really doesn't matter anymore because autoreconf appears to take
+care of it all.
diff --git a/README.freebsd b/README.freebsd
index 6d96510..28e2815 100644
--- a/README.freebsd
+++ b/README.freebsd
@@ -4,16 +4,17 @@
 
 Rivet can be built under FreeBSD without any special tweaks.
 
-We'd love some help in making this a port in the FreeBSD ports tree, so this 
-build could be even more automatic.
+Rivet is a port in the FreeBSD ports tree.  To build the latest one
+supported there, cd to /usr/ports/www/mod_rivet and do a make install
+or equivalent.
 
-For now, you need to build and install Tcl and Apache
+To build from source, first you need to build and install Tcl and Apache...
 
-    cd /usr/ports/lang/tcl84
+    cd /usr/ports/lang/tcl85
     make
     make install
 
-    cd /usr/ports/www/apache13
+    cd /usr/ports/www/apache22
     make
     make install
 
@@ -24,38 +25,10 @@
 
 Run configure in this directory with the following parameters:
 
-./configure  --with-tcl=/usr/local/lib/tcl8.4 --with-tclinclude=/usr/local/include/tcl8.4
+./configure  --with-tcl=/usr/local/lib/tcl8.5
 
-...or equivalent.  Your mileage may vary.
+If you want to build with debugging symbols enabled for debugging Apache
+and mod_rivet with gdb or whatever, add "--enable-symbols" to the above.
 
+Your mileage may vary.
 
-
-RUNNING AUTOMAKE, AUTOCONF, ETC
-
-
-you gotta use automake 1.9 (and with it, aclocal 1.9)
-
-you gotta use autoconf 2.59 (and with it, autoheader 2.59)
-
-You need to build and install /usr/ports/devel/gnu-autotools
-to get a libtoolize that has no special adaptations to FreeBSD.
-
-PATH=/usr/local/gnu-autotools/bin:$PATH
-
-aclocal19
-automake19
-autoconf259
-autoheader259
-
-Karl has found that setting some environment variables makes it work better...
-
-export AUTOHEADER=autoheader259
-export AUTOCONF=autoconf259
-export AUTOMAKE=automake19
-export ACLOCAL=aclocal19
-
-But there's still a problem where it'll try to run aclocal as aclocal-1.9,
-and fail.  I usually just try to run aclocal19 there and see if that fixes
-the make dependency or whatever.
-
-I think the autoconf tools are moving towards that kind of naming scheme.
diff --git a/VERSION b/VERSION
index 4952462..0e4065c 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.0r1
+2.1.0a1
diff --git a/configure.ac b/configure.ac
index 8a9d02a..7a5cd3e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@
 # so you can encode the package version directly into the source files.
 #-----------------------------------------------------------------------
 
-AC_INIT([Rivet],[2.1.0r1])
+AC_INIT([Rivet],[2.1.0a1])
 TEA_INIT([3.9])
 
 AC_CONFIG_AUX_DIR(tclconfig)
@@ -218,7 +218,7 @@
 
 # We have to either find a working tclsh or be told where it is 
 # using --with-tclsh
-AC_ARG_WITH(tclsh, [  --with-tclsh=FILE       location of a working tclsh executable], with_tclsh=${withval})
+AC_ARG_WITH(tclsh, [  --with-tclsh=FILE location of a working tclsh executable], with_tclsh=${withval})
 
 #
 # allow them to override the tclsh we think we found
@@ -365,7 +365,25 @@
     fi
 ])
 
-# apache version
+
+#--------------------------------------------------------------------
+# 6-Dec-2011: Introducing new ::rivet namespace. Some components 
+# (namely RivetTcl, providing Tcl level initialization) are required 
+# within mod_rivet.c. Unfortunalely Tcl < 8.5.10 loaded shared
+# libs exporting names that clashed with Apache's own namespace and, 
+# hence we have to make sure we are running a Tcl compatible version.
+# (See bug #3216070). If you're running Tcl < 8.5.10 we won't go any
+# further ahead...
+
+AX_COMPARE_VERSION([$TCL_VERSION$TCL_PATCH_LEVEL],[lt],[8.5.10],[
+    AC_MSG_ERROR([Rivet 2.1 requires Tcl > 8.5.10 (current is $TCL_VERSION$TCL_PATCH_LEVEL)])
+] , [
+    AC_MSG_NOTICE([ok, we are running Tcl $TCL_VERSION$TCL_PATCH_LEVEL])
+])
+
+
+
+# APACHE_VERSION
 #
 # let's determine whether we are building for apache1.x or apache2.x.
 # This variable has consequences on the default values for the remaining 
@@ -381,13 +399,14 @@
 
     AC_MSG_CHECKING(for apache version)
     if test "$with_apache_version" = "1"; then
-        AC_MSG_ERROR([Apache 1.x no more supported])
+        AC_MSG_ERROR([Apache 1.x no more supported starting with Rivet 2.1])
     else
         AC_MSG_RESULT( building for apache 2.x )
         AC_CONFIG_FILES([src/apache-2/Makefile])
         apache_version_dir="apache-2"
         AC_DEFINE(APACHE2,1,[APACHE2 definition in config.h])
     fi
+    MOD_RIVET_INCLUDES="-I ${apache_version_dir}"
 ])
 
 AC_DEFUN([HANDLE_TCL_PACKAGE_PATH],[
@@ -500,6 +519,53 @@
     fi
 ])
 
+# RIVET_COMMANDS_EXPORT (--enable-rivet-commands-export).
+# Enable export of commands in Rivet's namespace. Definining this symbols
+# sets the boolean configuration variable rivet_commands_export 
+# Default: yes
+
+AC_DEFUN([RIVET_COMMANDS_EXPORT],[
+    AC_ARG_ENABLE(
+        rivet-commands-export,
+        [  --disable-rivet-commands-export to prevent export from ::rivet namespace],
+        [ rivet_commands_export=$enable_rivet_commands_export ],
+        [ rivet_commands_export="yes"]
+    )
+
+    AC_MSG_CHECKING(whether the commands in ::rivet namespace will be exported)
+    if test "$rivet_commands_export" = "yes"; then
+        AC_MSG_RESULT([yes])
+        AC_DEFINE(NAMESPACE_EXPORT,1,[commands will be exported])
+    else
+        AC_MSG_RESULT([no])
+        AC_DEFINE(NAMESPACE_EXPORT,0,[commands will not be exported])
+    fi
+])
+
+# IMPORT_RIVET_COMMANDS (--enable-import-rivet-commands).
+# For compatibility the module can be compiled and installed forcing rivet
+# to import commands from ::rivet into the global namespace.
+# Default: yes
+
+AC_DEFUN([IMPORT_RIVET_COMMANDS],[
+    AC_ARG_ENABLE(
+        import-rivet-commands,
+        [ --disable-import-rivet-commands requires explicit namespace import if required],
+        [ import_rivet_commands=$enable_import_rivet_commands],
+        [ import_rivet_commands="yes"]
+    )
+
+    AC_MSG_CHECKING(if ::rivet namespace will be automatically imported for compatibility)
+    if test "$import_rivet_commands" = "yes"; then
+        AC_MSG_RESULT([yes])
+        AC_DEFINE(NAMESPACE_IMPORT,1,[commands will be imported into the global namespace])
+    else
+        AC_MSG_RESULT([no])
+        AC_DEFINE(NAMESPACE_IMPORT,0,[good, no automatic import will be done])
+    fi
+])
+
+
 # SEPARATE_VIRTUAL_INTERPS (--enable-virtual-interps-separation)
 # Virtual hosts get their own interpreter and configuration. Different
 # applications running on different virtual hosts don't mix up variables
@@ -511,10 +577,10 @@
     virtual-interps-separation,
     [  --enable-virtual-interps-separation to turn on virtual host separation],
     [ separate_virtual_interps=$enable_virtual_interps_separation ],
-    [ separate_virtual_interps="yes"]
+    [ separate_virtual_interps="no"]
     )
 
-    AC_MSG_CHECKING(whether Rivet will crate an interpreter for each virtual host)
+    AC_MSG_CHECKING(whether Rivet will create an interpreter for each virtual host)
     if test "$separate_virtual_interps" = "yes"; then
         AC_MSG_RESULT([yes])
         AC_DEFINE(SEPARATE_VIRTUAL_INTERPS,1,[virtual hosts will have their own interp])
@@ -580,7 +646,16 @@
 VIRTUAL_INTERPS_SEPARATION
 POST_MAX_SIZE
 UPLOAD_TO_VAR
+IMPORT_RIVET_COMMANDS
+if test $import_rivet_commands = "yes"; then
+    AC_MSG_NOTICE([forcing Rivet to export commands from ::rivet namespace])
+    AC_DEFINE(NAMESPACE_EXPORT,1,[commands will be exported])
+else
+    RIVET_COMMANDS_EXPORT
+fi
+
 AC_SUBST(apache_version_dir)
+AC_SUBST(MOD_RIVET_INCLUDES)
 
 AC_DEFINE_UNQUOTED(RIVETLIB_DESTDIR,"${RIVET_TCL_TARGET}",[The path to the rivet tcl library])
 AC_DEFINE_UNQUOTED(NAMEOFEXECUTABLE,"${TCLSH_PROG}",[The path to a working tclsh executable])
diff --git a/doc/convert_examples.tcl.in b/doc/convert_examples.tcl.in
index 504df05..5f29652 100644
--- a/doc/convert_examples.tcl.in
+++ b/doc/convert_examples.tcl.in
@@ -1,7 +1,7 @@
-# convert_examples --
+# convert_examples.tcl --
 #
 #
-# reads the examples dir, checks if a file had been already converted
+# reads the examples dir, checks if a file has been already converted
 # in <target-dir> and compares their mtimes. If the file in
 # <source-dir> is more recent the target dir is recreated.
 
@@ -9,20 +9,20 @@
 # into text suitable to be inclued and displayed in XML/XHTML 
 # documentation
 
-# NOTICE: This script requires Rivet the rivet scripts and
-# libraries in the auto_path.
+# NOTICE: This script requires Rivet, its scripts and
+# libraries to be in the auto_path.
 
 # usage:
 #
 # tclsh ./convert_examples
 #
-# $Id: $
+# $Id$
 #
 
 lappend auto_path @RIVET_TCL_TARGET@
 lappend auto_path [file join @RIVET_TCL_TARGET@ rivet-tcl]
 
-package require Rivet
+package require rivetlib
 
 set source_dir examples
 set target_dir examples-sgml
@@ -44,12 +44,11 @@
 
         puts "$example needs rebuild"
         
-        set example_text [read_file $example]
+        set example_text [::rivet::read_file $example]
 
         set example_sgml_fid [open $example_sgml w+]
-        puts $example_sgml_fid [escape_sgml_chars $example_text]
+        puts $example_sgml_fid [::rivet::escape_sgml_chars $example_text]
         close $example_sgml_fid
-
     }
 
 }
diff --git a/doc/examples-sgml/download.tcl b/doc/examples-sgml/download.tcl
index 444bb87..6dd5b1b 100644
--- a/doc/examples-sgml/download.tcl
+++ b/doc/examples-sgml/download.tcl
@@ -1,7 +1,7 @@
 # Code example for the transmission of a pdf file. 
 
-if {[var exists pdfname]} {
-    set pdfname [var get pdfname]
+if {[::rivet::var exists pdfname]} {
+    set pdfname [::rivet::var get pdfname]
 
 # let&#39;s build the full path to the pdf file. The &#39;pdf_repository&#39;
 # directory must be readable by the apache children
@@ -14,9 +14,9 @@
 # original one. In this case, this is the point where a new file name
 # must be generated.
 
-	headers type			        &quot;application/pdf&quot;
-	headers add Content-Disposition &quot;attachment; filename=${pdfname}.pdf&quot;
-	headers add Content-Description &quot;PDF Document&quot;
+        ::rivet::headers type                       &quot;application/pdf&quot;
+        ::rivet::headers add Content-Disposition    &quot;attachment; filename=${pdfname}.pdf&quot;
+        ::rivet::headers add Content-Description    &quot;PDF Document&quot;
 
 # The pdf is read and stored in a Tcl variable. The file handle is
 # configured for a binary read: we are just shipping raw data to a
@@ -24,21 +24,21 @@
 # that is able to retrieve the data to be sent from any data source
 # (e.g. database, external program, other Tcl code)
 
-	set paper	    [open $pdf_full_path r]
-	fconfigure	    $paper -translation binary
-	set pdf		    [read $paper]
-	close $paper
+        set paper       [open $pdf_full_path r]
+        fconfigure      $paper -translation binary
+        set pdf         [read $paper]
+        close $paper
 
 # Now we got the data: let&#39;s tell the client how many bytes we are
 # about to send (useful for the download progress bar of a dialog box)
 
-	headers add Content-Length  [string length $pdf]
+        ::rivet::headers add Content-Length  [string length $pdf]
 
 # Let&#39;s send the actual file content
 
-	puts $pdf
+        puts $pdf
     } else {
-	source pdf_not_found_error.rvt
+        source pdf_not_found_error.rvt
     }
 } else {
     source parameter_not_defined_error.rvt
diff --git a/doc/examples-sgml/rivet_web_service.tcl b/doc/examples-sgml/rivet_web_service.tcl
index f60e485..973faf4 100644
--- a/doc/examples-sgml/rivet_web_service.tcl
+++ b/doc/examples-sgml/rivet_web_service.tcl
@@ -12,16 +12,17 @@
 
 # A pseudo database. rec_id matches a record in the db
 
-set composers [dict create  1 { first_name Claudio middle_name &quot;&quot; last_name Monteverdi  \
-                                lifespan 1567-1643 era Renaissance/Baroque}             \
-                            2 { first_name Johann middle_name Sebastian last_name Bach  \
-                                lifespan 1685-1750 era Baroque }                        \
-                            3 { first_name Ludwig middle_name &quot;&quot; last_name &quot;van Beethoven&quot; \
-                                lifespan 1770-1827 era Classical/Romantic}              \
-                            4 { first_name Wolfgang middle_name Amadeus last_name Mozart \
-                                lifespan 1756-1791 era Classical }                      \
-                            5 { first_name Robert middle_name &quot;&quot; last_name Schumann     \
-                                lifespan 1810-1856 era Romantic} ]
+set composers [dict create  \
+                1 {first_name Claudio middle_name &quot;&quot; last_name Monteverdi   \
+                    lifespan 1567-1643 era Renaissance/Baroque}             \
+                2 {first_name Johann middle_name Sebastian last_name Bach   \
+                    lifespan 1685-1750 era Baroque }                        \
+                3 {first_name Ludwig middle_name &quot;&quot; last_name &quot;van Beethoven&quot; \
+                    lifespan 1770-1827 era Classical/Romantic}              \
+                4 {first_name Wolfgang middle_name Amadeus last_name Mozart \
+                    lifespan 1756-1791 era Classical }                      \
+                5 {first_name Robert middle_name &quot;&quot; last_name Schumann      \
+                    lifespan 1810-1856 era Romantic} ]
 
 # we use the &#39;load&#39; argument in order to determine the type of query
 #
@@ -29,35 +30,34 @@
 # load=composer&amp;amp;res_id=&lt;id&gt;: the script is supposed to return the record
 #               having &lt;id&gt; as record id
 
-if {[var exists load]} {
+if {[::rivet::var exists load]} {
 
 # the xml declaration is common to every message (error messages included)
 
     set xml &quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;ISO-8859-1\&quot;?&gt;\n&quot;
-    switch [var get load] {
+    switch [::rivet::var get load] {
         catalog {
             append xml &quot;&lt;catalog&gt;\n&quot;
             foreach nm [dict keys $composers] {
-            set first_name [dict get $composers $nm first_name]
-            set middle_name [dict get $composers $nm middle_name]
-            set last_name  [dict get $composers $nm last_name]
+                set first_name  [dict get $composers $nm first_name]
+                set middle_name [dict get $composers $nm middle_name]
+                set last_name   [dict get $composers $nm last_name]
                 append xml &quot;    &lt;composer key=\&quot;$nm\&quot;&gt;$first_name &quot;
-            if {[string length [string trim $middle_name]] &gt; 0} {
-                append xml &quot;$middle_name &quot;
-            }
-            append xml &quot;$last_name&lt;/composer&gt;\n&quot;
+                if {[string length [string trim $middle_name]] &gt; 0} {
+                    append xml &quot;$middle_name &quot;
+                }
+                append xml &quot;$last_name&lt;/composer&gt;\n&quot;
             }
             append xml &quot;&lt;/catalog&gt;\n&quot;
         }
         composer {
             append xml &quot;&lt;composer&gt;\n&quot;
-            if {[var exists rec_id]} {
-                set rec_id [var get rec_id]
+            if {[::rivet::var exists rec_id]} {
+                set rec_id [::rivet::var get rec_id]
                 if {[dict exists $composers $rec_id]} {
                     foreach {k v} [dict get $composers $rec_id] {
                         append xml &quot;&lt;$k&gt;$v&lt;/$k&gt;\n&quot;
                     }
-
                 }
             }
             append xml &quot;&lt;/composer&gt;\n&quot;
@@ -67,8 +67,8 @@
 # we have to tell the client this is an XML message. Failing to do so
 # would result in an XMLResponse property set to null
 
-    headers type &quot;text/xml&quot;
-    headers add Content-Length [string length $xml]
+    ::rivet::headers type &quot;text/xml&quot;
+    ::rivet::headers add Content-Length [string length $xml]
     puts $xml
 }
 
diff --git a/doc/examples-sgml/upload.rvt b/doc/examples-sgml/upload.rvt
index 9391c43..1535568 100644
--- a/doc/examples-sgml/upload.rvt
+++ b/doc/examples-sgml/upload.rvt
@@ -1,6 +1,6 @@
 &lt;?
-upload save MyUpload /tmp/uploadfiles/file1
-puts &quot;Saved file [upload filename MyUpload] \
-	([upload size MyUpload] bytes) to server&quot;
+::rivet::upload save MyUpload /tmp/uploadfiles/file1
+puts &quot;Saved file [::rivet::upload filename MyUpload] \
+	([::rivet::upload size MyUpload] bytes) to server&quot;
 ?&gt;
 
diff --git a/doc/examples-sgml/vars.rvt b/doc/examples-sgml/vars.rvt
index 0860bce..dd668a0 100644
--- a/doc/examples-sgml/vars.rvt
+++ b/doc/examples-sgml/vars.rvt
@@ -1,57 +1,57 @@
 &lt;?
 set errlist {}
-if { [var exists title] } {
-    set title [var get title]
+if { [::rivet::var exists title] } {
+    set title [::rivet::var get title]
 } else {
     set errlist &quot;You need to enter a title&quot;
 }
 
-if { [var exists salary] } {
-    set salary [var get salary]
+if { [::rivet::var exists salary] } {
+    set salary [::rivet::var get salary]
     if { ! [string is digit $salary] } {
-	lappend errlist &quot;Salary must be a number&quot;
+        lappend errlist &quot;Salary must be a number&quot;
     }
 } else {
     lappend errlist &quot;You need to enter a salary&quot;
 }
 
-if { [var exists boss] } {
-    set boss [var get boss]
+if { [::rivet::var exists boss] } {
+    set boss [::rivet::var get boss]
 } else {
     set boss &quot;Mr. Burns&quot;
 }
 
-if { [var exists skills] } {
-    set skills [var list skills]
+if { [::rivet::var exists skills] } {
+    set skills [::rivet::var list skills]
 } else {
     lappend errlist &quot;You need to enter some skills&quot;
 }
 
 if { [llength $errlist] != 0 } {
     foreach err $errlist {
-	puts &quot;&lt;b&gt; $err &lt;/b&gt;&quot;
+        puts &quot;&lt;b&gt; $err &lt;/b&gt;&quot;
     }
 } else {
     puts &quot;Thanks for the information!&quot;
     ?&gt;
     &lt;table&gt;
       &lt;tbody&gt;
-	&lt;tr&gt;
-	  &lt;td&gt;&lt;b&gt;Title:&lt;/b&gt;&lt;/td&gt;
-	  &lt;td&gt;&lt;? puts $title ?&gt;&lt;/td&gt;
-	&lt;/tr&gt;
-	&lt;tr&gt;
-	  &lt;td&gt;&lt;b&gt;Boss:&lt;/b&gt;&lt;/td&gt;
-	  &lt;td&gt;&lt;? puts $boss ?&gt;&lt;/td&gt;
-	&lt;/tr&gt;
-	&lt;tr&gt;
-	  &lt;td&gt;&lt;b&gt;Salary:&lt;/b&gt;&lt;/td&gt;
-	  &lt;td&gt;&lt;? puts $salary ?&gt;&lt;/td&gt;
-	&lt;/tr&gt;
-	&lt;tr&gt;
-	  &lt;td&gt;&lt;b&gt;Skills:&lt;/b&gt;&lt;/td&gt;
-	  &lt;td&gt;&lt;? puts $skills ?&gt;&lt;/td&gt;
-	&lt;/tr&gt;
+        &lt;tr&gt;
+          &lt;td&gt;&lt;b&gt;Title:&lt;/b&gt;&lt;/td&gt;
+          &lt;td&gt;&lt;? puts $title ?&gt;&lt;/td&gt;
+        &lt;/tr&gt;
+        &lt;tr&gt;
+          &lt;td&gt;&lt;b&gt;Boss:&lt;/b&gt;&lt;/td&gt;
+          &lt;td&gt;&lt;? puts $boss ?&gt;&lt;/td&gt;
+        &lt;/tr&gt;
+        &lt;tr&gt;
+          &lt;td&gt;&lt;b&gt;Salary:&lt;/b&gt;&lt;/td&gt;
+          &lt;td&gt;&lt;? puts $salary ?&gt;&lt;/td&gt;
+        &lt;/tr&gt;
+        &lt;tr&gt;
+          &lt;td&gt;&lt;b&gt;Skills:&lt;/b&gt;&lt;/td&gt;
+          &lt;td&gt;&lt;? puts $skills ?&gt;&lt;/td&gt;
+        &lt;/tr&gt;
       &lt;/tbody&gt;
     &lt;/table&gt;
     &lt;?
diff --git a/doc/examples/download.tcl b/doc/examples/download.tcl
index a8508f1..ca57030 100644
--- a/doc/examples/download.tcl
+++ b/doc/examples/download.tcl
@@ -1,7 +1,7 @@
 # Code example for the transmission of a pdf file. 
 
-if {[var exists pdfname]} {
-    set pdfname [var get pdfname]
+if {[::rivet::var exists pdfname]} {
+    set pdfname [::rivet::var get pdfname]
 
 # let's build the full path to the pdf file. The 'pdf_repository'
 # directory must be readable by the apache children
@@ -14,9 +14,9 @@
 # original one. In this case, this is the point where a new file name
 # must be generated.
 
-	headers type			        "application/pdf"
-	headers add Content-Disposition "attachment; filename=${pdfname}.pdf"
-	headers add Content-Description "PDF Document"
+        ::rivet::headers type                       "application/pdf"
+        ::rivet::headers add Content-Disposition    "attachment; filename=${pdfname}.pdf"
+        ::rivet::headers add Content-Description    "PDF Document"
 
 # The pdf is read and stored in a Tcl variable. The file handle is
 # configured for a binary read: we are just shipping raw data to a
@@ -24,21 +24,21 @@
 # that is able to retrieve the data to be sent from any data source
 # (e.g. database, external program, other Tcl code)
 
-	set paper	    [open $pdf_full_path r]
-	fconfigure	    $paper -translation binary
-	set pdf		    [read $paper]
-	close $paper
+        set paper       [open $pdf_full_path r]
+        fconfigure      $paper -translation binary
+        set pdf         [read $paper]
+        close $paper
 
 # Now we got the data: let's tell the client how many bytes we are
 # about to send (useful for the download progress bar of a dialog box)
 
-	headers add Content-Length  [string length $pdf]
+        ::rivet::headers add Content-Length  [string length $pdf]
 
 # Let's send the actual file content
 
-	puts $pdf
+        puts $pdf
     } else {
-	source pdf_not_found_error.rvt
+        source pdf_not_found_error.rvt
     }
 } else {
     source parameter_not_defined_error.rvt
diff --git a/doc/examples/rivet_web_service.tcl b/doc/examples/rivet_web_service.tcl
index d67bfcf..7271a33 100644
--- a/doc/examples/rivet_web_service.tcl
+++ b/doc/examples/rivet_web_service.tcl
@@ -12,16 +12,17 @@
 
 # A pseudo database. rec_id matches a record in the db
 
-set composers [dict create  1 { first_name Claudio middle_name "" last_name Monteverdi  \
-                                lifespan 1567-1643 era Renaissance/Baroque}             \
-                            2 { first_name Johann middle_name Sebastian last_name Bach  \
-                                lifespan 1685-1750 era Baroque }                        \
-                            3 { first_name Ludwig middle_name "" last_name "van Beethoven" \
-                                lifespan 1770-1827 era Classical/Romantic}              \
-                            4 { first_name Wolfgang middle_name Amadeus last_name Mozart \
-                                lifespan 1756-1791 era Classical }                      \
-                            5 { first_name Robert middle_name "" last_name Schumann     \
-                                lifespan 1810-1856 era Romantic} ]
+set composers [dict create  \
+                1 {first_name Claudio middle_name "" last_name Monteverdi   \
+                    lifespan 1567-1643 era Renaissance/Baroque}             \
+                2 {first_name Johann middle_name Sebastian last_name Bach   \
+                    lifespan 1685-1750 era Baroque }                        \
+                3 {first_name Ludwig middle_name "" last_name "van Beethoven" \
+                    lifespan 1770-1827 era Classical/Romantic}              \
+                4 {first_name Wolfgang middle_name Amadeus last_name Mozart \
+                    lifespan 1756-1791 era Classical }                      \
+                5 {first_name Robert middle_name "" last_name Schumann      \
+                    lifespan 1810-1856 era Romantic} ]
 
 # we use the 'load' argument in order to determine the type of query
 #
@@ -29,35 +30,34 @@
 # load=composer&amp;res_id=<id>: the script is supposed to return the record
 #               having <id> as record id
 
-if {[var exists load]} {
+if {[::rivet::var exists load]} {
 
 # the xml declaration is common to every message (error messages included)
 
     set xml "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
-    switch [var get load] {
+    switch [::rivet::var get load] {
         catalog {
             append xml "<catalog>\n"
             foreach nm [dict keys $composers] {
-            set first_name [dict get $composers $nm first_name]
-            set middle_name [dict get $composers $nm middle_name]
-            set last_name  [dict get $composers $nm last_name]
+                set first_name  [dict get $composers $nm first_name]
+                set middle_name [dict get $composers $nm middle_name]
+                set last_name   [dict get $composers $nm last_name]
                 append xml "    <composer key=\"$nm\">$first_name "
-            if {[string length [string trim $middle_name]] > 0} {
-                append xml "$middle_name "
-            }
-            append xml "$last_name</composer>\n"
+                if {[string length [string trim $middle_name]] > 0} {
+                    append xml "$middle_name "
+                }
+                append xml "$last_name</composer>\n"
             }
             append xml "</catalog>\n"
         }
         composer {
             append xml "<composer>\n"
-            if {[var exists rec_id]} {
-                set rec_id [var get rec_id]
+            if {[::rivet::var exists rec_id]} {
+                set rec_id [::rivet::var get rec_id]
                 if {[dict exists $composers $rec_id]} {
                     foreach {k v} [dict get $composers $rec_id] {
                         append xml "<$k>$v</$k>\n"
                     }
-
                 }
             }
             append xml "</composer>\n"
@@ -67,8 +67,8 @@
 # we have to tell the client this is an XML message. Failing to do so
 # would result in an XMLResponse property set to null
 
-    headers type "text/xml"
-    headers add Content-Length [string length $xml]
+    ::rivet::headers type "text/xml"
+    ::rivet::headers add Content-Length [string length $xml]
     puts $xml
 }
 
diff --git a/doc/examples/upload.rvt b/doc/examples/upload.rvt
index 31b8150..e92bceb 100644
--- a/doc/examples/upload.rvt
+++ b/doc/examples/upload.rvt
@@ -1,5 +1,5 @@
 <?
-upload save MyUpload /tmp/uploadfiles/file1
-puts "Saved file [upload filename MyUpload] \
-	([upload size MyUpload] bytes) to server"
+::rivet::upload save MyUpload /tmp/uploadfiles/file1
+puts "Saved file [::rivet::upload filename MyUpload] \
+	([::rivet::upload size MyUpload] bytes) to server"
 ?>
diff --git a/doc/examples/vars.rvt b/doc/examples/vars.rvt
index 9b551c0..b1091a6 100644
--- a/doc/examples/vars.rvt
+++ b/doc/examples/vars.rvt
@@ -1,57 +1,57 @@
 <?
 set errlist {}
-if { [var exists title] } {
-    set title [var get title]
+if { [::rivet::var exists title] } {
+    set title [::rivet::var get title]
 } else {
     set errlist "You need to enter a title"
 }
 
-if { [var exists salary] } {
-    set salary [var get salary]
+if { [::rivet::var exists salary] } {
+    set salary [::rivet::var get salary]
     if { ! [string is digit $salary] } {
-	lappend errlist "Salary must be a number"
+        lappend errlist "Salary must be a number"
     }
 } else {
     lappend errlist "You need to enter a salary"
 }
 
-if { [var exists boss] } {
-    set boss [var get boss]
+if { [::rivet::var exists boss] } {
+    set boss [::rivet::var get boss]
 } else {
     set boss "Mr. Burns"
 }
 
-if { [var exists skills] } {
-    set skills [var list skills]
+if { [::rivet::var exists skills] } {
+    set skills [::rivet::var list skills]
 } else {
     lappend errlist "You need to enter some skills"
 }
 
 if { [llength $errlist] != 0 } {
     foreach err $errlist {
-	puts "<b> $err </b>"
+        puts "<b> $err </b>"
     }
 } else {
     puts "Thanks for the information!"
     ?>
     <table>
       <tbody>
-	<tr>
-	  <td><b>Title:</b></td>
-	  <td><? puts $title ?></td>
-	</tr>
-	<tr>
-	  <td><b>Boss:</b></td>
-	  <td><? puts $boss ?></td>
-	</tr>
-	<tr>
-	  <td><b>Salary:</b></td>
-	  <td><? puts $salary ?></td>
-	</tr>
-	<tr>
-	  <td><b>Skills:</b></td>
-	  <td><? puts $skills ?></td>
-	</tr>
+        <tr>
+          <td><b>Title:</b></td>
+          <td><? puts $title ?></td>
+        </tr>
+        <tr>
+          <td><b>Boss:</b></td>
+          <td><? puts $boss ?></td>
+        </tr>
+        <tr>
+          <td><b>Salary:</b></td>
+          <td><? puts $salary ?></td>
+        </tr>
+        <tr>
+          <td><b>Skills:</b></td>
+          <td><? puts $skills ?></td>
+        </tr>
       </tbody>
     </table>
     <?
diff --git a/doc/rivet.xml b/doc/rivet.xml
index e90fa2d..ca8072f 100644
--- a/doc/rivet.xml
+++ b/doc/rivet.xml
@@ -2,29 +2,29 @@
 
 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
   "http://www.oasis-open.org/committees/docbook/xml/4.1.2/docbookx.dtd" [
-    <!ENTITY hello.rvt		   SYSTEM	"examples-sgml/hello.rvt" >
-    <!ENTITY table.rvt		   SYSTEM  	"examples-sgml/table.rvt" >
-    <!ENTITY vars.html		   SYSTEM  	"examples-sgml/vars.html" >
-    <!ENTITY vars.rvt		   SYSTEM	"examples-sgml/vars.rvt" >
-    <!ENTITY upload.html	   SYSTEM	"examples-sgml/upload.html" >
-    <!ENTITY upload.rvt		   SYSTEM	"examples-sgml/upload.rvt" >
-    <!ENTITY download.tcl	   SYSTEM	"examples-sgml/download.tcl" >
+    <!ENTITY hello.rvt		        SYSTEM	"examples-sgml/hello.rvt" >
+    <!ENTITY table.rvt		        SYSTEM  "examples-sgml/table.rvt" >
+    <!ENTITY vars.html		        SYSTEM  "examples-sgml/vars.html" >
+    <!ENTITY vars.rvt		        SYSTEM	"examples-sgml/vars.rvt" >
+    <!ENTITY upload.html	        SYSTEM	"examples-sgml/upload.html" >
+    <!ENTITY upload.rvt		        SYSTEM	"examples-sgml/upload.rvt" >
+    <!ENTITY download.tcl	        SYSTEM	"examples-sgml/download.tcl" >
     <!ENTITY rivet_web_service.tcl  SYSTEM  "examples-sgml/rivet_web_service.tcl" >
-    <!ENTITY intro.xml		   SYSTEM  	"xml/intro.xml" >
-    <!ENTITY install.xml	   SYSTEM  	"xml/install.xml" >
-    <!ENTITY directives.xml	SYSTEM  	"xml/directives.xml" >
-    <!ENTITY commands.xml	   SYSTEM  	"xml/commands.xml" >
-    <!ENTITY examples.xml     SYSTEM   "xml/examples.xml" >
-    <!ENTITY packages.xml	   SYSTEM   "xml/packages.xml" >
-    <!ENTITY dio.xml		    	SYSTEM  	"xml/dio.xml" >
-    <!ENTITY diodisplay.xml	SYSTEM  	"xml/diodisplay.xml" >
-    <!ENTITY session.xml	   SYSTEM  	"xml/session.xml" >
-    <!ENTITY form.xml		   SYSTEM  	"xml/form.xml" >
-    <!ENTITY calendar.xml	   SYSTEM  	"xml/calendar.xml" >
-    <!ENTITY help.xml		   SYSTEM  	"xml/help.xml" >
-    <!ENTITY internals.xml	   SYSTEM  	"xml/internals.xml" >
-    <!ENTITY upgrade.xml	   SYSTEM  	"xml/upgrade.xml" >
-    <!ENTITY request.xml	 	SYSTEM	"xml/request.xml" >
+    <!ENTITY intro.xml		        SYSTEM  "xml/intro.xml" >
+    <!ENTITY install.xml	        SYSTEM  "xml/install.xml" >
+    <!ENTITY directives.xml	        SYSTEM  "xml/directives.xml" >
+    <!ENTITY commands.xml           SYSTEM  "xml/commands.xml" >
+    <!ENTITY examples.xml           SYSTEM  "xml/examples.xml" >
+    <!ENTITY packages.xml           SYSTEM  "xml/packages.xml" >
+    <!ENTITY dio.xml                SYSTEM  "xml/dio.xml" >
+    <!ENTITY diodisplay.xml         SYSTEM  "xml/diodisplay.xml" >
+    <!ENTITY session.xml            SYSTEM  "xml/session.xml" >
+    <!ENTITY form.xml               SYSTEM  "xml/form.xml" >
+    <!ENTITY calendar.xml           SYSTEM  "xml/calendar.xml" >
+    <!ENTITY help.xml               SYSTEM  "xml/help.xml" >
+    <!ENTITY internals.xml          SYSTEM  "xml/internals.xml" >
+    <!ENTITY upgrade.xml            SYSTEM  "xml/upgrade.xml" >
+    <!ENTITY request.xml            SYSTEM  "xml/request.xml" >
 ]>
 
 <!--
@@ -95,7 +95,7 @@
    &directives.xml;
 
     <!-- Commands -->
-   &commands.xml;
+    &commands.xml;
 
     <!-- examples-sgml -->
    &examples.xml;
diff --git a/doc/xml/commands.xml b/doc/xml/commands.xml
index 2d0673b..2b9d2f0 100644
--- a/doc/xml/commands.xml
+++ b/doc/xml/commands.xml
@@ -1,6 +1,31 @@
 <section id="commands">
-    <title>Rivet Tcl Commands and Variables</title>
-
+	<title>Rivet Tcl Commands and Variables</title>
+	<section>
+		<para>
+			Starting with version 2.1.0 Rivet command set moved into the 
+			<command>::rivet</command> namespace.
+		</para>
+		<para>
+			In order to preserve out of the box compatibility with existing scripts,
+			Rivet exports commands by default and makes them available for import 
+			into any namespace (global namespace included). 
+			Rivet's build system can be told not to export the command set by
+			passing the switch <command>--disable-rivet-commands-export</command> 
+			to 'configure'. In the future we may change this option's default.
+		</para>
+		<para>
+			Commands must be imported into another namespace with the
+			command:
+		</para>
+		<para>
+			<command>namespace import -force ::rivet::*</command>
+		</para>
+		<para>
+			Whenever a new application is being developed and compatibility
+			issues can be confined within specific files, it is recommended
+			that commands be specified with their fully qualified names.
+		</para>
+	</section>
 	<refentry id="abort_code">
 		<refnamediv>
 			<refname>abort_code</refname>
@@ -11,959 +36,988 @@
 		</refnamediv>
 		<refsynopsisdiv>
 			<cmdsynopsis>
-			  <command>abort_code</command>
+			  <command>::rivet::abort_code</command>
 			</cmdsynopsis>
-      </refsynopsisdiv>
-      <refsect1>
+		</refsynopsisdiv>
+		<refsect1>
 			<title>Description</title> 
 			<para>
-				Usage of this command is meaningful only in scripts run as
+				Usage of this command is meaningful only in code that runs as
 				AbortScript or AfterEveryScript. 
 				<command>abort_code</command> returns the value of the optional 
-				parameter passed to <command>abort_page</command> earlier during
+				parameter passed to <command>abort_page</command> earlier in
 				the same request processing.
 			</para>
-      </refsect1>
+		</refsect1>
 	</refentry>
-    <refentry id="abort_page">
-        <refnamediv>
-			<refname>abort_page</refname>
-			<refpurpose>
-				Stops outputing data to web page, similar in
-			  	purpose to PHP's <command>die</command> command.
-			</refpurpose>
-        </refnamediv>
+	<refentry id="abort_page">
+	    <refnamediv>
+		<refname>abort_page</refname>
+		<refpurpose>
+		    Stops outputting data to web page, similar in
+		    purpose to PHP's <command>die</command> command.
+		</refpurpose>
+	    </refnamediv>
 
-        <refsynopsisdiv>
-			<cmdsynopsis>
-			  	<command>abort_page</command>
-			  	<group choice="req">
-					<arg><replaceable>abort code</replaceable></arg>
-					<arg><replaceable>-aborting</replaceable></arg>
-				</group>
-			</cmdsynopsis>
-        </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::abort_page</command>
+		    <group choice="req">
+			<arg><replaceable>abort code</replaceable></arg>
+			<arg><replaceable>-aborting</replaceable></arg>
+		    </group>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
+	    <refsect1>
+		<title>Description</title> 
+		<para>
+		    This command flushes the output buffer and stops the Tcl 
+		    script from sending any more data to the client.
+		    A normal Tcl script might use the
+		    <command>exit</command> command, but that cannot be used in
+		    Rivet without actually exiting the apache child
+		    process!
+		    <command>abort_page</command> triggers
+		    the execution of an optional AbortScript that has to be
+		    specified in the configuration. The value of the
+		    argument <arg>abort code</arg> can be retrieved with the 
+		    <command>abort_code</command> command during the
+		    execution of AbortScript or AfterEveryScript, allowing 
+		    the script to take appropriate actions in order to deal
+		    with the cause of the abort. 
+		</para>
+		<para>
+		    When passed the argument <option>-aborting</option> the
+		    command returns 1 if <option>abort_page</option>
+		    had been called earlier in the request processing, thus
+		    providing a tool for code in AfterEveryScript to tell
+		    if the an abort condition took place.
+		</para>
+	  </refsect1>
+	</refentry>
 
-        <refsect1>
-			<title>Description</title> 
-			<para>
-				This command flushes the output buffer and stops the Tcl 
-				script from sending any more data to the client.
-				A normal Tcl script might use the
-				<command>exit</command> command, but that cannot be used in
-				Rivet without actually exiting the apache child
-				process!
-				<command>abort_page</command> triggers
-				the execution of an optional AbortScript that has to be
-				specified in the configuration. The value of the
-				argument <arg>abort code</arg> can be retrieved with the 
-				<command>abort_code</command> command during the
-				execution of AbortScript or AfterEveryScript, allowing 
-				the script to take appropriate actions in order to deal
-				with the cause of the abort. 
-			</para>
-			<para>
-				When passed the argument <command>-aborting</command> the
-				command returns 1 if <option>abort_page</option>
-				had been called earlier in the request processing, thus
-				providing a tool for code in AfterEveryScript to tell
-				if the an abort condition took place.
-			</para>
-        </refsect1>
-    </refentry>
 
-    <refentry id="apache_log_error">
-      <refnamediv>
-	<refname>apache_log_error</refname>
-	<refpurpose>log messages to the Apache error log</refpurpose>
-      </refnamediv>
+	<refentry id="apache_log_error">
+	    <refnamediv>
+		<refname>apache_log_error</refname>
+		<refpurpose>log messages to the Apache error log</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-	<cmdsynopsis>
-	  <command>apache_log_error</command>
-	    <arg>priority</arg>
-	    <arg>message</arg>
-	</cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::apache_log_error</command>
+		    <arg>priority</arg>
+		    <arg>message</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsect1>
-	<title>Description</title>
-	<para>The apache_log_error command logs a message to the 
-	  Apache error log, whose name and location have been
-	  set by the <option>ErrorLog</option> directive.
-	</para>
-	<para>
-	Priority must be one of
-	    <option>debug</option>,
-	    <option>info</option>,
-	    <option>notice</option>,
-	    <option>warning</option>,
-	    <option>err</option>,
-	    <option>crit</option>,
-	    <option>alert</option>, or
-	    <option>emerg</option>.
-	</para>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    The apache_log_error command logs a message to the 
+		    Apache error log, whose name and location have been
+		    set by the <option>ErrorLog</option> directive.
+		</para>
+		<para>
+		    Priority must be one of
+			    <option>debug</option>,
+			    <option>info</option>,
+			    <option>notice</option>,
+			    <option>warning</option>,
+			    <option>err</option>,
+			    <option>crit</option>,
+			    <option>alert</option>, or
+			    <option>emerg</option>.
+		</para>
+	    </refsect1>
+	</refentry>
 
-    <refentry id="apache_table">
-      <refnamediv>
-        <refname>apache_table</refname>
-        <refpurpose>access and manipulate Apache tables in the request structure.</refpurpose>
-      </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>apache_table</command>
-          <group choice="req">
-            <arg>get</arg>
-            <arg>set</arg>
-            <arg>exists</arg>
-            <arg>unset</arg>
-            <arg>names</arg>
-            <arg>array_get</arg>
-            <arg>clear</arg>
-          </group>
-        </cmdsynopsis>
-    </refsynopsisdiv>
+	<refentry id="apache_table">
+	    <refnamediv>
+		<refname>apache_table</refname>
+		<refpurpose>access and manipulate Apache tables in the request structure.</refpurpose>
+	    </refnamediv>
 
-    <refsect1>
-    <title>Description</title>
-        <para>The apache_table command is for accessing and manipulating
-          Apache tables in the request structure.
-        </para>
-        <para>
-        The table name must be one of
-            <option>notes</option>,
-            <option>headers_in</option>,
-            <option>headers_out</option>,
-            <option>err_headers_out</option>, or
-            <option>subprocess_env</option>.
-        </para>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::apache_table</command>
+		    <group choice="req">
+			<arg>get</arg>
+			<arg>set</arg>
+			<arg>exists</arg>
+			<arg>unset</arg>
+			<arg>names</arg>
+			<arg>array_get</arg>
+			<arg>clear</arg>
+		    </group>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-	<variablelist>
-	  <varlistentry>
-	    <term>
-	        <cmdsynopsis>
-                <command>apache_table</command>
-                <arg choice="plain">get</arg>
-                <arg><replaceable>tablename</replaceable></arg>
-                <arg><replaceable>key</replaceable></arg>
-            </cmdsynopsis>
-        </term>
-        <listitem>
-            <para>
-                When given the name of an Apache table
-                <option><replaceable>tablename</replaceable></option>
-                and the name of a key
-                <option><replaceable>tablename</replaceable></option>,
-                returns the value of the key in the table, or an empty
-                string.
-            </para>
-        </listitem>
-        </varlistentry>
-        <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>apache_table</command>
-            <arg choice="plain">set</arg>
-            <arg><replaceable>tablename</replaceable></arg>
-            <arg><replaceable>key</replaceable></arg>
-            <arg><replaceable>value</replaceable></arg>
-	      </cmdsynopsis>
-	      <cmdsynopsis>
-		<command>apache_table</command>
-		<arg choice="plain">set</arg>
-		<arg><replaceable>tablename</replaceable></arg>
-		<arg><replaceable>list</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Stores the
-		<option><replaceable>value</replaceable></option> in
-		the table
-		<option><replaceable>tablename</replaceable></option>
-		under the key
-		<option><replaceable>key</replaceable></option>.
-	      </para>
-	      <para>
-	            For the list form,
-                <option><replaceable>list</replaceable></option> contains
-                a list of zero or more pairs of key-value pairs to be
-                set into the table
-                <option><replaceable>tablename</replaceable></option>.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>apache_table</command>
-		<arg choice="plain">exists</arg>
-		<arg><replaceable>tablename</replaceable></arg>
-		<arg><replaceable>key</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Returns 1 if the specified key,
-		<option><replaceable>key</replaceable></option>,
-		exists in table
-		<option><replaceable>tablename</replaceable></option>,
-		else 0.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>apache_table</command>
-		<arg choice="plain">unset</arg>
-		<arg><replaceable>tablename</replaceable></arg>
-		<arg><replaceable>key</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-	        Removes the key-value pair referenced by
-		<option><replaceable>key</replaceable></option>
-		from the table
-		<option><replaceable>tablename</replaceable></option>.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>apache_table</command>
-		<arg choice="plain">names</arg>
-		<arg><replaceable>tablename</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Returns a list of all of the keys present in the table
-		<option><replaceable>tablename</replaceable></option>.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>apache_table</command>
-		<arg choice="plain">array_get</arg>
-		<arg><replaceable>tablename</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-	        Returns a list of key-value pairs from the table
-		<option><replaceable>tablename</replaceable></option>.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>apache_table</command>
-		<arg choice="plain">clear</arg>
-		<arg><replaceable>tablename</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Clears the contents of the specified table.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	</variablelist>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    The apache_table command is for accessing and manipulating
+		    Apache tables in the request structure.
+		</para>
+		<para>
+		    The table name must be one of
+		    <option>notes</option>,
+		    <option>headers_in</option>,
+		    <option>headers_out</option>,
+		    <option>err_headers_out</option>, or
+		    <option>subprocess_env</option>.
+		</para>
 
-    <refentry id="clock_to_rfc">
-      <refnamediv>
-	<refname>clock_to_rfc850_gmt</refname>
-	<refpurpose>create a rfc850 time from [clock seconds].</refpurpose>
-      </refnamediv>
+		<variablelist>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">get</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+				<arg><replaceable>key</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				When given the name of an Apache table
+				<option><replaceable>tablename</replaceable></option>
+				and the name of a key
+				<option><replaceable>tablename</replaceable></option>,
+				returns the value of the key in the table, or an empty
+				string.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">set</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+				<arg><replaceable>key</replaceable></arg>
+				<arg><replaceable>value</replaceable></arg>
+			    </cmdsynopsis>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">set</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+				<arg><replaceable>list</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Stores the <option><replaceable>value</replaceable></option> in
+				the table <option><replaceable>tablename</replaceable></option>
+				under the key <option><replaceable>key</replaceable></option>.
+			    </para>
+			    <para>
+				For the list form,
+				<option><replaceable>list</replaceable></option> contains
+				a list of zero or more pairs of key-value pairs to be
+				set into the table
+				<option><replaceable>tablename</replaceable></option>.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">exists</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+				<arg><replaceable>key</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns 1 if the specified key,
+				<option><replaceable>key</replaceable></option>,
+				exists in table
+				<option><replaceable>tablename</replaceable></option>,
+				else 0.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">unset</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+				<arg><replaceable>key</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Removes the key-value pair referenced by
+				<option><replaceable>key</replaceable></option>
+				from the table
+				<option><replaceable>tablename</replaceable></option>.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">names</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns a list of all of the keys present in the table
+				<option><replaceable>tablename</replaceable></option>.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">array_get</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns a list of key-value pairs from the table
+				<option><replaceable>tablename</replaceable></option>.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::apache_table</command>
+				<arg choice="plain">clear</arg>
+				<arg><replaceable>tablename</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Clears the contents of the specified table.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		</variablelist>
+	    </refsect1>
+	</refentry>
+    <!-- Reference page for command 'clock_to_rfc' -->
+	<refentry id="clock_to_rfc">
+	    <refnamediv>
+		<refname>clock_to_rfc850_gmt</refname>
+		<refpurpose>create a rfc850 time from [clock seconds].</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-	<cmdsynopsis>
-	  <command>clock_to_rfc850_gmt</command>
-	  <arg><replaceable>seconds</replaceable></arg>
-	</cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::clock_to_rfc850_gmt</command>
+		    <arg><replaceable>seconds</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsect1>
-	<title>Description</title>
-	<para>
-	  Convert an integer-seconds-since-1970 click value to
-	  RFC850 format, with the additional requirement that it be
-	  GMT only.
-	</para>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Convert an integer-seconds-since-1970 click value to
+		    RFC850 format, with the additional requirement that it be
+		    GMT only.
+		</para>
+	    </refsect1>
+	</refentry>
 
-    <refentry id="cookie">
-      <refnamediv>
-	<refname>cookie</refname>
-	<refpurpose>get and set cookies.</refpurpose>
-      </refnamediv>
+    <!-- Reference page for command 'cookie' -->
+	<refentry id="cookie">
+	    <refnamediv>
+		<refname>cookie</refname>
+		<refpurpose>get, set and delete cookies.</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-	<cmdsynopsis>
-	  <command>cookie</command>
-	  <arg>set</arg>
-	  <arg><replaceable>cookieName</replaceable></arg>
-	  <arg><replaceable><optional>cookiValue</optional></replaceable></arg>
-	  <arg>-days <replaceable>expireInDays</replaceable></arg>
-	  <arg>-hours <replaceable>expireInHours</replaceable></arg>
-	  <arg>-minutes <replaceable>expireInMinutes</replaceable></arg>
-	  <arg>-expires <replaceable>Wdy, DD-Mon-YYYY HH:MM:SS GMT</replaceable></arg>
-	  <arg>-path <replaceable>uriPathCookieAppliesTo</replaceable></arg>
-	  <arg>-secure <replaceable>1/0</replaceable></arg>
-	</cmdsynopsis>
-	<cmdsynopsis>
-	  <command>cookie</command>
-	  <arg>get</arg>
-	  <arg><replaceable>cookieName</replaceable></arg>
-	</cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::cookie</command>
+		    <arg>set</arg>
+		    <arg><replaceable>cookieName</replaceable></arg>
+		    <arg><replaceable><optional>cookiValue</optional></replaceable></arg>
+		    <arg>-days <replaceable>expireInDays</replaceable></arg>
+		    <arg>-hours <replaceable>expireInHours</replaceable></arg>
+		    <arg>-minutes <replaceable>expireInMinutes</replaceable></arg>
+		    <arg>-expires <replaceable>Wdy, DD-Mon-YYYY HH:MM:SS GMT</replaceable></arg>
+		    <arg>-path <replaceable>uriPathCookieAppliesTo</replaceable></arg>
+		    <arg>-secure <replaceable>1/0</replaceable></arg>
+		</cmdsynopsis>
+		<cmdsynopsis>
+		    <command>::rivet::cookie</command>
+		    <arg>get</arg>
+		    <arg><replaceable>cookieName</replaceable></arg>
+		</cmdsynopsis>
+		<cmdsynopsis>
+		    <command>::rivet::cookie</command>
+		    <arg>delete</arg>
+		    <arg><replaceable>cookieName</replaceable></arg>
+		</cmdsynopsis>
+		<cmdsynopsis>
+		    <command>::rivet::cookie</command>
+		    <arg>unset</arg>
+		    <arg><replaceable>cookieName</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsect1>
-	<title>Description</title>
-	<para>
-	  <command>cookie</command> gets or sets a cookie.  When you
-	  get a cookie, the command returns the value of the cookie,
-	  or an empty string if no cookie exists.
-	</para>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    <command>cookie</command> gets, sets, unsets or deletes a cookie.  When you
+		    get a cookie, the command returns the value of the cookie,
+		    or an empty string if no cookie exists.
+		</para>
+		<para>
+		    <command>cookie delete</command> will set the timeout value to -1 minutes - 
+		    deleting the cookie in the browser.
+		</para>
+		<para>
+		    <command>cookie unset</command> will remove the defined cookie in the server 
+		    (perhaps preparatory to checking/resetting the cookie).
+		</para>
+	    </refsect1>
+	</refentry>
 
 	<refentry id="debug">
-		<refnamediv>
-			<refname>debug</refname>
-			<refpurpose>
-				A command to print strings, arrays
-    			and the values of variables as specified by the arguments.
-    		</refpurpose>
-    	</refnamediv>
-    	<refsynopsisdiv>
-    		<cmdsynopsis>
-    			<command>debug</command>
-    			<arg choice="plain">-subst</arg><arg>&lt;on|off&gt;</arg>
-    			<arg choice="plain">-separator</arg><arg>&lt;string&gt;</arg>
-    			<arg choice="plain">-option</arg><arg><replaceable>&lt;value&gt;</replaceable></arg>
-    			<arg choice="plain">-option</arg><arg><replaceable>&lt;value&gt;</replaceable></arg>
-    			<arg choice="plain">...</arg>
-    		</cmdsynopsis>
-    	</refsynopsisdiv>    	
-    	
-    	<refsect1>
-    		<title>Description</title>
-    		<para>
-    			A command to make debugging more convenient print strings, arrays
-				and the values of variables as specified by the arguments.
-			</para>
-			<para>
-				Also allows the setting of an array called debug which will pick up
-				options for all debug commands.
-			</para>
-    	</refsect1>
+	    <refnamediv>
+		<refname>debug</refname>
+		<refpurpose>
+		    A command to print strings, arrays
+		    and the values of variables as specified by the arguments.
+		</refpurpose>
+	    </refnamediv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::debug</command>
+		    <arg choice="plain">-subst</arg><arg>&lt;on|off&gt;</arg>
+		    <arg choice="plain">-separator</arg><arg>&lt;string&gt;</arg>
+		    <arg choice="plain">-option</arg><arg><replaceable>&lt;value&gt;</replaceable></arg>
+		    <arg choice="plain">-option</arg><arg><replaceable>&lt;value&gt;</replaceable></arg>
+		    <arg choice="plain">...</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    A command to make debugging more convenient print strings, arrays
+		    and the values of variables as specified by the arguments.
+		</para>
+		<para>
+		    Also allows the setting of an array called debug which will pick up
+		    options for all debug commands.
+		</para>
+	    </refsect1>
 	</refentry>
 
-    <refentry id="env">
-      <refnamediv>
-	    <refname>env</refname> <refpurpose>Loads a single
-	        "environmental variable" into a Tcl variable.</refpurpose>
-      </refnamediv>
 
-      <refsynopsisdiv>
-	    <cmdsynopsis>
-	        <command>env</command>
-	        <arg><replaceable>varName</replaceable></arg>
-	    </cmdsynopsis>
-      </refsynopsisdiv>
+	<refentry id="env">
+	    <refnamediv>
+		<refname>env</refname> 
+		<refpurpose>
+		    Loads a single "environmental variable" into a Tcl variable.
+		</refpurpose>
+	    </refnamediv>
 
-      <refsect1>
-	    <title>Description</title>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::env</command>
+		    <arg><replaceable>varName</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-        <para>
-          If it is only necessary to load one environmental variable,
-          this command may be used to avoid the overhead of loading
-          and storing the entire array.
-        </para>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    If it is only necessary to load one environmental variable,
+		    this command may be used to avoid the overhead of loading
+		    and storing the entire array.
+		</para>
+	    </refsect1>
+	</refentry>
 
-    <refentry id="escape_sgml_chars">
-      <refnamediv>
-        <refname>escape_sgml_chars</refname>
-        <refpurpose>escape special SGML characters in a string.</refpurpose>
-      </refnamediv>
+	<refentry id="escape_sgml_chars">
+	    <refnamediv>
+		<refname>escape_sgml_chars</refname>
+		<refpurpose>escape special SGML characters in a string.</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>escape_sgml_chars</command>
-          <arg>string</arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::escape_sgml_chars</command>
+		    <arg>string</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Scans through each character in the specified string looking
-          for any special (with respect to SGML, and hence HTML) characters
-          from the specified string, and returns the result.  
-          For example, the right angle
-          bracket is escaped to the corrected ampersand gt symbol.
-        </para>
-        <note> 
-            You must require the Rivet package in order to gain access to this command
-        </note>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Scans through each character in the specified string looking
+		    for any special (with respect to SGML, and hence HTML) characters
+		    from the specified string, and returns the result.  
+		    For example, the right angle
+		    bracket is escaped to the corrected ampersand gt symbol.
+		</para>
+		<!--note> 
+		    You must require the <command>rivetlib</command> package in order to gain access to this command
+		</note -->
+	    </refsect1>
+	</refentry>
 
-    <refentry id="escape_shell_command">
-      <refnamediv>
-        <refname>escape_shell_command</refname>
-        <refpurpose>escape shell metacharacters in a string.</refpurpose>
-      </refnamediv>
+	<refentry id="escape_shell_command">
+	    <refnamediv>
+		<refname>escape_shell_command</refname>
+		<refpurpose>escape shell metacharacters in a string.</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>escape_shell_command</command>
-          <arg>string</arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::escape_shell_command</command>
+		    <arg>string</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Scans through each character in the specified string looking
-          for any shell metacharacters, such as asterisk, less than and
-          greater than, parens, square brackets, curly brackets, angle 
-          brackets, dollar signs, backslashes, semicolons, ampersands,
-          vertical bars, etc. 	
-        </para>
-        <para>
-          For each metacharacter found, it is quoted in the result by
-          prepending it with a backslash, returning the result.
-        </para>
-        <note> 
-            You must require the Rivet package in order to gain access to this command
-        </note>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Scans through each character in the specified string looking
+		    for any shell metacharacters, such as asterisk, less than and
+		    greater than, parens, square brackets, curly brackets, angle 
+		    brackets, dollar signs, backslashes, semicolons, ampersands,
+		    vertical bars, etc.	
+		</para>
+		<para>
+		    For each metacharacter found, it is quoted in the result by
+		    prepending it with a backslash, returning the result.
+		</para>
+		<!-- note>
+		    You must require the <command>rivetlib</command> package in order to gain access to this command
+		</note -->
+	    </refsect1>
+	</refentry>
+	
+	<refentry id="escape_string">
+	    <refnamediv>
+		<refname>escape_string</refname>
+		<refpurpose>convert a string into escaped characters.</refpurpose>
+	    </refnamediv>
 
-      </refsect1>
-    </refentry>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::escape_string</command>
+		    <arg>string</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-    <refentry id="escape_string">
-      <refnamediv>
-			<refname>escape_string</refname>
-			<refpurpose>convert a string into escaped characters.</refpurpose>
-      </refnamediv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Scans through each character in the specified string looking
+		    for special characters, escaping them as needed, mapping
+		    special characters to a quoted hexadecimal equivalent,
+		    returning the result.
+		</para>
+		<para>
+		    This is useful for quoting strings that are going to be
+		    part of a URL.
+		</para>
+		<!-- note> 
+		    You must require the <command>rivetlib</command> package in order to gain access 
+		    to this command
+		</note -->
+	    </refsect1>
+	</refentry>
 
-      <refsynopsisdiv>
-	    <cmdsynopsis>
-            <command>escape_string</command>
-            <arg>string</arg>
-	    </cmdsynopsis>
-      </refsynopsisdiv>
+	
+	<refentry id="headers">
+	    <refnamediv>
+		<refname>headers</refname>
+		<refpurpose>set and parse HTTP headers.</refpurpose>
+	    </refnamediv>
 
-      <refsect1>
-        <title>Description</title>
-        <para>
-            Scans through each character in the specified string looking
-            for special characters, escaping them as needed, mapping
-            special characters to a quoted hexadecimal equivalent,
-            returning the result.
-        </para>
-        <para>
-            This is useful for quoting strings that are going to be
-            part of a URL.
-        </para>
-        <note> 
-            You must require the Rivet package in order to gain access to this command
-        </note>
-      </refsect1>
-    </refentry>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::headers</command>
+		    <group choice="req">
+			<arg>set</arg>
+			<arg>redirect</arg>
+			<arg>add</arg>
+			<arg>type</arg>
+			<arg>numeric</arg>
+		    </group>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-    <refentry id="headers">
-      <refnamediv>
-        <refname>headers</refname>
-        <refpurpose>set and parse HTTP headers.</refpurpose>
-      </refnamediv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		  The <command>headers</command> command is for setting and
+		  parsing HTTP headers.
+		</para>
+		
+		<variablelist>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::headers</command>
+				<arg choice="plain">set</arg>
+				<arg><replaceable>headername</replaceable></arg>
+				<arg><replaceable>value</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Set arbitrary header names and values.
+			    </para>
+			</listitem>
+		    </varlistentry>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>headers</command>
-          <group choice="req">
-            <arg>set</arg>
-            <arg>redirect</arg>
-            <arg>add</arg>
-            <arg>type</arg>
-            <arg>numeric</arg>
-          </group>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::headers</command>
+				<arg choice="plain">redirect</arg>
+				<arg><replaceable>uri</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Redirect from the current page to a new
+				URI. <emphasis>Must</emphasis> be done in the first block
+				of TCL code.
+			    </para>
+			</listitem>
+		    </varlistentry>
 
-      <refsect1>
-	<title>Description</title>
-	<para>
-	  The <command>headers</command> command is for setting and
-	  parsing HTTP headers.
-	</para>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::headers</command>
+				<arg choice="plain">add</arg>
+				<arg><replaceable>headername</replaceable></arg>
+				<arg><replaceable>value</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>Add text to header
+				<varname>headername</varname>.
+			    </para>
+			</listitem>
+		    </varlistentry>
 
-	<variablelist>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::headers</command>
+				<arg choice="plain">type</arg>
+				<arg><replaceable>content-type</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				This command sets the <constant>Content-type</constant>
+				header returned by the script, which is useful if you wish
+				to send content other than HTML with Rivet - PNG or jpeg
+				images, for example.
+			    </para>
+			</listitem>
+		    </varlistentry>
 
-	  <varlistentry>
-	    <term><cmdsynopsis>
-		<command>headers</command>
-		<arg choice="plain">set</arg>
-		<arg><replaceable>headername</replaceable></arg>
-		<arg><replaceable>value</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Set arbitrary header names and values.
-	      </para>
-	    </listitem>
-	  </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::headers</command>
+				<arg choice="plain">numeric</arg>
+				<arg><replaceable>response code</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Set a numeric response code, such as 200, 404 or 500.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		</variablelist>
+	    </refsect1>
+	</refentry>
 
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>headers</command>
-		<arg choice="plain">redirect</arg>
-		<arg><replaceable>uri</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Redirect from the current page to a new
-		URI. <emphasis>Must</emphasis> be done in the first block
-		of TCL code.
-	      </para>
-	    </listitem>
-	  </varlistentry>
+	<refentry id="html">
+	    <refnamediv>
+		<refname>html</refname>
+		<refpurpose>construct html tagged text.</refpurpose>
+	    </refnamediv>
 
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>headers</command>
-		<arg choice="plain">add</arg>
-		<arg><replaceable>headername</replaceable></arg>
-		<arg><replaceable>value</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>Add text to header
-		<varname>headername</varname>.</para>
-	    </listitem>
-	  </varlistentry>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::html</command>
+		    <arg><replaceable>string</replaceable></arg>
+		    <arg rep="repeat"><replaceable>arg</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-	  <varlistentry>
-	    <term><cmdsynopsis>
-		<command>headers</command>
-		<arg choice="plain">type</arg>
-		<arg><replaceable>content-type</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		This command sets the <constant>Content-type</constant>
-		header returned by the script, which is useful if you wish
-		to send content other than HTML with Rivet - PNG or jpeg
-		images, for example.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>headers</command>
-		<arg choice="plain">numeric</arg>
-		<arg><replaceable>response code</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>Set a numeric response code, such as 200, 404 or 500.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	</variablelist>
-      </refsect1>
-    </refentry>
-
-    <refentry id="html">
-      <refnamediv>
-        <refname>html</refname>
-        <refpurpose>construct html tagged text.</refpurpose>
-      </refnamediv>
-
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>html</command>
-          <arg><replaceable>string</replaceable></arg>
-          <arg rep="repeat"><replaceable>arg</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
-
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Print text with the added ability to pass HTML tags
-          following the string.  Example:
-          <programlisting>html "Test" b i</programlisting>
-          produces: <computeroutput>&lt;b&gt;&lt;i&gt;Test&lt;/i&gt;&lt;/b&gt;</computeroutput>
-        </para>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Print text with the added ability to pass HTML tags
+		    following the string.  Example:
+		    <programlisting>::rivet::html "Test" b i</programlisting>
+		    produces: <computeroutput>&lt;b&gt;&lt;i&gt;Test&lt;/i&gt;&lt;/b&gt;</computeroutput>
+		</para>
+	    </refsect1>
+	</refentry>
 
 	<refentry id="import_keyvalue_pairs">
-		<refnamediv>
-			<refname>import_keyvalue_pairs</refname>
-			<refpurpose>Import an argument list into the named array</refpurpose>
-		</refnamediv>
-		<refsynopsisdiv>
-			<cmdsynopsis>
-				<command>import_keyvalue_pairs</command>
-				<arg>arrayName</arg>
-				<arg>argsList</arg>
-			</cmdsynopsis>
-		</refsynopsisdiv>	
-		<refsect1>
-			<title>Description</title>
-			<para>
-				key-value pairs, like "-foo bar" are stored in the array <arg>arrayName</arg>.  
-				In that case, the value "bar" would be stored in the element "foo"
-			</para>
-			<para>
-				If "--" appears or a key doesn't begin with "-", the rest of the arg 
-				list is stored in the special args element of the array.
-			</para>
-			<para>
-				Example:
-				<programlisting>import_keyvalue_pairs keyvalue_map [list -a1 v1 -a2 v2 -a3 v3 -- 1 2 3 4 5]
+	    <refnamediv>
+		<refname>import_keyvalue_pairs</refname>
+		<refpurpose>Import an argument list into the named array</refpurpose>
+	    </refnamediv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::import_keyvalue_pairs</command>
+		    <arg>arrayName</arg>
+		    <arg>argsList</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    key-value pairs, like "-foo bar" are stored in the array <arg>arrayName</arg>.  
+		    In that case, the value "bar" would be stored in the element "foo"
+		</para>
+		<para>
+		    If "--" appears or a key doesn't begin with "-", the rest of the arg 
+		    list is stored in the special args element of the array.
+		</para>
+		<para>
+		    Example:
+		    <programlisting>::rivet::import_keyvalue_pairs keyvalue_map [list -a1 v1 -a2 v2 -a3 v3 -- 1 2 3 4 5]
 parray keyvalue_map
 
 keyvalue_map(a1)   = v1
 keyvalue_map(a2)   = v2
 keyvalue_map(a3)   = v3
 keyvalue_map(args) = 1 2 3 4 5</programlisting>
-			</para>
-		</refsect1>
+		</para>
+	    </refsect1>
 	</refentry>
-    <refentry id="include">
-      <refnamediv>
-        <refname>include</refname>
-        <refpurpose>includes a file into the output stream without modification.</refpurpose>
-      </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>include</command>
-          <arg><replaceable>filename_name</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	<refentry id="include">
+	    <refnamediv>
+		<refname>include</refname>
+		<refpurpose>includes a file into the output stream without modification.</refpurpose>
+	    </refnamediv>
 
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Include a file without parsing it for processing tags &lt;?
-          and ?&gt;.  This is the best way to include an HTML file or
-          any other static content.
-        </para>
-      </refsect1>
-    </refentry>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::include</command>
+		    <arg><replaceable>filename_name</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-    <refentry id="incr0">
-      <refnamediv>
-        <refname>incr0</refname>
-        <refpurpose>increment a variable or set it to 1 if nonexistant.</refpurpose>
-      </refnamediv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Include a file without parsing it for processing tags &lt;?
+		    and ?&gt;.  This is the best way to include an HTML file or
+		    any other static content.
+		</para>
+	    </refsect1>
+	</refentry>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>incr0</command>
-          <arg><replaceable>varname</replaceable></arg>
-          <arg><replaceable>num</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	<refentry id="incr0">
+	    <refnamediv>
+		<refname>incr0</refname>
+		<refpurpose>increment a variable or set it to 1 if nonexistent.</refpurpose>
+	    </refnamediv>
 
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Increment a variable
-          <option><replaceable>varname</replaceable></option> by
-          <option><replaceable>num</replaceable></option>.  If the
-          variable doesn't exist, create it instead of returning an
-          error.
-        </para>
-      </refsect1>
-    </refentry>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>incr0</command>
+		    <arg><replaceable>varname</replaceable></arg>
+		    <arg><replaceable>num</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Increment a variable
+		    <option><replaceable>varname</replaceable></option> by
+		    <option><replaceable>num</replaceable></option>.  If the
+		    variable doesn't exist, create it instead of returning an
+		    error.
+		</para>
+
+		<note> 
+		    incr0 functionality is now provided by <command>incr</command>, 
+		    therefore this command is obsolete and it's kept 
+		    only for compatibility. It will be removed in future versions of Rivet
+		</note>
+	    </refsect1>
+	</refentry>
 
 	<refentry id="lassign">
-		<refnamediv>
-			<refname>lassign</refname>
-			<refpurpose>Assign a list of values to a list of variables</refpurpose>
-		</refnamediv>	
-		<refsynopsisdiv>
-			<cmdsynopsis>
-				<command>lassign</command>
-				<arg>value_list</arg>
-				<arg>variables</arg>
-			</cmdsynopsis>
-		</refsynopsisdiv>	
-		<refsect1>
-			<title>Description</title>
-			<para>
-				<command>lassign</command> emulates the TclX lassign command. It accepts
-				a list variables and treats the rest as a list of variable names that will
-				be assigned with the values in the caller's scope
-			</para>
-			<para>
-				<programlisting># lassign {1 2 3} a b c
+	    <refnamediv>
+		<refname>lassign</refname>
+		<refpurpose>Assign a list of values to a list of variables</refpurpose>
+	    </refnamediv>	
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::lassign</command>
+		    <arg>value_list</arg>
+		    <arg>variables</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    <command>lassign</command> emulates the TclX lassign command. It accepts
+		    a list variables and treats the rest as a list of variable names that will
+		    be assigned with the values in the caller's scope
+		</para>
+		<para>
+		    <programlisting># ::rivet::lassign {1 2 3} a b c
 # set a
 1
 # set b
 2
 # set c
 3</programlisting>
-			</para>
-		</refsect1>
+		</para>
+	    </refsect1>
 	</refentry>
-
-	<refentry id="lempty">
-      <refnamediv>
-			<refname>lempty</refname>
-			<refpurpose>Returns 1 if &lt;list&gt; is empty or 0 if it has any elements.  
-			This command emulates the TclX lempty command.
-			</refpurpose>
-      </refnamediv>
 		
-		<refsynopsisdiv>
-			<cmdsynopsis>
-				<command>lempty</command>
-				<arg>list</arg>
-			</cmdsynopsis>
-		</refsynopsisdiv>	
-		<refsect1>
-			<title>Description</title>
-			<para>
-				Returns 1 if &lt;list&gt; is empty or 0 if it has any elements.  
-				This command emulates the TclX lempty command.
-			</para>
-		</refsect1>
+	<refentry id="lempty">
+	    <refnamediv>
+		<refname>lempty</refname>
+		<refpurpose>
+		    Returns 1 if &lt;list&gt; is empty or 0 if it has any elements.  
+		    This command emulates the TclX lempty command.
+		</refpurpose>
+	    </refnamediv>
+		
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::lempty</command>
+		    <arg>list</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Returns 1 if &lt;list&gt; is empty or 0 if it has any elements.  
+		    This command emulates the TclX lempty command.
+		</para>
+	    </refsect1>
 	</refentry>	
 
 	<refentry id="lmatch">
-      <refnamediv>
-			<refname>lmatch</refname>
-			<refpurpose>
-				Look for elements in &lt;list&gt; that match &lt;pattern&gt;
-			</refpurpose>
-      </refnamediv>
-		<refsynopsisdiv>
-			<cmdsynopsis>
-				<command>lmatch</command>
-				<group choice="req">
-					<arg>-exact</arg>
-					<arg>-glob</arg>
-					<arg>-regexp</arg>
-				</group>
-				<arg>list</arg>
-				<arg>pattern</arg>
-			</cmdsynopsis>
-		</refsynopsisdiv>	
-		<refsect1>
-			<title>Description</title>
-			<para>
-				Look for elements in &lt;list&gt; that match &lt;pattern&gt;.  
-				This command emulates the TclX lmatch command, but if TclX isn't 
-				available, it's a decent substitute.
-			</para>
-			<para>
-				In the following example a regular expression is matched against
-				each element in the input list and a list containing the matching
-				elements is returned
-			</para>
-			<para>
-				<programlisting># lmatch -regexp lmatch -regexp { aaxa bxxb ccxxxxcc } {.+[x]{2}.+}
-bxxb ccxxxxcc
-				</programlisting>
-			</para>
-		</refsect1>
+	    <refnamediv>
+		<refname>lmatch</refname>
+		<refpurpose>
+		    Look for elements in &lt;list&gt; that match &lt;pattern&gt;
+		</refpurpose>
+	    </refnamediv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::lmatch</command>
+		    <group choice="req">
+			<arg>-exact</arg>
+			<arg>-glob</arg>
+			<arg>-regexp</arg>
+		    </group>
+		    <arg>list</arg>
+		    <arg>pattern</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Look for elements in &lt;list&gt; that match &lt;pattern&gt;.  
+		    This command emulates the TclX lmatch command, but if TclX isn't 
+		    available, it's a decent substitute.
+		</para>
+		<para>
+		    In the following example a regular expression is matched against
+		    each element in the input list and a list containing the matching
+		    elements is returned
+		</para>
+		<para>
+		    <programlisting>::rivet::lmatch -regexp { aaxa bxxb ccxxxxcc } {.+[x]{2}.+}
+bxxb ccxxxxcc</programlisting>
+		</para>
+	    </refsect1>
 	</refentry>	
 
 
-    <refentry id="load_cookies">
-      <refnamediv>
-        <refname>load_cookies</refname>
-        <refpurpose>get any cookie variables sent by the client.</refpurpose>
-      </refnamediv>
+	<refentry id="load_cookies">
+	    <refnamediv>
+		<refname>load_cookies</refname>
+		<refpurpose>get any cookie variables sent by the client.</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>load_cookies</command>
-          <arg choice="opt"><replaceable>array_name</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::load_cookies</command>
+		    <arg choice="opt"><replaceable>array_name</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsect1>
-        <title>Description</title>
-      </refsect1>
-      <para>
-        Load the array of cookie variables into the specified
-        array name.  Uses array <option>cookies</option> by
-        default.
-      </para>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+	    </refsect1>
+	    <para>
+		Load the array of cookie variables into the specified
+		array name.  Uses array <option>cookies</option> by
+		default.
+	    </para>
+	</refentry>
+		
+	<refentry id="load_env">
+	    <refnamediv>
+		<refname>load_env</refname>
+		<refpurpose>get the request's environment variables.</refpurpose>
+	    </refnamediv>
+		
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::load_env</command>
+		    <arg choice="opt"><replaceable>array_name</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-    <refentry id="load_env">
-      <refnamediv>
-        <refname>load_env</refname>
-        <refpurpose>get the request's environment variables.</refpurpose>
-      </refnamediv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Load the array of environment variables into the specified
+		    array name.  Uses array <option>::request::env</option> by
+		    default.
+		</para>
+		<para>
+		    As Rivet pages are run in the <option>::request</option>
+		    namespace, it isn't necessary to qualify the array name
+		    for most uses - it's ok to access it as
+		    <option>env</option>.
+		</para>
+	    </refsect1>
+	</refentry>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>load_env</command>
-          <arg choice="opt"><replaceable>array_name</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	<refentry id="load_headers">
+	    <refnamediv>
+		<refname>load_headers</refname>
+		<refpurpose>get client request's headers.</refpurpose>
+	    </refnamediv>
 
-      <refsect1>
-        <title>Description</title>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::load_headers</command>
+		    <arg><replaceable>array_name</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-        <para>
-          Load the array of environment variables into the specified
-          array name.  Uses array <option>::request::env</option> by
-          default.
-        </para>
-        <para>
-          As Rivet pages are run in the <option>::request</option>
-          namespace, it isn't necessary to qualify the array name
-          for most uses - it's ok to access it as
-          <option>env</option>.
-        </para>
-      </refsect1>
-    </refentry>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Load the headers that come from a client request into the
+		    provided array name, or use <option>headers</option> if no
+		    name is provided.
+		</para>
+	    </refsect1>
+	</refentry>
+	
+	<refentry id="load_response">
+	    <refnamediv>
+		<refname>load_response</refname>
+		<refpurpose>load form variables into an array.</refpurpose>
+	    </refnamediv>
 
-    <refentry id="load_headers">
-      <refnamediv>
-			<refname>load_headers</refname>
-			<refpurpose>get client request's headers.</refpurpose>
-      </refnamediv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::load_response</command>
+		    <arg><replaceable>arrayName</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>load_headers</command>
-          <arg><replaceable>array_name</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Load any form variables passed to this page into an
+		    array. If <command>load_response</command> is called without 
+		    arguments the array <option>response</option> is created in 
+		    the scope of the caller. If the variables var1,var2,var3...
+		    having values val1,val2,val3... are passed to the page, the
+		    resulting array will be a collection mapping var1,var2,var3...
+		    to their corresponding values. <command>load_response</command>
+		    was inspired by the same NeoWebScript procedure in the way
+		    it deals with multiple assignments: if a variable 
+		    is assigned more than once the corresponding array element will be a 
+		    list of the values for the variable. This can be useful in the case 
+		    of forms with checkbox options that are given the same name.
+		    Calling <command>load_response</command> several times for the same
+		    array results in adding more values to the array at every call. 
+		    When needed it is left to the caller to empty the array between 
+		    two subsequent calls.  
+		</para>
+	    </refsect1>
+	</refentry>
 
-	  <refsect1>
-        <title>Description</title>
-        <para>
-          Load the headers that come from a client request into the
-          provided array name, or use <option>headers</option> if no
-          name is provided.
-        </para>
-      </refsect1>
-    </refentry>
+	<refentry id="makeurl">
+	    <refnamediv>
+		<refname>makeurl</refname>
+		<refpurpose>construct url's based on hostname, port.</refpurpose>
+	    </refnamediv>
 
-    <refentry id="load_response">
-      <refnamediv>
-        <refname>load_response</refname>
-        <refpurpose>load form variables into an array.</refpurpose>
-      </refnamediv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::makeurl</command>
+		    <arg><replaceable>filename</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>load_response</command>
-          <arg><replaceable>arrayName</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		  Create a self referencing URL from a filename. <command>makeurl</command>
+		  can be used in three ways
+		  <itemizedlist> 
+		    <listitem> No argument is passed to the command (returns the current script URL)</listitem>
+		    <listitem> 
+			A relative style path is passed (returns the argument prepended with the
+			current script's URL
+		    </listitem>
+		    <listitem> 
+			An absolute path is passed to the command: (returns the full URL to the
+			resource)
+		    </listitem>
 
-      <refsect1>
-			<title>Description</title>
-			<para>
-				Load any form variables passed to this page into an
-				array. If <command>load_response</command> is called without 
-				arguments the array <option>response</option> is created in 
-				the scope of the caller. If the variables var1,var2,var3...
-				having values val1,val2,val3... are passed to the page, the
-				resulting array will be a collection mapping var1,var2,var3...
-				to their corresponding values. <command>load_response</command>
-				was inspired by the same NeoWebScript procedure in the way
-				it deals with multiple assignments: if a variable 
-				is assigned more than once the corresponding array element will be a 
-				list of the values for the variable. This can be useful in the case 
-				of forms with checkbox options that are given the same name.
-				Calling <command>load_response</command> several times for the same
-				array results in adding more values to the array at every call. 
-				When needed it is left to the caller to empty the array between 
-				two subsequent calls.  
-			</para>
-      </refsect1>
-    </refentry>
+		  </itemizedlist>
+		</para>
+		<para>
+		    Example of absolute path: <programlisting>::rivet::makeurl /tclp.gif</programlisting> returns
+		    <computeroutput>http://[hostname]:[port]/tclp.gif</computeroutput>.
+		    where hostname and port are the hostname and port of the
+		    server in question.
+		</para>
+	    </refsect1>
+	</refentry>
 
-    <refentry id="makeurl">
-      <refnamediv>
-        <refname>makeurl</refname>
-        <refpurpose>construct url's based on hostname, port.</refpurpose>
-      </refnamediv>
+	<refentry id="no_body">
+	    <refnamediv>
+		<refname>no_body</refname>
+		<refpurpose>Prevents Rivet from sending any content.</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>makeurl</command>
-          <arg><replaceable>filename</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
-
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Create a self referencing URL from a filename. <command>makeurl</command>
-          can be used in three ways
-          <itemizedlist> 
-            <listitem> No argument is passed to the command (returns the current script URL)</listitem>
-            <listitem> 
-                A relative style path is passed (returns the argument prepended with the
-                current script's URL)
-            </listitem>
-            <listitem> 
-                An absolute path is passed to the command: (returns the full URL to the
-                resource)
-            </listitem>
-
-          </itemizedlist>
-        </para>
-        <para>
-            Example of absolute path: <programlisting>makeurl /tclp.gif</programlisting> returns
-            <computeroutput>http://[hostname]:[port]/tclp.gif</computeroutput>.
-            where hostname and port are the hostname and port of the
-            server in question.
-        </para>
-      </refsect1>
-    </refentry>
-
-   <refentry id="no_body">
-      <refnamediv>
-        <refname>no_body</refname>
-        <refpurpose>Prevents Rivet from sending any content.</refpurpose>
-      </refnamediv>
-
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>no_body</command>
-        </cmdsynopsis>
-      </refsynopsisdiv>
-
-      <refsect1>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::no_body</command>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
+		<refsect1>
         <title>Description</title>
         <para>
           This command is useful for situations where it is necessary
@@ -971,494 +1025,508 @@
           instance, when returning a 304 redirect.
         </para>
       </refsect1>
-    </refentry>
 
-    <refentry id="parray">
-      <refnamediv>
-	<refname>parray</refname>
-	<refpurpose>Tcl's <command>parray</command> with html formatting.</refpurpose>
-      </refnamediv>
+	</refentry>
+	<refentry id="parray">
+	    <refnamediv>
+		<refname>parray</refname>
+		<refpurpose>Tcl's <command>parray</command> with html formatting.</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-	<cmdsynopsis>
-	  <command>parray</command>
-	  <arg><replaceable>arrayName</replaceable></arg>
-	  <arg><replaceable><optional>pattern</optional></replaceable></arg>
-	</cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::parray</command>
+		    <arg><replaceable>arrayName</replaceable></arg>
+		    <arg><replaceable><optional>pattern</optional></replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsect1>
-	<title>Description</title>
-	<para>
-	  An html version of the standard Tcl
-	  <command>parray</command> command.  Displays the entire
-	  contents of an array in a sorted, nicely-formatted way.
-	  Mostly used for debugging purposes.
-	</para>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    An html version of the standard Tcl
+		    <command>parray</command> command.  Displays the entire
+		    contents of an array in a sorted, nicely-formatted way.
+		    Mostly used for debugging purposes.
+		</para>
+	    </refsect1>
+	</refentry>
 
-      </refsect1>
-    </refentry>
+	<refentry id="parse">
+	    <refnamediv>
+		<refname>parse</refname>
+		<refpurpose>parses a Rivet template file.</refpurpose>
+	    </refnamediv>
 
-    <refentry id="parse">
-      <refnamediv>
-        <refname>parse</refname>
-        <refpurpose>parses a Rivet template file.</refpurpose>
-      </refnamediv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::parse</command>
+		    <arg><replaceable>filename</replaceable></arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>parse</command>
-          <arg><replaceable>filename</replaceable></arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Like the Tcl <command>source</command> command, but also
+		    parses for Rivet &lt;?  and ?&gt; processing tags.  Using
+		    this command, you can use one .rvt file from another.
+		</para>
+	    </refsect1>
+	</refentry>
 
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Like the Tcl <command>source</command> command, but also
-          parses for Rivet &lt;?  and ?&gt; processing tags.  Using
-          this command, you can use one .rvt file from another.
-        </para>
-      </refsect1>
-    </refentry>
+	<refentry id="raw_post">
+	    <refnamediv>
+		<refname>raw_post</refname>
+		<refpurpose>get the unmodified body of a POST request sent by the client.</refpurpose>
+	    </refnamediv>
+
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::raw_post</command>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
+
+	    <refsect1>
+		<title>Description</title>
+	    </refsect1>
+	    <para>
+		Returns the raw POST data from the request.  If the request was 
+		not a POST or there is no data, then "" - an empty string - is returned.
+	    </para>
+	</refentry>
 
 	<refentry id="read_file">
-        <refnamediv>
-			<refname>read_file</refname>
-			<refpurpose>
-				Read the entire contents of a file and return it as a string.			
-			</refpurpose>
-        </refnamediv>
+	    <refnamediv>
+		<refname>read_file</refname>
+		<refpurpose>
+		    Read the entire contents of a file and return it as a string.			
+		</refpurpose>
+	    </refnamediv>
 		
-		<refsynopsisdiv>
-			<cmdsynopsis>
-				<command>read_file</command>
-				<arg>file name</arg>
-			</cmdsynopsis>
-		</refsynopsisdiv>	
-		<refsect1>
-			<title>Description</title>
-			<para>
-				This is a utility command which loads the entire content of
-				a file and returns it as a result.
-			</para>
-		</refsect1>
+	    <refsynopsisdiv>
+	    	<cmdsynopsis>
+		    <command>::rivet::read_file</command>
+		    <arg>file name</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    This is a utility command which loads the entire content of
+		    a file and returns it as a result.
+		</para>
+	    </refsect1>
 	</refentry>	
-    <refentry id="unescape_string">
-      <refnamediv>
-        <refname>unescape_string</refname>
-        <refpurpose>unescape escaped characters in a string.</refpurpose>
-      </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>unescape_string</command>
-          <arg>string</arg>
-        </cmdsynopsis>
-      </refsynopsisdiv>
+	<refentry id="unescape_string">
+	    <refnamediv>
+		<refname>unescape_string</refname>
+		<refpurpose>unescape escaped characters in a string.</refpurpose>
+	    </refnamediv>
 
-      <refsect1>
-        <title>Description</title>
-        <para>
-          Scans through each character in the specified string looking
-          for escaped character sequences (characters containing a
-          percent sign and two hexadecimal characters, unescaping them 
-          back to their original character values, as needed, also mapping
-          plus signs to spaces, and returning the result.
-        </para>
-        <para>
-            This is useful for unquoting strings that have been quoted to
-            be part of a URL.
-        </para>
-        <note> 
-            You must require the Rivet package in order to gain access to this command
-        </note>
-      </refsect1>
-    </refentry>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::unescape_string</command>
+		    <arg>string</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-    <refentry id="upload">
-      <refnamediv>
-        <refname>upload</refname>
-        <refpurpose>handle a file uploaded by a client.</refpurpose>
-      </refnamediv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Scans through each character in the specified string looking
+		    for escaped character sequences (characters containing a
+		    percent sign and two hexadecimal characters, unescaping them 
+		    back to their original character values, as needed, also mapping
+		    plus signs to spaces, and returning the result.
+		</para>
+		<para>
+		    This is useful for unquoting strings that have been quoted to
+		    be part of a URL.
+		</para>
+		<!-- note> 
+		    You must require the <command>rivetlib</command> package in order to gain 
+		    access to this command
+		</note -->
+	    </refsect1>
+	</refentry>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-	        <command>upload</command>
-            <group choice="req">
-                <arg>channel</arg>
-                <arg>save</arg>
-                <arg>data</arg>
-                <arg>exists</arg>
-                <arg>size</arg>
-                <arg>type</arg>
-                <arg>filename</arg>
-            </group>
-	    </cmdsynopsis>
-      </refsynopsisdiv>
+	<refentry id="upload">
+	    <refnamediv>
+		<refname>upload</refname>
+		<refpurpose>handle a file uploaded by a client.</refpurpose>
+	    </refnamediv>
 
-      <refsect1>
-        <title>Description</title>
-        <para>The upload command is for file upload manipulation.
-          See the relevant Apache Directives to further configure the
-          behavior of this Rivet feature.
-        </para>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::upload</command>
+		    <group choice="req">
+			<arg>channel</arg>
+			<arg>save</arg>
+			<arg>data</arg>
+			<arg>exists</arg>
+			<arg>size</arg>
+			<arg>type</arg>
+			<arg>filename</arg>
+		    </group>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
 
-        <variablelist>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">channel</arg>
-            <arg><replaceable>uploadname</replaceable></arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            When given the name of a file upload
-            <option><replaceable>uploadname</replaceable></option>,
-            returns a Tcl channel that can be used to access the
-            uploaded file.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">save</arg>
-            <arg><replaceable>uploadname</replaceable></arg>
-            <arg><replaceable>filename</replaceable></arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            Saves the
-            <option><replaceable>uploadname</replaceable></option> in
-            the file
-            <option><replaceable>filename</replaceable></option>.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">data</arg>
-            <arg><replaceable>uploadname</replaceable></arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            Returns data uploaded to the server.  This is binary clean
-            - in other words, it will work even with files like
-            images, executables, compressed files, and so on.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">exists</arg>
-            <arg><replaceable>uploadname</replaceable></arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            Returns true if an upload named <arg>uploadname</arg>
-            exists.  This can be used in scripts that are meant to
-            be run by different forms that send over uploads that
-            might need specific processing.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">size</arg>
-            <arg><replaceable>uploadname</replaceable></arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            Returns the size of the file uploaded.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">type</arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            If the <varname>Content-type</varname> is set, it is
-            returned, otherwise, an empty string.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">filename</arg>
-            <arg><replaceable>uploadname</replaceable></arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            Returns the filename on the remote host that uploaded the file.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">tempname</arg>
-            <arg><replaceable>uploadname</replaceable></arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            Returns the name of the temporary file on the local host that the file was uploaded into.
-              </para>
-            </listitem>
-          </varlistentry>
-          <varlistentry>
-            <term>
-              <cmdsynopsis>
-            <command>upload</command>
-            <arg choice="plain">names</arg>
-              </cmdsynopsis>
-            </term>
-            <listitem>
-              <para>
-            Returns the variable names, as a list, of all the files
-            uploaded.
-              </para>
-            </listitem>
-          </varlistentry>
-        </variablelist>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    The upload command is for file upload manipulation.
+		    See the relevant Apache Directives to further configure the
+		    behavior of this Rivet feature.
+		</para>
 
-        <para>
-          See <xref linkend="upload"/>.
-        </para>
-      </refsect1>
-    </refentry>
+		<variablelist>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">channel</arg>
+    				<arg><replaceable>uploadname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				When given the name of a file upload
+	    			<option><replaceable>uploadname</replaceable></option>,
+				returns a Tcl channel that can be used to access the
+				uploaded file.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">save</arg>
+				<arg><replaceable>uploadname</replaceable></arg>
+				<arg><replaceable>filename</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Saves the <option><replaceable>uploadname</replaceable></option> in
+				the file <option><replaceable>filename</replaceable></option>.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">data</arg>
+				<arg><replaceable>uploadname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns data uploaded to the server.  This is binary clean
+				- in other words, it will work even with files like
+				images, executables, compressed files, and so on.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">exists</arg>
+				<arg><replaceable>uploadname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns true if an upload named <arg>uploadname</arg>
+				exists.  This can be used in scripts that are meant to
+				be run by different forms that send over uploads that
+				might need specific processing.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">size</arg>
+				<arg><replaceable>uploadname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns the size of the file uploaded.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">type</arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				If the <varname>Content-type</varname> is set, it is
+				returned, otherwise, an empty string.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">filename</arg>
+				<arg><replaceable>uploadname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns the filename on the remote host that uploaded the file.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">tempname</arg>
+				<arg><replaceable>uploadname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns the name of the temporary file on the local host that the file was uploaded into.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::upload</command>
+				<arg choice="plain">names</arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns the variable names, as a list, of all the files uploaded.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		</variablelist>
+		<para>
+		    See <xref linkend="file_upload"/>.
+		</para>
+	    </refsect1>
+	</refentry>
 
-    <refentry id="var">
-      <refnamediv>
-        <refname>var</refname>
-        <refname>var_qs</refname>
-        <refname>var_post</refname>
-        <refpurpose>get the value of a form variable.</refpurpose>
-      </refnamediv>
+	<refentry id="var">
+	    <refnamediv>
+		<refname>var</refname>
+		<refname>var_qs</refname>
+		<refname>var_post</refname>
+		<refpurpose>get the value of a form variable.</refpurpose>
+	    </refnamediv>
 
-      <refsynopsisdiv>
-        <cmdsynopsis>
-          <command>var</command>
-          <group choice="req">
-            <arg>get</arg>
-            <arg>list</arg>
-            <arg>exists</arg>
-            <arg>number</arg>
-            <arg>all</arg>
-          </group>
-	    </cmdsynopsis>
-
-        <cmdsynopsis>
-          <command>var_qs</command>
-          <group choice="req">
-            <arg>get</arg>
-            <arg>list</arg>
-            <arg>exists</arg>
-            <arg>number</arg>
-            <arg>all</arg>
-          </group>
-        </cmdsynopsis>
-
-        <cmdsynopsis>
-          <command>var_post</command>
-          <group choice="req">
-            <arg>get</arg>
-            <arg>list</arg>
-            <arg>exists</arg>
-            <arg>number</arg>
-            <arg>all</arg>
-          </group>
-        </cmdsynopsis>
-      </refsynopsisdiv>
-
-      <refsect1>
-        <title>Description</title>
-        <para>
-          The <command>var</command> command retrieves information
-          about GET or POST variables sent to the script via client
-          request.  It treats both GET and POST variables the same,
-          regardless of their origin.  Note that there are two
-          additional forms of <command>var</command>:
-          <command>var_qs</command> and <command>var_post</command>.
-          These two restrict the retrieval of information to
-          parameters arriving via the querystring
-          (?foo=bar&amp;bee=bop) or POSTing, respectively.
-        </para>
-	<variablelist>
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>var</command>
-		<arg choice="plain">get</arg>
-		<arg><replaceable>varname</replaceable></arg>
-		<arg><replaceable><optional>default</optional></replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Returns the value of variable
-		<option><replaceable>varname</replaceable></option>
-		as a string (even if there are multiple values).  If
-		the variable doesn't exist as a GET or POST
-		variable, the
-		<option><replaceable><optional>default</optional></replaceable></option>
-		value is returned, otherwise "" - an empty string -
-		is returned.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>var</command>
-		<arg choice="plain">list</arg>
-		<arg><replaceable>varname</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Returns the value of variable
-		<option><replaceable>varname</replaceable></option> as a
-		list, if there are multiple values.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>var</command>
-		<arg choice="plain">exists</arg>
-		<arg><replaceable>varname</replaceable></arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Returns 1 if
-		<option><replaceable>varname</replaceable></option>
-		exists, 0 if it doesn't.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>var</command>
-		<arg choice="plain">number</arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Returns the number of variables.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
-	    <term>
-	      <cmdsynopsis>
-		<command>var</command>
-		<arg choice="plain">all</arg>
-	      </cmdsynopsis>
-	    </term>
-	    <listitem>
-	      <para>
-		Return a list of variable names and values.
-	      </para>
-	    </listitem>
-	  </varlistentry>
-	</variablelist>
-
-        <para>
-          See <xref linkend="variable_access"/>.
-        </para>
-
-      </refsect1>
-    </refentry>
-
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::var</command>
+		    <group choice="req">
+			<arg>get</arg>
+			<arg>list</arg>
+			<arg>exists</arg>
+			<arg>number</arg>
+			<arg>all</arg>
+		    </group>
+		</cmdsynopsis>
+		
+		<cmdsynopsis>
+		    <command>::rivet::var_qs</command>
+		    <group choice="req">
+			<arg>get</arg>
+			<arg>list</arg>
+			<arg>exists</arg>
+			<arg>number</arg>
+			<arg>all</arg>
+		    </group>
+		</cmdsynopsis>
+		
+		<cmdsynopsis>
+		    <command>::rivet::var_post</command>
+		    <group choice="req">
+			<arg>get</arg>
+			<arg>list</arg>
+			<arg>exists</arg>
+			<arg>number</arg>
+			<arg>all</arg>
+		    </group>
+		</cmdsynopsis>
+	    </refsynopsisdiv>
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    The <command>var</command> command retrieves information
+		    about GET or POST variables sent to the script via client
+		    request.  It treats both GET and POST variables the same,
+		    regardless of their origin.  Note that there are two
+		    additional forms of <command>::rivet::var</command>:
+		    <command>rivet::var_qs</command> and 
+		    <command>::rivet::var_post</command>.
+		    These two restrict the retrieval of information to
+		    parameters arriving via the querystring
+		    (?foo=bar&amp;bee=bop) or POSTing, respectively.
+		</para>
+		<variablelist>
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::var</command>
+				<arg choice="plain">get</arg>
+				<arg><replaceable>varname</replaceable></arg>
+				<arg><replaceable><optional>default</optional></replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns the value of variable
+				<option><replaceable>varname</replaceable></option>
+				as a string (even if there are multiple values).  If
+				the variable doesn't exist as a GET or POST
+				variable, the
+				<option><replaceable><optional>default</optional></replaceable></option>
+				value is returned, otherwise "" - an empty string -
+				is returned.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		    
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::var</command>
+				<arg choice="plain">list</arg>
+				<arg><replaceable>varname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns the value of variable
+				<option><replaceable>varname</replaceable></option> as a
+				list, if there are multiple values.
+			    </para>
+			</listitem>
+		    </varlistentry>
+	    
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::var</command>
+				<arg choice="plain">exists</arg>
+				<arg><replaceable>varname</replaceable></arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns 1 if
+				<option><replaceable>varname</replaceable></option>
+				exists, 0 if it doesn't.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::var</command>
+				<arg choice="plain">number</arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Returns the number of variables.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		
+		    <varlistentry>
+			<term>
+			    <cmdsynopsis>
+				<command>::rivet::var</command>
+				<arg choice="plain">all</arg>
+			    </cmdsynopsis>
+			</term>
+			<listitem>
+			    <para>
+				Return a list of variable names and values.
+			    </para>
+			</listitem>
+		    </varlistentry>
+		</variablelist>
+		<para>See <xref linkend="variable_access"/>.</para>
+	    </refsect1>
+	</refentry>
 
 	<refentry id="wrap">
-      <refnamediv>
-			<refname>wrap</refname>
-			<refpurpose>
-				Split a string on newlines. 
-			</refpurpose>
-      </refnamediv>
+	    <refnamediv>
+		<refname>wrap</refname>
+		<refpurpose>
+		    Split a string on newlines. 
+		</refpurpose>
+	    </refnamediv>
 		
-		<refsynopsisdiv>
-			<cmdsynopsis>
-				<command>wrap</command>
-				<arg>string</arg>
-				<arg>maxlen</arg>
-				<arg choice="plan">html</arg>
-			</cmdsynopsis>
-		</refsynopsisdiv>	
-		<refsect1>
-			<title>Description</title>
-			<para>			
-				For each line, wrap the line at a space character to be 
-				equal to or shorter than the maximum length value passed.
-			</para>
-			<para>
-				If a third argument called "-html" is present, the string is put together
-				with html &lt;br&gt; line breaks, otherwise it's broken with newlines.
-			</para>
-		</refsect1>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::wrap</command>
+		    <arg>string</arg>
+		    <arg>maxlen</arg>
+		    <arg choice="plan">html</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	    <refsect1>
+		<title>Description</title>
+		<para>			
+		    For each line, wrap the line at a space character to be 
+		    equal to or shorter than the maximum length value passed.
+		</para>
+		<para>
+		    If a third argument called "-html" is present, the string is put together
+		    with html &lt;br&gt; line breaks, otherwise it's broken with newlines.
+		</para>
+	    </refsect1>
 	</refentry>	
 
 	<refentry id="wrapline">
-      <refnamediv>
-			<refname>wrapline</refname>
-			<refpurpose>
-				Split the line into multiple lines by splitting on space characters 
-			</refpurpose>
-      </refnamediv>
-		
-		<refsynopsisdiv>
-			<cmdsynopsis>
-				<command>wrapline</command>
-				<arg>string</arg>
-				<arg>maxlen</arg>
-				<arg choice="plan">html</arg>
-			</cmdsynopsis>
-		</refsynopsisdiv>	
-		<refsect1>
-			<title>Description</title>
-			<para>
-				Given a line and a maximum length and option "-html" argument, split the line 
-				into multiple lines by splitting on space characters and making sure each line 
-				is less than maximum length.
-			</para>
-			<para>
-				If the third argument, "-html", is present, return the result with the lines 
-				separated by html &lt;br&gt; line breaks, otherwise the lines are returned 
-				separated by newline characters.
-			</para>
-		</refsect1>
+	    <refnamediv>
+		<refname>wrapline</refname>
+		<refpurpose>
+		    Split the line into multiple lines by splitting on space characters 
+		</refpurpose>
+	    </refnamediv>
+	    <refsynopsisdiv>
+		<cmdsynopsis>
+		    <command>::rivet::wrapline</command>
+		    <arg>string</arg>
+		    <arg>maxlen</arg>
+		    <arg choice="plan">html</arg>
+		</cmdsynopsis>
+	    </refsynopsisdiv>	
+	    <refsect1>
+		<title>Description</title>
+		<para>
+		    Given a line and a maximum length and option "-html" argument, split the line 
+		    into multiple lines by splitting on space characters and making sure each line 
+		    is less than maximum length.
+		</para>
+		<para>
+		    If the third argument, "-html", is present, return the result with the lines 
+		    separated by html &lt;br&gt; line breaks, otherwise the lines are returned 
+		    separated by newline characters.
+		</para>
+	    </refsect1>
 	</refentry>	
+
 </section>
diff --git a/doc/xml/directives.xml b/doc/xml/directives.xml
index 44f5c62..6397bcd 100644
--- a/doc/xml/directives.xml
+++ b/doc/xml/directives.xml
@@ -1,130 +1,138 @@
 <section id="directives">
-    <title>Rivet Apache Directives</title>
-
-    <para>
-      These directives are used within the Apache httpd server
-      configuration files to modify Apache Rivet's behavior.  Their
-      precedence is as follows: <command>RivetDirConf</command>,
-      <command>RivetUserConf</command>,
-      <command>RivetServerConf</command>, meaning that DirConf will
-      override UserConf, which will in turn override ServerConf.
-    </para>
-    <para>
-    	The directive <command>ServerInitScript</command> plays a special
-    	role since the script runs within the master interpreter,
-    	an interpreter created before the Apache parent process spawns
-    	the children that actually will serve the requests coming from
-    	the network. During this
-    	stage Apache is still running as a single process, so this
-    	is the right place for doing initialization of anything that 
-    	might work as an IPC infrastructure. Moreover everything
-    	created and initialized in this stage will be handed on to the
-    	interpreters run by the child processes, as they are
-    	created by copying the memory of the parent process.
-    </para>
-
-    <variablelist>
-      <varlistentry>
-	<term>
-	  <cmdsynopsis>
-	    <command>RivetServerConf</command>
-	    <group choice="req">
-	      <arg>CacheSize</arg>
-	      <arg>ServerInitScript</arg>
-	      <arg>GlobalInitScript</arg>
-	      <arg>ChildInitScript</arg>
-	      <arg>ChildExitScript</arg>
-	      <arg>BeforeScript</arg>
-	      <arg>AfterScript</arg>
-	      <arg>ErrorScript</arg>
-	      <arg>AbortScript</arg>
-	      <arg>AfterEveryScript</arg>
-	      <arg>UploadDirectory</arg>
-	      <arg>UploadMaxSize</arg>
-	      <arg>UploadFilesToVar</arg>
-	      <arg>SeparateVirtualInterps</arg>
-	      <arg>HonorHeaderOnlyRequests</arg>
-	    </group>
-	  </cmdsynopsis>
-	</term>
-	<listitem>
-	  <para><command>RivetServerConf</command> specifies a global
-	    option that is valid for the whole server.  If you have a
-	    virtual host, in some cases, the option specified in the
-	    virtualhost takes precedence over the 'global' version.
-	  </para>
-	</listitem>
-	<listitem>
-	  <variablelist>
-	    <varlistentry>
-	      <term>
+   <title>Rivet Apache Directives</title>
+	<section>
+	   <para>
+	      Rivet directives are used within the Apache httpd server
+	      configuration to set up the environment where Rivet script
+	      will be run.  Their precedence is as follows: 
+	      <command>RivetDirConf</command>,
+	      <command>RivetUserConf</command>,
+	      <command>RivetServerConf</command>, meaning that DirConf will
+	      override UserConf, which will in turn override ServerConf.
+	   </para>
+	   <para>
+	    	The directive <command>ServerInitScript</command> plays a special
+	    	role since the script runs within the master interpreter,
+	    	an interpreter created before the Apache parent process spawns
+	    	the children that actually will serve the requests coming from
+	    	the network. During this stage Apache is still running as a 
+	    	single process, so this is the right place for doing 
+	    	initializations or loading packages 
+	    	that have be common to all the interpreters that will be created
+	    	when Apache forks its child processes, even when the option 
+	    	<command>SeparateVirtualInterps</command> is set. Since this
+	    	script will be running in a single process environment (from the
+	    	Apache point of view) <command>ServerInitScript</command> 
+	    	is also the right place for doing everything that must avoid
+	    	resource concurrency among processes (e.g. the creation and 
+	    	initialization of an IPC system)
+	   </para>
+	</section>
+	<section>
+	   <variablelist>	
+   		<varlistentry>
+			<term>
 				<cmdsynopsis>
-				  <arg choice="plain">CacheSize</arg>
-				  <arg><replaceable>size</replaceable></arg>
-				</cmdsynopsis>
-	      </term>
-			   <listitem>
-					<para>
-					  Sets the size of the internal page cache, where
-					  <option><replaceable>size</replaceable></option> is
-					  the number of byte-compiled pages to be cached for
-					  future use.  Default is
-					  <command>MaxRequestsPerChild</command> / 5, or 50,
-					  if <command>MaxRequestsPerChild</command> is 0.
-					</para>
-					<para>
-					  This option is completely global, even when using
-					  separate, per-virtual host interpreters.
-					</para>
-				</listitem>
-	   </varlistentry>
-	   <varlistentry>
-	   	<term>
-	   		<cmdsynopsis>
-	   			<arg choice="plain">ServerInitScript</arg>
-	   			<arg><replaceable>script</replaceable></arg>
-	   		</cmdsynopsis>
-	   	</term>
-	   	<listitem>
-	   		<para>
-	   			Tcl script which is to run when the master interpreter is created. 
-	   			Namespaces, variables and packages loaded during this stage will 
-	   			be copied later on in the startup process, when child
-	   			processes are created. In general any sort of I/O channel 
-	   			that is opened during this stage must be closed before the 
-	   			execution of the script completes.
-	   		</para>
-	   		<para>
-					This option is only available at the global level	   		
-	   		</para>
-	   	</listitem>
-		</varlistentry>
-	   <varlistentry>
-	      <term>
-				<cmdsynopsis>
-				  <arg choice="plain">GlobalInitScript</arg>
-				  <arg><replaceable>script</replaceable></arg>
-				</cmdsynopsis>
-	      </term>
-	      <listitem>
+			   	<command>RivetServerConf</command>
+			   	<group choice="req">
+				      <arg>CacheSize</arg>
+				      <arg>ServerInitScript</arg>
+				      <arg>GlobalInitScript</arg>
+				      <arg>ChildInitScript</arg>
+				      <arg>ChildExitScript</arg>
+				      <arg>BeforeScript</arg>
+				      <arg>AfterScript</arg>
+				      <arg>ErrorScript</arg>
+				      <arg>AbortScript</arg>
+				      <arg>AfterEveryScript</arg>
+				      <arg>UploadDirectory</arg>
+				      <arg>UploadMaxSize</arg>
+				      <arg>UploadFilesToVar</arg>
+				      <arg>SeparateVirtualInterps</arg>
+				      <arg>HonorHeaderOnlyRequests</arg>
+	    			</group>
+			  </cmdsynopsis>
+			</term>
+			<listitem>
 				<para>
-				  Tcl script that is run as part of a child process initialization. 
-				  If the option <option>SeparateVirtualInterp</option> is not used this is
-				  the right place where file handles, database connections or sockets can 
-				  be opened.
-				  The argument <replaceable><option>script</option></replaceable>
-				  is an actual Tcl script, so to run a file, you would
-				  do:
-		
-				  <programlisting>RivetServerConf GlobalInitScript "source /var/www/foobar.tcl"</programlisting>
+					<command>RivetServerConf</command> specifies a global
+			    	option that is valid for the whole server.  If you have a
+			    	virtual host, in some cases, the option specified in the
+			    	virtualhost takes precedence over the 'global' version.
 				</para>
-				<para>
-				  This option is ignored in virtual hosts.
-				</para>
-	      </listitem>
-	  </varlistentry>
+			</listitem>
+			<listitem>
+				<variablelist>
+	   		<varlistentry>
+	      		<term>
+						<cmdsynopsis>
+				  			<arg choice="plain">CacheSize</arg>
+				  			<arg><replaceable>size</replaceable></arg>
+						</cmdsynopsis>
+	      		</term>
+			   	<listitem>
+						<para>
+						  Sets the size of the internal page cache, where
+						  <option><replaceable>size</replaceable></option> is
+						  the number of byte-compiled pages to be cached for
+						  future use.  Default is
+						  <command>MaxRequestsPerChild</command> / 5, or 50,
+						  if <command>MaxRequestsPerChild</command> is 0.
+						</para>
+						<para>
+						  This option is completely global, even when using
+						  separate, per-virtual host interpreters.
+						</para>
+					</listitem>
+	   		</varlistentry>
+	   		<varlistentry>
+	   			<term>
+	   				<cmdsynopsis>
+			   			<arg choice="plain">ServerInitScript</arg>
+			   			<arg><replaceable>script</replaceable></arg>
+	   				</cmdsynopsis>
+	   			</term>
+	   			<listitem>
+			   		<para>
+			   			Tcl script which is to run when the master interpreter is created. 
+			   			Namespaces, variables and packages loaded during this stage will 
+			   			be copied later on in the startup process, when child
+			   			processes are created. In general any sort of I/O channel 
+			   			that is opened during this stage must be closed before the 
+			   			execution of the script completes.
+			   		</para>
+			   		<para>
+							This option is only available at the global level and has
+							effect only if <command>SeparateVirtualInterps</command> is off   		
+			   		</para>
+	   			</listitem>
+				</varlistentry>
+	   		<varlistentry>
+			      <term>
+						<cmdsynopsis>
+						  <arg choice="plain">GlobalInitScript</arg>
+						  <arg><replaceable>script</replaceable></arg>
+						</cmdsynopsis>
+			      </term>
+			      <listitem>
+						<para>
+						  Tcl script that is run as part of a child process initialization. 
+						  If the option <option>SeparateVirtualInterp</option> is not used this is
+						  the right place where file handles, database connections or sockets can 
+						  be opened.
+						  The argument <replaceable><option>script</option></replaceable>
+						  is an actual Tcl script, so to run a file, you would
+						  do:
+				
+						  <programlisting>RivetServerConf GlobalInitScript "source /var/www/foobar.tcl"</programlisting>
+						</para>
+						<para>
+						  This option is ignored in virtual hosts.
+						</para>
+			      </listitem>
+	  			</varlistentry>
 
-	  <varlistentry>
+			  <varlistentry>
 	      <term>
 				<cmdsynopsis>
 				  <arg choice="plain">ChildInitScript</arg>
@@ -252,10 +260,11 @@
 					is therefore run both when the content generation script
 					completes successfully and when its execution is interrupted
 					by <xref linkend="abort_page" />. The code in this script
-					can tell whether we are running after an abort condition
-					occurred by passing the argument <arg>-aborting</arg> to
-					<xref linkend="abort_page" /> which in turn returns 1 if
-					abort_page had been called earlier in the request processing.
+					can understand whether it's running after the page was
+					interrupted by calling <xref linkend="abort_page" />	
+					with the argument <arg>-aborting</arg>. The command
+					will return 1 if an abort_page call took place 
+					earlier in the request processing.
 				</para>
 	      </listitem>
 	    </varlistentry>
@@ -269,13 +278,13 @@
 			</term>
 			<listitem>
 				<para>
-					Execution of a content generating script can be
-					done by invoking <xref linkend="abort_page" />. When 
+					The execution of a can be interrupted by
+					invoking <xref linkend="abort_page" />. If  
 					an <option>AbortScript</option> is defined for the page
-					being generated, control is passed to it as a way
-					to undertake specific action that might be necessary
+					being generated, control is passed to it. <option>AbortScript</option>
+					is the right place where specific actions can be taken
 					to catch resources left dangling by the sudden interruption.				
-				</para>			
+				</para>
 			</listitem>
 		</varlistentry>
 
@@ -331,14 +340,14 @@
 
 	    <varlistentry>
 	      <term>
-		    <cmdsynopsis>
+		     <cmdsynopsis>
 		       <arg choice="plain">SeparateVirtualInterps</arg>
 		       <group choice="req">
 		          <arg>yes</arg>
 		          <arg>no</arg>
 		       </group>
-		       </cmdsynopsis>
-		   </term>
+		     </cmdsynopsis>
+		  </term>
 	      <listitem>
       		<para>
       		  If on, Rivet will create a separate Tcl interpreter
@@ -347,10 +356,16 @@
       		  clients into separate interpreters, so that they
       		  don't accidentally interfere with one another.
       		</para>
-   		   <para>
-   		     This option is, by nature, only available at the
-   		     global level.
-   		   </para>
+   		    <note>
+   		      This option is, by nature, only available at the
+   		      global level. By enabling <command>SeparateVirtualInterps</command>
+   		      you must rely only on <command>ChildInitScript</command> to
+   		      initialize the interpreters. Don't expect the 
+   		      initialization done in <command>ServerInitScript</command> and 
+   		      <command>GlobalInitScript</command> to be handed down to the
+   		      slave interpreters that are private to each configured 
+   		      virtual host.
+   		   </note>
 	      </listitem>
 	    </varlistentry>
 
@@ -377,52 +392,49 @@
 	  </variablelist>
 	</listitem>
       </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <cmdsynopsis>
-	    <command>RivetDirConf</command>
-	    <group choice="req">
-	      <arg>BeforeScript</arg>
-	      <arg>AfterScript</arg>
-	      <arg>ErrorScript</arg>
-	      <arg>UploadDirectory</arg>
-	    </group>
-	  </cmdsynopsis>
-	</term>
-	<listitem>
-	  <para>
-	    These options are the same as for
-	    <command>RivetServerConf</command>, except that they are
-	    only valid for the directory where they are specified, and
-	    its subdirectories.  It may be specified in <command>Directory</command> 
-	    sections.
-	  </para>
-	</listitem>
+      	<varlistentry>
+			<term>
+			  <cmdsynopsis>
+			    <command>RivetDirConf</command>
+			    <group choice="req">
+			      <arg>BeforeScript</arg>
+			      <arg>AfterScript</arg>
+			      <arg>ErrorScript</arg>
+			      <arg>UploadDirectory</arg>
+			    </group>
+			  </cmdsynopsis>
+			</term>
+			<listitem>
+			  <para>
+			    These options are the same as for
+			    <command>RivetServerConf</command>, except that they are
+			    only valid for the directory where they are specified, and
+			    its subdirectories.  It may be specified in <command>Directory</command> 
+			    sections.
+			  </para>
+			</listitem>
       </varlistentry>
-
-      <varlistentry>
-	<term>
-	  <cmdsynopsis>
-	    <command>RivetUserConf</command>
-	    <group choice="req">
-	      <arg>BeforeScript</arg>
-	      <arg>AfterScript</arg>
-	      <arg>ErrorScript</arg>
-	      <arg>UploadDirectory</arg>
-	    </group>
-	  </cmdsynopsis>
-	</term>
-	<listitem>
-	  <para>
-	    These options are the same as for
-	    <command>RivetServerConf</command>, except that they are
-	    only valid for the directory where they are specified, and
-	    its subdirectories.
-	  </para>
-	</listitem>
+      	<varlistentry>
+			<term>
+			  <cmdsynopsis>
+			    <command>RivetUserConf</command>
+			    <group choice="req">
+			      <arg>BeforeScript</arg>
+			      <arg>AfterScript</arg>
+			      <arg>ErrorScript</arg>
+			      <arg>UploadDirectory</arg>
+			    </group>
+			  </cmdsynopsis>
+			</term>
+			<listitem>
+			  <para>
+			    These options are the same as for
+			    <command>RivetServerConf</command>, except that they are
+			    only valid for the directory where they are specified, and
+			    its subdirectories.
+			  </para>
+			</listitem>
       </varlistentry>
-    </variablelist>
-
+		</variablelist>
+	</section>
 </section>
-
diff --git a/doc/xml/examples.xml b/doc/xml/examples.xml
index a529710..c964c9d 100644
--- a/doc/xml/examples.xml
+++ b/doc/xml/examples.xml
@@ -18,51 +18,50 @@
 			Assuming you have Apache configured correctly, create a file
 			called <filename>hello.rvt</filename> where Apache can find
 			it, with the following content:
-		</para>
+      </para>
       <programlisting>&hello.rvt;</programlisting>
       <para>
-	If you then access it with your browser, you should see a
-	blank page with the text "Hello World" (without the quotes) on it.
+			If you then access it with your browser, you should see a
+			blank page with the text "Hello World" (without the quotes) on it.
       </para>
     </example>
 
     <example>
-	<title>Generate a Table</title>
-	  <para>
-	    In another simple example, we dynamically generate a table:
-	  </para>
-	  <programlisting>&table.rvt;</programlisting>
-	  <para>
-	    If you read the code, you can see that this is pure Tcl.  We
-	    could take the same code, run it outside of Rivet, and it
-	    would generate the same HTML!
-	  </para>
-	  <para>
-	    The result should look something like this:
-	  </para>
-	  <graphic fileref="images/table.png"/>
-
+		<title>Generate a Table</title>
+	  	<para>
+	   	In another simple example, we dynamically generate a table:
+	  	</para>
+	  	<programlisting>&table.rvt;</programlisting>
+	  	<para>
+	    	If you read the code, you can see that this is pure Tcl.  We
+	    	could take the same code, run it outside of Rivet, and it
+	    	would generate the same HTML!
+	  	</para>
+	  	<para>
+	    	The result should look something like this:
+	  	</para>
+	  	<graphic fileref="images/table.png"/>
     </example>
 
     <example id="variable_access">
       <title>Variable Access</title>
       <para>
-	Here, we demonstrate how to access variables set by GET or
-	POST operations.
+			Here, we demonstrate how to access variables set by GET or
+			POST operations.
       </para>
       <para>
-	Given an HTML form like the following:
+			Given an HTML form like the following:
       </para>
       <programlisting>&vars.html;</programlisting>
       <para>
-	We can use this Rivet script to get the variable values:
+			We can use this Rivet script to get the variable values:
       </para>
       <programlisting>&vars.rvt;</programlisting>
       <para>
-	The first statement checks to make sure that the
-	<varname>boss</varname> variable has been passed to the
-	script, and then does something with that information.  If
-	it's not present, an error is added to the list of errors.
+			The first statement checks to make sure that the
+			<varname>boss</varname> variable has been passed to the
+			script, and then does something with that information.  If
+			it's not present, an error is added to the list of errors.
       </para>
       <para>
 	In the second block of code, the variable
@@ -88,74 +87,74 @@
 	of errors it contains is printed.
       </para>
     </example>
-
+    
     <example id="file_upload">
       <title>File Upload</title>
       <para>
-	The <command>upload</command> command endows Rivet with an
-	interface to access files transferred over http as parts of a
-	multipart form.  The following HTML in one file, say,
-	<filename>upload.html</filename> creates a form with a text
-	input entry. By clicking the file chooser button the file
-	browser shows up and the user selects the file to be uploaded
-	(the file path will appear in the text input).  In order to make
-	sure you're uploading the whole file you must combine the
-	action of the enctype and method attributes of the
-	&lt;form...&gt; tag in the way shown in the example.  Failure
-	to do so would result in the client sending only the file's
-	path, rather than the actual contents.
+			The <command>::rivet::upload</command> command endows Rivet with an
+			interface to access files transferred over http as parts of a
+			multipart form.  The following HTML in one file, say,
+			<filename>upload.html</filename> creates a form with a text
+			input entry. By clicking the file chooser button the file
+			browser shows up and the user selects the file to be uploaded
+			(the file path will appear in the text input).  In order to make
+			sure you're uploading the whole file you must combine the
+			action of the enctype and method attributes of the
+			&lt;form...&gt; tag in the way shown in the example.  Failure
+			to do so would result in the client sending only the file's
+			path, rather than the actual contents.
       </para>
       <programlisting>&upload.html;</programlisting>
       <para>
-	In the script invoked by the form
-	(<filename>upload.rvt</filename>) <command>upload</command>
-	<arg>argument ...</arg> commands can be used to manipulate the
-	various files uploaded.
+			In the script invoked by the form
+			(<filename>upload.rvt</filename>) <command>upload</command>
+			<arg>argument ...</arg> commands can be used to manipulate the
+			various files uploaded.
       </para>
       <programlisting>&upload.rvt;</programlisting>
       <para>
-	Don't forget that the apache server must have write access to
-	the directory where files are being created.  The Rivet Apache
-	directives have a substantial impact on the upload process,
-	you have to carefully read the docs in order to set the
-	appropriate directives values that would match your
-	requirements.
+			Don't forget that the apache server must have write access to
+			the directory where files are being created.  The Rivet Apache
+			directives have a substantial impact on the upload process,
+			you have to carefully read the docs in order to set the
+			appropriate directives values that would match your
+			requirements.
       </para>
       <para>
-	It is also important to understand that some 
-	<command>upload</command> commands are effective only when
-	used in a mutually exclusive way.  Apache stores the data in
-	temporary files which are read by the <command>upload save
-	<arg>upload name</arg><arg>filename</arg></command> or by the
-	<command>upload data <arg>upload name</arg></command>
-	command. Subsequent calls to these 2 commands using the same
-	<arg>upload name</arg> argument will return no data on the
-	second call.  Likewise <command>upload channel <arg>upload
-	name</arg></command> will return a Tcl file channel that you
-	can use in regular Tcl scripts only if you haven't already
-	read the data, for example with a call to the <command>upload
-	data <arg>upload name</arg></command> command.
+			It is also important to understand that some 
+			<command>upload</command> commands are effective only when
+			used in a mutually exclusive way.  Apache stores the data in
+			temporary files which are read by the <command>upload save
+			<arg>upload name</arg><arg>filename</arg></command> or by the
+			<command>upload data <arg>upload name</arg></command>
+			command. Subsequent calls to these 2 commands using the same
+			<arg>upload name</arg> argument will return no data on the
+			second call.  Likewise <command>upload channel <arg>upload
+			name</arg></command> will return a Tcl file channel that you
+			can use in regular Tcl scripts only if you haven't already
+			read the data, for example with a call to the <command>upload
+			data <arg>upload name</arg></command> command.
       </para>
     </example>
     <example id="file_download">
       <title>File Download</title>
       <para>
-	In general setting up a data file for being sent over http is 
-	as easy as determining the file's URI and letting Apache's
-	do all that is needed. If this approach fits your design all 
-	you have to do is to keep the downloadable files somewhere 
-	within Apache's DocumentRoot (or in any of the directories 
-	Apache has right to access).
+			In general setting up a data file for being sent over http is 
+			as easy as determining the file's URI and letting Apache's
+			do all that is needed. If this approach fits your design all 
+			you have to do is to keep the downloadable files somewhere 
+			within Apache's DocumentRoot (or in any of the directories 
+			Apache has right to access).
       </para>
       <para>
-	When a client sends a request for a file, Apache takes
-	care of determining the filetype, sends appropriate headers to
-	the client and then the file content. The client is responsible
-	for deciding how to handle the data accordingly to the 
-	"content-type" headers and its internal design. For example
-	when browsers give up trying to display a certain "content-type"
-	they display a download dialog box asking for directions from
-	the user. 
+			When a client sends a request for a file, Apache takes
+			care of determining the filetype, sends appropriate headers to
+			the client and then the file content. The client is responsible
+			for deciding how to handle the data accordingly to the 
+			"content-type" headers and its internal design. For example
+			when browsers give up trying to display a certain "content-type"
+			they display a download dialog box asking for directions from
+			the user. 
       </para>
       <para>
 	Rivet can help if you have more sofisticated needs.  For
diff --git a/doc/xml/install.xml b/doc/xml/install.xml
index 0de625a..276fcd7 100644
--- a/doc/xml/install.xml
+++ b/doc/xml/install.xml
@@ -146,14 +146,6 @@
                </listitem>
             </varlistentry>
             <varlistentry>
-                <term>--with-rivet-target-dir=DIR</term>
-               <listitem>
-                    <para>
-                    This option tells the install script where Rivet's Tcl packages have to be copied. 
-                    </para>
-               </listitem>
-            </varlistentry>
-            <varlistentry>
                 <term>--with-upload-dir=DIR (default: '/tmp')</term>
                 <listitem>
                     <para>
@@ -188,10 +180,34 @@
             <varlistentry>
                 <term>--disable-upload-var</term>
                 <listitem>
-                    By default uploads are stored in Tcl variables. This switch sets the default for the configuration 
-                    parameter 'UploadFilesToVar' to 0. (Can be changed in the configuration)
+                    By default uploads are stored in Tcl variables. 
+                    This switch sets the default for the configuration 
+                    parameter 'UploadFilesToVar' to 0. 
+                    (Can be changed in the configuration)
                 </listitem>
             </varlistentry>
+            <varlistentry>
+            	<term>--disable-rivet-commands-export</term>
+            	<listitem>
+            		Rivet commands are created in the ::rivet namespace. To improve code readability
+            		it is recommended you write your scripts using the fully qualified name
+            		definitions. For compatibility with existing code, commands are exported from
+            		::rivet and can be thus imported into any namespace (global namespace included)
+            		with the command
+            		<programlisting>namespace import -force ::rivet::*</programlisting>
+            		The default value for this option may change in the future.
+            	</listitem>
+            </varlistentry>
+            <varlistentry>
+            	<term>--disable-import-rivet-commands</term>
+            	<listitem>
+            		Rivet commands can be imported imported into the global namespace. This
+            		is done by default and can be disabled using this option. In future
+            		versions of Rivet the default will be changed to off and eventually
+            		removed altogether. 
+            		<note>This option implicitly sets --enable-rivet-commands-export</note>
+            	</listitem>
+            </varlistentry>
         </variablelist>
             </para>
             <para>
diff --git a/doc/xml/packages.xml b/doc/xml/packages.xml
index 5d4c750..e0d042e 100644
--- a/doc/xml/packages.xml
+++ b/doc/xml/packages.xml
@@ -36,5 +36,10 @@
       <listitem>
 			<para>tclrivet</para>
       </listitem>
+      
+      <listitem>
+			<para>calendar - a package providing a simple configurable calendar generator</para>
+      </listitem>
+      
     </itemizedlist>
   </section>
diff --git a/doc/xml/request.xml b/doc/xml/request.xml
index 5a5375b..2fcb545 100644
--- a/doc/xml/request.xml
+++ b/doc/xml/request.xml
@@ -4,18 +4,29 @@
     <simplesect>
     	<title>Apache Child Process Lifecycle</title>
 	    <para>
-	    	Apache responds to HTTP requests through child processes spawned at 
-	    	start up. The number of child processes that have to be initially created
+			At startup Apache spawns child processes which are to become the real
+			agents responding to incoming HTTP requests.
+
+	    	The number of child processes that have to be initially created
 	    	can be controlled in the configuration and the optimum choice
 	    	for this numbers basically depends on the webserver workload and on the 
 	    	available system resources. See
 	    	<ulink url="http://httpd.apache.org/docs/2.2/misc/perf-tuning.html">Apache
 	    	documentation</ulink> for further reading about this crucial point. 
-	    	Each of the child process is set up to respond to requests
-	    	that will come from the network accordingly to the configuration 
-	    	parameters. If your webserver has been properly configured you will have Tcl 
-	    	scripts executed (Rivet templates go through a parsing stage before execution).
-	    	Your web applications will be doing much of their work doing this job of
+	    	 If your webserver has been properly configured you will have Tcl 
+	    	scripts executed (Rivet templates go through a parsing stage before execution)
+	    	when tcl or rvt files are referenced in one of these cases
+	    	<itemizedlist>
+	    		<listitem>The script is explicitly referenced in the URL. E.g.:
+	    		<programlisting>http://&lt;myserver&gt;/&lt;path-to-script&gt;/&lt;script&gt;.tcl</programlisting></listitem>
+	    		<listitem>The script is implicitly referenced by rewriting the URL. See:
+		<ulink url="http://httpd.apache.org/docs/current/mod/mod_rewrite.html">mod_rewrite</ulink> 
+				documentation</listitem>
+	    		<listitem>The script is implicitly referenced by 
+	<ulink url="http://httpd.apache.org/docs/2.0/mod/mod_alias.html">redirecting or
+	    			aliasing</ulink> the URL to the real script</listitem>
+	    	</itemizedlist>
+	    	Your web applications will be doing much of their work doing this work of
 	    	responding to requests and creating content to be sent back to a client.
 	    </para>
 	    <para>
@@ -38,8 +49,13 @@
 		    		creation of private data. Example of tasks that can be done
 		    		in this context are importing namespace commands and loading packages
 		    		providing code of general interest for every application to
-		    		be served.
+		    		be served. 
 	    		</para>
+	    		<para>
+	    			<note>
+	    				<command>ServerInitScript</command> has effect for child processes when 
+		    			<command>SeparateVirtualInterps</command> is off</note>
+		    	</para>
 	    	</listitem>
 	    	<listitem>
 	    		<bridgehead>Child Process Initialization</bridgehead>
@@ -59,7 +75,7 @@
 	    			When <command>SeparateVirtualInterps</command> is turned on 
 	    			each configured virtual host will have its own slave interpreter.
 	    			<command>ChildInitScript</command> is the directive to be
-	    			placed within a &lt;VirtualHost ...&gt; ... &lt;/VirtualHost ...&gt;
+	    			placed within a &lt;VirtualHost...&gt;...&lt;/VirtualHost ...&gt;
 	    			stanza to have a special initialization of an interpreter bound to
 	    			a certain virtual host. This scenario of interpreter 
 	    			separation is extremely useful to
@@ -67,8 +83,10 @@
 	    			serving different web applications. 
 	    		</para>
 	    		<para>
-	    			<command>GlobalInitScript</command> has no effect to working interpreters
-	    			when <command>SeparateVirtualInterps</command> is set.
+	    			<note>
+	    				<command>GlobalInitScript</command> has no effect to working interpreters
+	    				when <command>SeparateVirtualInterps</command> is set.
+	    			</note>
 	    		</para>
 	    	</listitem>
 	    	<listitem>
diff --git a/m4/ax_compare_version.m4 b/m4/ax_compare_version.m4
new file mode 100644
index 0000000..74dc0fd
--- /dev/null
+++ b/m4/ax_compare_version.m4
@@ -0,0 +1,177 @@
+# ===========================================================================
+#    http://www.gnu.org/software/autoconf-archive/ax_compare_version.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+#
+# DESCRIPTION
+#
+#   This macro compares two version strings. Due to the various number of
+#   minor-version numbers that can exist, and the fact that string
+#   comparisons are not compatible with numeric comparisons, this is not
+#   necessarily trivial to do in a autoconf script. This macro makes doing
+#   these comparisons easy.
+#
+#   The six basic comparisons are available, as well as checking equality
+#   limited to a certain number of minor-version levels.
+#
+#   The operator OP determines what type of comparison to do, and can be one
+#   of:
+#
+#    eq  - equal (test A == B)
+#    ne  - not equal (test A != B)
+#    le  - less than or equal (test A <= B)
+#    ge  - greater than or equal (test A >= B)
+#    lt  - less than (test A < B)
+#    gt  - greater than (test A > B)
+#
+#   Additionally, the eq and ne operator can have a number after it to limit
+#   the test to that number of minor versions.
+#
+#    eq0 - equal up to the length of the shorter version
+#    ne0 - not equal up to the length of the shorter version
+#    eqN - equal up to N sub-version levels
+#    neN - not equal up to N sub-version levels
+#
+#   When the condition is true, shell commands ACTION-IF-TRUE are run,
+#   otherwise shell commands ACTION-IF-FALSE are run. The environment
+#   variable 'ax_compare_version' is always set to either 'true' or 'false'
+#   as well.
+#
+#   Examples:
+#
+#     AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8])
+#     AX_COMPARE_VERSION([3.15],[lt],[3.15.8])
+#
+#   would both be true.
+#
+#     AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8])
+#     AX_COMPARE_VERSION([3.15],[gt],[3.15.8])
+#
+#   would both be false.
+#
+#     AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8])
+#
+#   would be true because it is only comparing two minor versions.
+#
+#     AX_COMPARE_VERSION([3.15.7],[eq0],[3.15])
+#
+#   would be true because it is only comparing the lesser number of minor
+#   versions of the two values.
+#
+#   Note: The characters that separate the version numbers do not matter. An
+#   empty string is the same as version 0. OP is evaluated by autoconf, not
+#   configure, so must be a string, not a variable.
+#
+#   The author would like to acknowledge Guido Draheim whose advice about
+#   the m4_case and m4_ifvaln functions make this macro only include the
+#   portions necessary to perform the specific comparison specified by the
+#   OP argument in the final configure script.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Tim Toolan <toolan@ele.uri.edu>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 11
+
+dnl #########################################################################
+AC_DEFUN([AX_COMPARE_VERSION], [
+  AC_REQUIRE([AC_PROG_AWK])
+
+  # Used to indicate true or false condition
+  ax_compare_version=false
+
+  # Convert the two version strings to be compared into a format that
+  # allows a simple string comparison.  The end result is that a version
+  # string of the form 1.12.5-r617 will be converted to the form
+  # 0001001200050617.  In other words, each number is zero padded to four
+  # digits, and non digits are removed.
+  AS_VAR_PUSHDEF([A],[ax_compare_version_A])
+  A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
+                     -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/[[^0-9]]//g'`
+
+  AS_VAR_PUSHDEF([B],[ax_compare_version_B])
+  B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
+                     -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/[[^0-9]]//g'`
+
+  dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
+  dnl # then the first line is used to determine if the condition is true.
+  dnl # The sed right after the echo is to remove any indented white space.
+  m4_case(m4_tolower($2),
+  [lt],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
+  ],
+  [gt],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
+  ],
+  [le],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
+  ],
+  [ge],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
+  ],[
+    dnl Split the operator from the subversion count if present.
+    m4_bmatch(m4_substr($2,2),
+    [0],[
+      # A count of zero means use the length of the shorter version.
+      # Determine the number of characters in A and B.
+      ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'`
+      ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'`
+
+      # Set A to no more than B's length and B to no more than A's length.
+      A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
+      B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
+    ],
+    [[0-9]+],[
+      # A count greater than zero means use only that many subversions
+      A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
+      B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
+    ],
+    [.+],[
+      AC_WARNING(
+        [illegal OP numeric parameter: $2])
+    ],[])
+
+    # Pad zeros at end of numbers to make same length.
+    ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
+    B="$B`echo $A | sed 's/./0/g'`"
+    A="$ax_compare_version_tmp_A"
+
+    # Check for equality or inequality as necessary.
+    m4_case(m4_tolower(m4_substr($2,0,2)),
+    [eq],[
+      test "x$A" = "x$B" && ax_compare_version=true
+    ],
+    [ne],[
+      test "x$A" != "x$B" && ax_compare_version=true
+    ],[
+      AC_WARNING([illegal OP parameter: $2])
+    ])
+  ])
+
+  AS_VAR_POPDEF([A])dnl
+  AS_VAR_POPDEF([B])dnl
+
+  dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
+  if test "$ax_compare_version" = "true" ; then
+    m4_ifvaln([$4],[$4],[:])dnl
+    m4_ifvaln([$5],[else $5])dnl
+  fi
+]) dnl AX_COMPARE_VERSION
diff --git a/m4/ax_prefix_config_h.m4 b/m4/ax_prefix_config_h.m4
index 83f8df6..43a3906 100644
--- a/m4/ax_prefix_config_h.m4
+++ b/m4/ax_prefix_config_h.m4
@@ -1,5 +1,5 @@
 # ===========================================================================
-#           http://autoconf-archive.cryp.to/ax_prefix_config_h.html
+#    http://www.gnu.org/software/autoconf-archive/ax_prefix_config_h.html
 # ===========================================================================
 #
 # SYNOPSIS
@@ -68,10 +68,10 @@
 #   it by itself". You might want to clean up about these - consider an
 #   extra mylib/conf.h that reads something like:
 #
-#      #include <mylib/_config.h>
-#      #ifndef _testpkg_const
-#      #define _testpkg_const const
-#      #endif
+#     #include <mylib/_config.h>
+#     #ifndef _testpkg_const
+#     #define _testpkg_const const
+#     #endif
 #
 #   and then start using _testpkg_const in the header files. That is also a
 #   good thing to differentiate whether some library-user has starting to
@@ -87,11 +87,7 @@
 #     #define _testpkg_const const
 #     #endif
 #
-# LAST MODIFICATION
-#
-#   2008-04-12
-#
-# COPYLEFT
+# LICENSE
 #
 #   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
 #   Copyright (c) 2008 Marten Svantesson
@@ -99,7 +95,7 @@
 #
 #   This program is free software; you can redistribute it and/or modify it
 #   under the terms of the GNU General Public License as published by the
-#   Free Software Foundation; either version 2 of the License, or (at your
+#   Free Software Foundation; either version 3 of the License, or (at your
 #   option) any later version.
 #
 #   This program is distributed in the hope that it will be useful, but
@@ -119,11 +115,14 @@
 #   all other use of the material that constitutes the Autoconf Macro.
 #
 #   This special exception to the GPL applies to versions of the Autoconf
-#   Macro released by the Autoconf Macro Archive. When you make and
-#   distribute a modified version of the Autoconf Macro, you may extend this
-#   special exception to the GPL to apply to your modified version as well.
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+#serial 11
 
 AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl
+AC_PREREQ([2.62])
 AC_BEFORE([AC_CONFIG_HEADERS],[$0])dnl
 AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
 AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
@@ -167,14 +166,14 @@
   fi fi
   AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
   if test -f $_INP ; then
-    echo "s/^@%:@undef  *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/" > _script
-    echo "s/^@%:@undef  *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/" >> _script
-    echo "s/^@%:@def[]ine  *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1 \\" >> _script
-    echo "@%:@def[]ine $_UPP""_\\1 \\2 \\" >> _script
-    echo "@%:@endif/" >>_script
-    echo "s/^@%:@def[]ine  *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1 \\" >> _script
-    echo "@%:@define $_LOW""_\\1 \\2 \\" >> _script
-    echo "@%:@endif/" >> _script
+    AS_ECHO(["s/^@%:@undef  *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/"]) > _script
+    AS_ECHO(["s/^@%:@undef  *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/"]) >> _script
+    AS_ECHO(["s/^@%:@def[]ine  *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1\\"]) >> _script
+    AS_ECHO(["@%:@def[]ine $_UPP""_\\1\\2\\"]) >> _script
+    AS_ECHO(["@%:@endif/"]) >> _script
+    AS_ECHO(["s/^@%:@def[]ine  *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1\\"]) >> _script
+    AS_ECHO(["@%:@define $_LOW""_\\1\\2\\"]) >> _script
+    AS_ECHO(["@%:@endif/"]) >> _script
     # now executing _script on _DEF input to create _OUT output file
     echo "@%:@ifndef $_DEF"      >$tmp/pconfig.h
     echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h
@@ -208,12 +207,3 @@
 AS_VAR_POPDEF([_DEF])dnl
 AS_VAR_POPDEF([_OUT])dnl
 ],[PACKAGE="$PACKAGE"])])
-
-dnl implementation note: a bug report (31.5.2005) from Marten Svantesson points
-dnl out a problem where `echo "\1"` results in a Control-A. The unix standard
-dnl    http://www.opengroup.org/onlinepubs/000095399/utilities/echo.html
-dnl defines all backslash-sequences to be inherently non-portable asking
-dnl for replacement mit printf. Some old systems had problems with that
-dnl one either. However, the latest libtool (!) release does export an $ECHO
-dnl (and $echo) that does the right thing - just one question is left: what
-dnl was the first version to have it? Is it greater 2.58 ?
diff --git a/rivet/init.tcl b/rivet/init.tcl
index 0749155..a2ffa64 100644
--- a/rivet/init.tcl
+++ b/rivet/init.tcl
@@ -12,11 +12,56 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-package provide RivetTcl 1.1
+package provide RivetTcl 2.1
 
 namespace eval ::Rivet {
 
     ###
+    ## export_tcl_commands --
+    ## this is temporary hack to export names of Tcl commands in rivet-tcl/.
+    ## This function will be removed in future versions of Rivet and it's
+    ## meant to provide a basic way to guarantee compatibility with older
+    ## versions of Rivet (see code in ::Rivet::init)
+    ##
+
+    proc tcl_commands_export_list {tclpath} {
+
+        # we collect the commands in rivet-tcl by reading the tclIndex
+        # file and then we extract the command list from auto_index
+
+        namespace eval ::rivet_temp { }
+        set ::rivet_temp::tclpath $tclpath
+
+        namespace eval ::rivet_temp {
+            variable auto_index
+            array set auto_index {}
+
+            # the auto_index in ${tclpath}/tclIndex is loaded
+            
+            set dir $tclpath
+            source [file join $tclpath tclIndex]
+        }
+        
+        set command_list [namespace eval ::rivet_temp {array names auto_index}]
+
+        # commands in 'command_list' are prefixed with ::rivet, so we have to
+        # remove it to build an export list 
+        
+        set export_list {}
+        foreach c $command_list {
+            if {[regexp {::rivet::(.*)} $c m cmd]} {
+                lappend export_list $cmd
+#               namespace eval ::rivet [list namespace export $cmd]
+            }
+        }
+
+        # we won't left anything behind
+        namespace delete ::rivet_temp
+
+        return $export_list
+    }
+
+    ###
     ## This routine gets called each time a new request comes in.
     ## It sets up the request namespace and creates a global command
     ## to replace the default global.  This ensures that when a user
@@ -72,6 +117,31 @@
         set tclpath [file join [file dirname [info script]] rivet-tcl]
         set auto_path [linsert $auto_path 0 $tclpath]
 
+        ## As we moved the commands ensemble to ::rivet namespace we
+        ## we want to guarantee the commands are still accessible
+        ## at global level by putting them on the export list.
+        ## Importing the ::rivet namespace is deprecated and we should
+        ## make it clear that this will be removed in the future
+
+        ## we keep in ::rivet::export_list a list of importable commands
+
+        namespace eval ::rivet [list set export_list [tcl_commands_export_list $tclpath]]
+        namespace eval ::rivet {
+
+        ## init.tcl is run by mod_rivet (which creates the ::rivet namespace) but it gets run
+        ## standalone by mkPkgindex during the installation phase. We have to make sure the
+        ## procedure won't fail in this case, so we check for the existence of the variable.
+
+            if {[info exists module_conf(export_namespace_commands)] && \
+                 $module_conf(export_namespace_commands)} {
+
+                apache_log_error debug "exporting ::rivet commands"
+                eval namespace export $export_list
+
+            } else {
+                apache_log_error debug "::rivet commands won't be exported"
+            }
+        }
         ## Add the packages directory to the auto_path.
         ## If we have a packages$tcl_version directory
         ## (IE: packages8.3, packages8.4) append that as well.
@@ -88,7 +158,7 @@
         ## Likewise we have also to add to auto_path the directory containing 
         ## this script since it holds the pkgIndex.tcl file for package Rivet. 
 
-        # set auto_path [linsert $auto_path 0 [file dirname [info script]]]
+        set auto_path [linsert $auto_path 0 [file dirname [info script]]]
 
         ## This will allow users to create proc libraries and tclIndex files
         ## in the local directory that can be autoloaded.
@@ -99,5 +169,29 @@
 
 } ;## namespace eval ::Rivet
 
+
+## Rivet 2.1.x supports Tcl >= 8.5, therefore there's no more need for
+## the command incr0, as the functionality of creating a not yet
+## existing variable is now provided by 'incr'. Being incr0 a command
+## in Rivet < 2.1.0, before the move into the ::Rivet namespace, 
+## we alias this command only in the global namespace
+
+interp alias {} ::incr0 {} incr
+
 ## Initialize Rivet.
 ::Rivet::init
+
+## And now we get to the import of the whole ::rivet namespace. 
+## Some commands (namely lassign) replace the native lassign command
+## so we have to  use the -force switch
+
+# Do we actually want to import everything? If Rivet was configured
+# to import the ::rivet namespace for compatibility we do it right away.
+# This option is not guaranteed to be supported in future versions.
+
+if {[info exists module_conf(import_rivet_commands)] && $module_conf(import_rivet_commands)} {
+    namespace import -force ::rivet::*
+}
+
+array unset module_conf
+
diff --git a/rivet/packages/entities/entities.tcl b/rivet/packages/entities/entities.tcl
new file mode 100644
index 0000000..928f84f
--- /dev/null
+++ b/rivet/packages/entities/entities.tcl
@@ -0,0 +1,144 @@
+# -- package entities
+#
+# The code is largely taken from a simple yet clever encoder/decoder of HTML entities
+# starting from a utf-8 character string. The original code writted by Andy Goth is 
+# at http://wiki.tcl.tk/26403. Package entities extends the functionality in the 
+# original code combining it with Tcl's 'encoding' command to encode/decode from 
+# any supported encoding
+#
+#   $Id$
+
+package provide RivetEntities 1.0
+
+namespace eval rivet {
+#   namespace ensemble create -subcommands {encode decode}
+    namespace export encode decode
+    variable utf8_entities_map {
+        \u00a0 &nbsp\; \u00a1 &iexcl\; \u00a2 &cent\; \u00a3 &pound\; \u00a4
+        &curren\; \u00a5 &yen\; \u00a6 &brvbar\; \u00a7 &sect\; \u00a8 &uml\;
+        \u00a9 &copy\; \u00aa &ordf\; \u00ab &laquo\; \u00ac &not\; \u00ad
+        &shy\; \u00ae &reg\; \u00af &macr\; \u00b0 &deg\; \u00b1 &plusmn\;
+        \u00b2 &sup2\; \u00b3 &sup3\; \u00b4 &acute\; \u00b5 &micro\; \u00b6
+        &para\; \u00b7 &middot\; \u00b8 &cedil\; \u00b9 &sup1\; \u00ba &ordm\;
+        \u00bb &raquo\; \u00bc &frac14\; \u00bd &frac12\; \u00be &frac34\;
+        \u00bf &iquest\; \u00c0 &Agrave\; \u00c1 &Aacute\; \u00c2 &Acirc\;
+        \u00c3 &Atilde\; \u00c4 &Auml\; \u00c5 &Aring\; \u00c6 &AElig\; \u00c7
+        &Ccedil\; \u00c8 &Egrave\; \u00c9 &Eacute\; \u00ca &Ecirc\; \u00cb
+        &Euml\; \u00cc &Igrave\; \u00cd &Iacute\; \u00ce &Icirc\; \u00cf
+        &Iuml\; \u00d0 &ETH\; \u00d1 &Ntilde\; \u00d2 &Ograve\; \u00d3
+        &Oacute\; \u00d4 &Ocirc\; \u00d5 &Otilde\; \u00d6 &Ouml\; \u00d7
+        &times\; \u00d8 &Oslash\; \u00d9 &Ugrave\; \u00da &Uacute\; \u00db
+        &Ucirc\; \u00dc &Uuml\; \u00dd &Yacute\; \u00de &THORN\; \u00df
+        &szlig\; \u00e0 &agrave\; \u00e1 &aacute\; \u00e2 &acirc\; \u00e3
+        &atilde\; \u00e4 &auml\; \u00e5 &aring\; \u00e6 &aelig\; \u00e7
+        &ccedil\; \u00e8 &egrave\; \u00e9 &eacute\; \u00ea &ecirc\; \u00eb
+        &euml\; \u00ec &igrave\; \u00ed &iacute\; \u00ee &icirc\; \u00ef
+        &iuml\; \u00f0 &eth\; \u00f1 &ntilde\; \u00f2 &ograve\; \u00f3
+        &oacute\; \u00f4 &ocirc\; \u00f5 &otilde\; \u00f6 &ouml\; \u00f7
+        &divide\; \u00f8 &oslash\; \u00f9 &ugrave\; \u00fa &uacute\; \u00fb
+        &ucirc\; \u00fc &uuml\; \u00fd &yacute\; \u00fe &thorn\; \u00ff &yuml\;
+        \u0192 &fnof\; \u0391 &Alpha\; \u0392 &Beta\; \u0393 &Gamma\; \u0394
+        &Delta\; \u0395 &Epsilon\; \u0396 &Zeta\; \u0397 &Eta\; \u0398 &Theta\;
+        \u0399 &Iota\; \u039a &Kappa\; \u039b &Lambda\; \u039c &Mu\; \u039d
+        &Nu\; \u039e &Xi\; \u039f &Omicron\; \u03a0 &Pi\; \u03a1 &Rho\; \u03a3
+        &Sigma\; \u03a4 &Tau\; \u03a5 &Upsilon\; \u03a6 &Phi\; \u03a7 &Chi\;
+        \u03a8 &Psi\; \u03a9 &Omega\; \u03b1 &alpha\; \u03b2 &beta\; \u03b3
+        &gamma\; \u03b4 &delta\; \u03b5 &epsilon\; \u03b6 &zeta\; \u03b7 &eta\;
+        \u03b8 &theta\; \u03b9 &iota\; \u03ba &kappa\; \u03bb &lambda\; \u03bc
+        &mu\; \u03bd &nu\; \u03be &xi\; \u03bf &omicron\; \u03c0 &pi\; \u03c1
+        &rho\; \u03c2 &sigmaf\; \u03c3 &sigma\; \u03c4 &tau\; \u03c5 &upsilon\;
+        \u03c6 &phi\; \u03c7 &chi\; \u03c8 &psi\; \u03c9 &omega\; \u03d1
+        &thetasym\; \u03d2 &upsih\; \u03d6 &piv\; \u2022 &bull\; \u2026
+        &hellip\; \u2032 &prime\; \u2033 &Prime\; \u203e &oline\; \u2044
+        &frasl\; \u2118 &weierp\; \u2111 &image\; \u211c &real\; \u2122
+        &trade\; \u2135 &alefsym\; \u2190 &larr\; \u2191 &uarr\; \u2192 &rarr\;
+        \u2193 &darr\; \u2194 &harr\; \u21b5 &crarr\; \u21d0 &lArr\; \u21d1
+        &uArr\; \u21d2 &rArr\; \u21d3 &dArr\; \u21d4 &hArr\; \u2200 &forall\;
+        \u2202 &part\; \u2203 &exist\; \u2205 &empty\; \u2207 &nabla\; \u2208
+        &isin\; \u2209 &notin\; \u220b &ni\; \u220f &prod\; \u2211 &sum\;
+        \u2212 &minus\; \u2217 &lowast\; \u221a &radic\; \u221d &prop\; \u221e
+        &infin\; \u2220 &ang\; \u2227 &and\; \u2228 &or\; \u2229 &cap\; \u222a
+        &cup\; \u222b &int\; \u2234 &there4\; \u223c &sim\; \u2245 &cong\;
+        \u2248 &asymp\; \u2260 &ne\; \u2261 &equiv\; \u2264 &le\; \u2265 &ge\;
+        \u2282 &sub\; \u2283 &sup\; \u2284 &nsub\; \u2286 &sube\; \u2287
+        &supe\; \u2295 &oplus\; \u2297 &otimes\; \u22a5 &perp\; \u22c5 &sdot\;
+        \u2308 &lceil\; \u2309 &rceil\; \u230a &lfloor\; \u230b &rfloor\;
+        \u2329 &lang\; \u232a &rang\; \u25ca &loz\; \u2660 &spades\; \u2663
+        &clubs\; \u2665 &hearts\; \u2666 &diams\; \u0022 &quot\; \u0026 &amp\;
+        \u003c &lt\; \u003e &gt\; \u0152 &OElig\; \u0153 &oelig\; \u0160
+        &Scaron\; \u0161 &scaron\; \u0178 &Yuml\; \u02c6 &circ\; \u02dc
+        &tilde\; \u2002 &ensp\; \u2003 &emsp\; \u2009 &thinsp\; \u200c &zwnj\;
+        \u200d &zwj\; \u200e &lrm\; \u200f &rlm\; \u2013 &ndash\; \u2014
+        &mdash\; \u2018 &lsquo\; \u2019 &rsquo\; \u201a &sbquo\; \u201c
+        &ldquo\; \u201d &rdquo\; \u201e &bdquo\; \u2020 &dagger\; \u2021
+        &Dagger\; \u2030 &permil\; \u2039 &lsaquo\; \u203a &rsaquo\; \u20ac
+        &euro\;
+    }
+
+    variable entitities_utf8_map [lreverse $utf8_entities_map]
+
+    proc args_processing {string mode arglist} {
+
+        if {    [dict exists $arglist -encoding]
+                && [dict get $arglist -encoding] ne "utf-8"
+        } {
+            return [encoding $mode [dict get $arglist -encoding] $string]
+        } else {
+            return $string
+        }
+
+    }
+
+# -- encode
+#
+# input string is processed and its characted suitable to be transformed
+# into entities are replaced with their corrisponding HTML (SGML?) entity
+# 
+# if the input string encoding is diffrent from utf-8 the string is 
+# transformed into utf-8 and then processed for entity substitution
+#
+#   ::rivet::encode <input_string> ?-encode <encoding>?  
+#
+#  Arguments:
+#
+#   * <input_string>: string whose characted must go through HTML 
+#                     entities expansion 
+#   * <encoding>:     input string character encoding (utf-8 when omitted)
+#
+#  Returned value:
+#
+#      - expanded string 
+#
+#
+
+    proc encode {string args} {
+        variable utf8_entities_map
+        return [string map $utf8_entities_map\
+                [args_processing $string convertfrom $args]]
+    }
+
+# -- decode
+#
+# input string is converted into utf-8 and in case the final string
+# has to be in some other encoding Tcl's command 'enconding' is 
+# invoked for final conversion
+#
+#   ::rivet::decode <input_string> ?-encode <encoding>?  
+#
+#  Arguments:
+#
+#   * <input_string>: string whose HTML entities have to be reconverted
+#                     in characters 
+#   * <encoding>:     output string character encoding (utf-8 when omitted)
+#
+#  Returned value:
+#
+#      - converted string
+#
+
+    proc decode {string args} {
+        variable entitities_utf8_map
+        return [args_processing [string map $entitities_utf8_map $string]\
+                convertto $args]
+    }
+}
diff --git a/rivet/packages/form/form.tcl b/rivet/packages/form/form.tcl
index 47d919b..8e5e525 100644
--- a/rivet/packages/form/form.tcl
+++ b/rivet/packages/form/form.tcl
@@ -223,11 +223,7 @@
 	append string " />"
 
 	# ...and emit it
-	if {($type == "radio") || ($type == "checkbox")} {
-	    html $string$data(label)
-	} else {
 	    html $string
-	}
     }
 
     #
diff --git a/rivet/packages/simpledb/simpledb.tcl b/rivet/packages/simpledb/simpledb.tcl
index 11c5d87..bae992c 100644
--- a/rivet/packages/simpledb/simpledb.tcl
+++ b/rivet/packages/simpledb/simpledb.tcl
@@ -194,12 +194,14 @@
 # Results:
 #	None.
 
-proc simpledb::delitem { table oid } {
+proc simpledb::delitem { table oid properties } {
+    upvar $properties props
+
     foreach col [array names ${table}::cols] {
-	unset ${table}::${col}::data($oid)
-	set item [lsearch ${table}::${col}::values($props($col)) $oid]
-	set ${table}::${col}::values($props($col)) \
-	    [lreplace ${table}::${col}::values($props($col)) $item $item]
+        unset ${table}::${col}::data($oid)
+        set item [lsearch ${table}::${col}::values($props($col)) $oid]
+        set ${table}::${col}::values($props($col)) \
+            [lreplace ${table}::${col}::values($props($col)) $item $item]
     }
     unset ${table}::goodoids($oid)
     return $oid
@@ -225,21 +227,21 @@
 proc simpledb::finditems { table propertymatch } {
     array set res {}
     foreach {col value} $propertymatch {
-	foreach {value oids} [array get ${table}::${col}::values $value] {
-	    foreach oid $oids {
-		if { [info exists res($oid)] } {
-		    incr res($oid)
-		} else {
-		    set res($oid) 1
-		}
-	    }
-	}
+        foreach {value oids} [array get ${table}::${col}::values $value] {
+            foreach oid $oids {
+                if { [info exists res($oid)] } {
+                    incr res($oid)
+                } else {
+                    set res($oid) 1
+                }
+            }
+        }
     }
     set retlist {}
     foreach {oid num} [array get res] {
-	if { $res($oid) == [expr {[llength $propertymatch] / 2}] } {
-	    lappend retlist $oid
-	}
+        if { $res($oid) == [llength $propertymatch] / 2 } {
+            lappend retlist $oid
+        }
     }
     return $retlist
 }
@@ -298,7 +300,7 @@
 	set collist [array names ${ns}::cols]
 	puts $fl "namespace eval $ns \{"
 	puts $fl "    array set cols \{ [array get ${ns}::cols] \}"
-	puts $fl "    array set goodoids \{ [array get ${ns}::goodoids] \}".
+	puts $fl "    array set goodoids \{ [array get ${ns}::goodoids] \}"
 	foreach col $collist {
 	    puts $fl "    namespace eval ${col} \{"
 	    puts $fl "        array set data [list [array get ${ns}::${col}::data]]"
diff --git a/rivet/packages/tclrivet/tclrivet.tcl b/rivet/packages/tclrivet/tclrivet.tcl
index 5275e11..4f279ae 100644
--- a/rivet/packages/tclrivet/tclrivet.tcl
+++ b/rivet/packages/tclrivet/tclrivet.tcl
@@ -38,7 +38,6 @@
 proc var_qs {} {}
 proc var_post {} {}
 proc upload {} {}
-proc include {} {}
 proc parse {} {}
 proc no_body {} {}
 proc env {} {}
diff --git a/rivet/packages/tclrivet/tclrivetparser.tcl b/rivet/packages/tclrivet/tclrivetparser.tcl
index 0014623..ad93c0d 100644
--- a/rivet/packages/tclrivet/tclrivetparser.tcl
+++ b/rivet/packages/tclrivet/tclrivetparser.tcl
@@ -45,7 +45,7 @@
     variable outputcmd
 
     if { $outputcmd == "" } {
-	return $outputcmd
+	    return $outputcmd
     }
     set outputcmd $newcmd
 }
@@ -80,69 +80,69 @@
     set len [expr {[string length $data] + 1}]
     set next [string index $data 0]
     while {$i < $len} {
-	incr i
-	set cur $next
-	set next [string index $data $i]
-	if { $inside == 0 } {
-	    # Outside the delimiting tags.
-	    if { $cur == [string index $starttag $p] } {
-		incr p
-		if { $p == [string length $starttag] } {
-		    append outbuf "\"\n"
-		    set inside 1
-		    set p 0
-		    continue
-		}
-	    } else {
-		if { $p > 0 } {
-		    append outbuf [string range $starttag 0 [expr {$p - 1}]]
-		    set p 0
-		}
-		switch -exact -- $cur {
-		    "\{" {
-			append outbuf "\\{"
-		    }
-		    "\}" {
-			append outbuf "\\}"
-		    }
-		    "\$" {
-			append outbuf "\\$"
-		    }
-		    "\[" {
-			append outbuf "\\["
-		    }
-		    "\]" {
-			append outbuf "\\]"
-		    }
-		    "\"" {
-			append outbuf "\\\""
-		    }
-		    "\\" {
-			append outbuf "\\\\"
-		    }
-		    default {
-			append outbuf $cur
-		    }
-		}
-		continue
-	    }
-	} else {
-	    # Inside the delimiting tags.
-	    if { $cur == [string index $endtag $p] } {
-		incr p
-		if { $p == [string length $endtag] } {
-		    append outbuf "\n$outputcmd \""
-		    set inside 0
-		    set p 0
-		}
-	    } else {
-		if { $p > 0 } {
-		    append outbuf [string range $endtag 0 $p]
-		    set p 0
-		}
-		append outbuf $cur
-	    }
-	}
+        incr i
+        set cur $next
+        set next [string index $data $i]
+        if { $inside == 0 } {
+            # Outside the delimiting tags.
+            if { $cur == [string index $starttag $p] } {
+                incr p
+                if { $p == [string length $starttag] } {
+                    append outbuf "\"\n"
+                    set inside 1
+                    set p 0
+                    continue
+                }
+            } else {
+                if { $p > 0 } {
+                    append outbuf [string range $starttag 0 [expr {$p - 1}]]
+                    set p 0
+                }
+                switch -exact -- $cur {
+                    "\{" {
+                        append outbuf \ $cur
+                    }
+                    "\}" {
+                        append outbuf \ $cur 
+                    }
+                    "\$" {
+                        append outbuf "\\$"
+                    }
+                    "\[" {
+                        append outbuf "\\["
+                    }
+                    "\]" {
+                        append outbuf "\\]"
+                    }
+                    "\"" {
+                        append outbuf "\\\""
+                    }
+                    "\\" {
+                        append outbuf "\\\\"
+                    }
+                    default {
+                        append outbuf $cur
+                    }
+                }
+                continue
+            }
+        } else {
+            # Inside the delimiting tags.
+            if { $cur == [string index $endtag $p] } {
+                incr p
+                if { $p == [string length $endtag] } {
+                    append outbuf "\n$outputcmd \""
+                    set inside 0
+                    set p 0
+                }
+            } else {
+                if { $p > 0 } {
+                    append outbuf [string range $endtag 0 $p]
+                    set p 0
+                }
+                append outbuf $cur
+            }
+        }
     }
     return $inside
 }
@@ -167,7 +167,7 @@
     set outbuf {}
     append outbuf "$outputcmd \""
     if { [parse $data outbuf] == 0 } {
-	append outbuf "\"\n"
+        append outbuf "\"\n"
     }
     return $outbuf
 }
diff --git a/rivet/rivet-tcl/cookie.tcl b/rivet/rivet-tcl/cookie.tcl
index 8c930eb..eaf1e70 100644
--- a/rivet/rivet-tcl/cookie.tcl
+++ b/rivet/rivet-tcl/cookie.tcl
@@ -4,13 +4,16 @@
 ## $Id$
 ##
 
+
+namespace eval ::rivet {
+
 ## clock_to_rfc850_gmt seconds -- Convert an integer-seconds-since-1970 
 ## click value to RFC850 format, with the additional requirement that it 
 ## be GMT only.
 ##
-proc clock_to_rfc850_gmt {seconds} {
-    return [clock format $seconds -format "%a, %d-%b-%y %T GMT" -gmt 1]
-}
+    proc clock_to_rfc850_gmt {seconds} {
+        return [clock format $seconds -format "%a, %d-%b-%y %T GMT" -gmt 1]
+    }
 
 ## make_cookie_attributes paramsArray -- Build up cookie parameters.
 ##
@@ -27,37 +30,38 @@
 ##
 ## The resut is returned.
 ##
-proc make_cookie_attributes {paramsArray} {
-    upvar 1 $paramsArray params
 
-    set cookieParams ""
-    set expiresIn 0
+    proc make_cookie_attributes {paramsArray} {
+        upvar 1 $paramsArray params
 
-    if { [info exists params(expires)] } {
-	append cookieParams "; expires=$params(expires)"
-    } else {
-	foreach {time num} [list days 86400 hours 3600 minutes 60] {
-	    if [info exists params($time)] {
-		incr expiresIn [expr $params($time) * $num]
-	    }
-	}
-	if {$expiresIn != 0} {
-	    set secs [expr [clock seconds] + $expiresIn]
-	    append cookieParams "; expires=[clock_to_rfc850_gmt $secs]"
-	}
-    }
-    if { [info exists params(path)] } {
-        append cookieParams "; path=$params(path)"
-    }
-    if { [info exists params(domain)] } {
-        append cookieParams "; domain=$params(domain)"
-    }
-    if { [info exists params(secure)] && $params(secure) == 1} {
-        append cookieParams "; secure"
-    }
+        set cookieParams ""
+        set expiresIn    0
 
-    return $cookieParams
-}
+        if { [info exists params(expires)] } {
+            append cookieParams "; expires=$params(expires)"
+        } else {
+            foreach {time num} [list days 86400 hours 3600 minutes 60] {
+                if {[info exists params($time)]} {
+                    incr expiresIn [expr {$params($time) * $num}]
+                }
+            }
+            if {$expiresIn != 0} {
+                set secs [expr [clock seconds] + $expiresIn]
+                append cookieParams "; expires=[clock_to_rfc850_gmt $secs]"
+            }
+        }
+        if { [info exists params(path)] } {
+            append cookieParams "; path=$params(path)"
+        }
+        if { [info exists params(domain)] } {
+            append cookieParams "; domain=$params(domain)"
+        }
+        if { [info exists params(secure)] && $params(secure) == 1} {
+            append cookieParams "; secure"
+        }
+
+        return $cookieParams
+    }
 
 ## cookie [set|get] cookieName ?cookieValue? [-days expireInDays]
 ##    [-hours expireInHours] [-minutes expireInMinutes]
@@ -65,50 +69,53 @@
 ##    [-path uriPathCookieAppliesTo]
 ##    [-secure 1|0]
 ##
-proc cookie {cmd name args} {
-    set badchars "\[ \t;\]"
 
-    switch -- $cmd {
-	"set" {
-	    set value [lindex $args 0]
-	    set args  [lrange $args 1 end]
-	    import_keyvalue_pairs params $args
+    proc cookie {cmd name args} {
+        set badchars "\[ \t;\]"
 
-	    if {[regexp $badchars $name]} {
-		return -code error \
-		    "name may not contain semicolons, spaces, or tabs"
-	    }
-	    if {[regexp $badchars $value]} {
-		return -code error \
-		    "value may not contain semicolons, spaces, or tabs"
-	    }
+        switch -- $cmd {
+        "set" {
+            set value [lindex $args 0]
+            set args  [lrange $args 1 end]
+            import_keyvalue_pairs params $args
 
-	    set cookieKey "Set-Cookie"
-	    set cookieValue "$name=$value"
+            if {[regexp $badchars $name]} {
+            return -code error \
+                "name may not contain semicolons, spaces, or tabs"
+            }
+            if {[regexp $badchars $value]} {
+            return -code error \
+                "value may not contain semicolons, spaces, or tabs"
+            }
 
-	    append cookieValue [make_cookie_attributes params]
+            set cookieKey "Set-Cookie"
+            set cookieValue "$name=$value"
 
-	    headers add $cookieKey $cookieValue
-	}
+            append cookieValue [make_cookie_attributes params]
 
-	"get" {
-	    ::request::global RivetCookies
+            headers add $cookieKey $cookieValue
+        }
 
-	    if {![array exists RivetCookies]} { load_cookies RivetCookies }
-	    if {![info exists RivetCookies($name)]} { return }
-	    return $RivetCookies($name)
-	}
+        "get" {
+            ::request::global RivetCookies
 
-	"delete" {
-	    ## In order to delete a cookie, we just need to set a cookie
-	    ## with a time that has already expired.
-	    cookie set $name "" -minutes -1
-	}
-	"unset" {
-	    ::request::global RivetCookies
-	    if {![array exists RivetCookies]} { load_cookies RivetCookies }
-	    if {![info exists RivetCookies($name)]} { return }
-	    unset RivetCookies($name)
-	}
+            if {![array exists RivetCookies]} { load_cookies RivetCookies }
+            if {![info exists RivetCookies($name)]} { return }
+            return $RivetCookies($name)
+        }
+
+        "delete" {
+            ## In order to delete a cookie, we just need to set a cookie
+            ## with a time that has already expired.
+            cookie set $name "" -minutes -1
+        }
+        "unset" {
+            ::request::global RivetCookies
+            if {![array exists RivetCookies]} { load_cookies RivetCookies }
+            if {![info exists RivetCookies($name)]} { return }
+            unset RivetCookies($name)
+        }
+        }
     }
+
 }
diff --git a/rivet/rivet-tcl/debug.tcl b/rivet/rivet-tcl/debug.tcl
index 30eda3d..ace19df 100644
--- a/rivet/rivet-tcl/debug.tcl
+++ b/rivet/rivet-tcl/debug.tcl
@@ -11,6 +11,7 @@
 ##    it at the global level.
 ##
 ##    Options:
+##
 ##	-subst <on|off> - Each word should be considered a variable and subst'd.
 ##	-separator <string> - A text string that goes between each variable.
 ##	-ip <ip address> - A list of IP addresses to display to.
@@ -19,70 +20,73 @@
 ##
 ###
 
-proc debug {args} {
-    ## If they've turned off debugging, we don't do anything.
-    if {[info exists ::RivetUserConf(Debug)] && !$::RivetUserConf(Debug)} {
-	return
-    }
+namespace eval ::rivet {
 
-    ## We want to save the REMOTE_ADDR for any subsequent calls to debug.
-    if {![info exists ::RivetUserConf(REMOTE_ADDR)]} {
-	set REMOTE_ADDR [env REMOTE_ADDR]
-	set ::RivetUserConf(REMOTE_ADDR) $REMOTE_ADDR
-    }
+    proc debug {args} {
+        ## If they've turned off debugging, we don't do anything.
+        if {[info exists ::RivetUserConf(Debug)] && !$::RivetUserConf(Debug)} {
+            return
+        }
+
+        ## We want to save the REMOTE_ADDR for any subsequent calls to debug.
+        if {![info exists ::RivetUserConf(REMOTE_ADDR)]} {
+            set REMOTE_ADDR [env REMOTE_ADDR]
+            set ::RivetUserConf(REMOTE_ADDR) $REMOTE_ADDR
+        }
 
 
-    ## Set some defaults for the options.
-    set data(subst) 0
-    set data(separator) <br>
+        ## Set some defaults for the options.
+        set data(subst) 0
+        set data(separator) <br>
 
-    ## Check RivetUserConf for globally set options.
-    if {[info exists ::RivetUserConf(DebugIp)]} {
-	set data(ip) $::RivetUserConf(DebugIp)
-    }
-    if {[info exists ::RivetUserConf(DebugSubst)]} {
-	set data(subst) $::RivetUserConf(DebugSubst)
-    }
-    if {[info exists ::RivetUserConf(DebugSeparator)]} {
-	set data(separator) $::RivetUserConf(DebugSeparator)
-    }
+        ## Check RivetUserConf for globally set options.
+        if {[info exists ::RivetUserConf(DebugIp)]} {
+            set data(ip) $::RivetUserConf(DebugIp)
+        }
+        if {[info exists ::RivetUserConf(DebugSubst)]} {
+            set data(subst) $::RivetUserConf(DebugSubst)
+        }
+        if {[info exists ::RivetUserConf(DebugSeparator)]} {
+            set data(separator) $::RivetUserConf(DebugSeparator)
+        }
 
-    import_keyvalue_pairs data $args
+        import_keyvalue_pairs data $args
 
-    if {[info exists data(ip)]} {
-	set can_see 0
-	foreach ip $data(ip) {
-	    if {[string match $data(ip)* $::RivetUserConf(REMOTE_ADDR)]} {
-		set can_see 1
-		break
-	    }
-	}
-	if {!$can_see} { return }
-    }
+        if {[info exists data(ip)]} {
+            set can_see 0
+            foreach ip $data(ip) {
+                if {[string match $data(ip)* $::RivetUserConf(REMOTE_ADDR)]} {
+                    set can_see 1
+                    break
+                }
+            }
+            if {!$can_see} { return }
+        }
 
-    if {[string tolower $data(subst)] != "on"} {
-	html [join $data(args)]
-	return
-    }
+        if {[string tolower $data(subst)] != "on"} {
+            ::rivet::html [join $data(args)]
+            return
+        }
 
-    set lastWasArray 0
-    foreach varName $data(args) {
-	upvar $varName var
-	if {[array exists var]} {
-	    parray $varName
-	    set lastWasArray 1
-	} elseif {[info exists var]} {
-	    if {!$lastWasArray} {
-		html $data(separator)
-	    }
-	    html $var
-	    set lastWasArray 0
-	} else {
-	    if {!$lastWasArray} {
-		html $data(separator)
-	    }
-	    html $varName
-	    set lastWasArray 0
-	}
+        set lastWasArray 0
+        foreach varName $data(args) {
+            upvar $varName var
+            if {[array exists var]} {
+                parray $varName
+                set lastWasArray 1
+            } elseif {[info exists var]} {
+                if {!$lastWasArray} {
+                    ::rivet::html $data(separator)
+                }
+                ::rivet::html $var
+                set lastWasArray 0
+            } else {
+                if {!$lastWasArray} {
+                    ::rivet::html $data(separator)
+                }
+                ::rivet::html $varName
+                set lastWasArray 0
+            }
+        }
     }
 }
diff --git a/rivet/rivet-tcl/html.tcl b/rivet/rivet-tcl/html.tcl
index b87a02a..a4ae702 100644
--- a/rivet/rivet-tcl/html.tcl
+++ b/rivet/rivet-tcl/html.tcl
@@ -14,11 +14,15 @@
 ##
 ###
 
-proc html {string args} {
-    foreach arg $args { append output <$arg> }
-    append output $string
-    for {set i [expr [llength $args] - 1]} {$i >= 0} {incr i -1} {
-	append output </[lindex [lindex $args $i] 0]>
+namespace eval ::rivet {
+
+    proc html {string args} {
+        foreach arg $args { append output <$arg> }
+        append output $string
+        for {set i [expr {[llength $args] - 1} ]} {$i >= 0} {incr i -1} {
+            append output </[lindex [lindex $args $i] 0]>
+        }
+        puts $output
     }
-    puts $output
+
 }
diff --git a/rivet/rivet-tcl/import_keyvalue_pairs.tcl b/rivet/rivet-tcl/import_keyvalue_pairs.tcl
index 4f3f965..bb4625b 100644
--- a/rivet/rivet-tcl/import_keyvalue_pairs.tcl
+++ b/rivet/rivet-tcl/import_keyvalue_pairs.tcl
@@ -10,43 +10,48 @@
 ## $Id$
 ##
 ###
-proc import_keyvalue_pairs {arrayName argsList} {
-    upvar 1 $arrayName data
 
-    # if the first character of the arg list isn't a dash, put the whole
-    # body in the args element of the array, and we're done
+namespace eval ::rivet {
 
-    if {[string index $argsList 0] != "-"} {
-	set data(args) $argsList
-	return
+    proc import_keyvalue_pairs {arrayName argsList} {
+        upvar 1 $arrayName data
+
+        # if the first character of the arg list isn't a dash, put the whole
+        # body in the args element of the array, and we're done
+
+        if {[string index $argsList 0] != "-"} {
+            set data(args) $argsList
+            return
+        }
+
+        set index 0
+        set looking 0
+        set data(args) ""
+
+        foreach arg $argsList {
+            if {$looking} {
+                set data($varName) $arg
+                set looking 0
+            } elseif {[string index $arg 0] == "-"} {
+
+                if {$arg == "--"} {
+                # "--" appears as an argument, store the rest of the arg list
+                # in the args element of the array
+                    set data(args) [lrange $argsList [expr {$index + 1} ] end]
+                    break
+                }
+
+                if {$arg == "-args"} {
+                    return -code error "-args is a reserved value."
+                }
+                set varName [string range $arg 1 end]
+                set looking 1
+            } else {
+                set data(args) [lrange $argsList $index end]
+                break
+            }
+            incr index
+        }
     }
 
-    set index 0
-    set looking 0
-    set data(args) ""
-
-    foreach arg $argsList {
-	if {$looking} {
-	    set data($varName) $arg
-	    set looking 0
-	} elseif {[string index $arg 0] == "-"} {
-
-	    if {$arg == "--"} {
-		# "--" appears as an argument, store the reset of the arg list
-		# in the args element of the array
-		set data(args) [lrange $argsList [expr $index + 1] end]
-		break
-	    }
-
-	    if {$arg == "-args"} {
-		return -code error "-args is a reserved value."
-	    }
-	    set varName [string range $arg 1 end]
-	    set looking 1
-	} else {
-	    set data(args) [lrange $argsList $index end]
-	    break
-	}
-	incr index
-    }
 }
diff --git a/rivet/rivet-tcl/import_switch_args.tcl b/rivet/rivet-tcl/import_switch_args.tcl
index 1671272..4caa472 100644
--- a/rivet/rivet-tcl/import_switch_args.tcl
+++ b/rivet/rivet-tcl/import_switch_args.tcl
@@ -8,29 +8,35 @@
 ## $Id$
 ##
 ###
-proc import_switch_args {arrayName argsList {switchList ""}} {
-    upvar 1 $arrayName array
-    set index 0
-    set array(args) ""
-    set array(switches) ""
-    if {[llength $switchList] > 0} {
-	set proofSwitches 1
-    } else {
-	set proofSwitches 0
-    }
-    foreach arg $argsList {
-	if {[string index $args 0] != "-"} {
-            set array(args) [lrange $argsList $index end]
-            break
-        } elseif {$arg == "--"} {
-	    set array(args) [lrange $argsList [expr $index + 1] end]
-	    break
-	}
-        set switch [string range $arg 1 end]
-	if {!$proofSwitches || [lsearch -exact $switchList $switch] >= 0} {
-            set array($switch) $index
-	    lappend array(switches) $switch
-	}
-        incr index
+
+namespace eval ::rivet {
+
+    proc import_switch_args {arrayName argsList {switchList ""}} {
+        upvar 1 $arrayName array
+        set index 0
+        set array(args) ""
+        set array(switches) ""
+        if {[llength $switchList] > 0} {
+            set proofSwitches 1
+        } else {
+            set proofSwitches 0
+        }
+
+        foreach arg $argsList {
+            if {[string index $arg 0] != "-"} {
+                set array(args) [lrange $argsList $index end]
+                break
+            } elseif {$arg == "--"} {
+                set array(args) [lrange $argsList [expr {$index + 1}] end]
+                break
+            }
+
+            set switch [string range $arg 1 end]
+            if {!$proofSwitches || [lsearch -exact $switchList $switch] >= 0} {
+                set array($switch) $index
+                lappend array(switches) $switch
+            }
+            incr index
+        }
     }
 }
diff --git a/rivet/rivet-tcl/incr0.tcl b/rivet/rivet-tcl/incr0.tcl
deleted file mode 100644
index d1b6166..0000000
--- a/rivet/rivet-tcl/incr0.tcl
+++ /dev/null
@@ -1,18 +0,0 @@
-###
-##
-## incr0 ?varName? ?num?
-##    Increment a variable by <num>.  If the variable doesn't exist, create
-##    it instead of returning an error.
-##
-##    varName - Name of the variable to increment.
-##    num     - Number to increment by.
-##
-## $Id$
-##
-###
-
-proc incr0 {varName {num 1}} {
-    upvar 1 $varName var
-    if {![info exists var]} { set var 0 }
-    return [incr var $num]
-}
diff --git a/rivet/rivet-tcl/lassign.tcl b/rivet/rivet-tcl/lassign.tcl
index e0ebd87..f001ab7 100644
--- a/rivet/rivet-tcl/lassign.tcl
+++ b/rivet/rivet-tcl/lassign.tcl
@@ -8,9 +8,13 @@
 ##
 ###
 
-proc lassign {list args} {
-    foreach elem $list varName $args {
-	upvar 1 $varName var
-	set var $elem
+namespace eval ::rivet {
+
+    proc lassign {list args} {
+        foreach elem $list varName $args {
+            upvar 1 $varName var
+            set var $elem
+        }
     }
+
 }
diff --git a/rivet/rivet-tcl/lempty.tcl b/rivet/rivet-tcl/lempty.tcl
index 4245a5b..7b54d35 100644
--- a/rivet/rivet-tcl/lempty.tcl
+++ b/rivet/rivet-tcl/lempty.tcl
@@ -8,7 +8,11 @@
 ##
 ###
 
-proc lempty {list} {
-    if {[catch {llength $list} len]} { return 0 }
-    return [expr $len == 0]
+namespace eval ::rivet {
+
+    proc lempty {list} {
+        if {[catch {llength $list} len]} { return 0 }
+        return [expr {$len == 0}]
+    }
+
 }
diff --git a/rivet/rivet-tcl/lmatch.tcl b/rivet/rivet-tcl/lmatch.tcl
index 4ba2826..89f28e2 100644
--- a/rivet/rivet-tcl/lmatch.tcl
+++ b/rivet/rivet-tcl/lmatch.tcl
@@ -13,38 +13,40 @@
 ##
 ###
 
-proc lmatch {args} {
-    set modes(-exact)  0
-    set modes(-glob)   1
-    set modes(-regexp) 2
+namespace eval ::rivet {
+    proc lmatch {args} {
+        set modes(-exact)  0
+        set modes(-glob)   1
+        set modes(-regexp) 2
 
-    if {[llength $args] == 3} {
-	lassign $args mode list pattern
-    } elseif {[llength $args] == 2} {
-	set mode -glob
-	lassign $args list pattern
-    } else {
-        return -code error \
-	    {wrong # args: should be "lmatch ?mode? list pattern"}
-    }
+        if {[llength $args] == 3} {
+            lassign $args mode list pattern
+        } elseif {[llength $args] == 2} {
+            set mode -glob
+            lassign $args list pattern
+        } else {
+            return -code error \
+                {wrong # args: should be "lmatch ?mode? list pattern"}
+        }
 
-    if {![info exists modes($mode)]} {
-	return -code error \
-	    "bad search mode \"$mode\": must be -exact, -glob, or -regexp"
-    }
-    set mode $modes($mode)
+        if {![info exists modes($mode)]} {
+            return -code error \
+                "bad search mode \"$mode\": must be -exact, -glob, or -regexp"
+        }
+        set mode $modes($mode)
 
-    set return {}
-    foreach elem $list {
-	if {$mode == 0} {
-	    if {[string compare $elem $pattern] == 0} { lappend return $elem }
-	}
-	if {$mode == 1} {
-	    if {[string match $pattern $elem]} { lappend return $elem }
-	}
-	if {$mode == 2} {
-	    if {[regexp $pattern $elem]} { lappend return $elem }
-	}
+        set return {}
+        foreach elem $list {
+            if {$mode == 0} {
+                if {[string compare $elem $pattern] == 0} { lappend return $elem }
+            }
+            if {$mode == 1} {
+                if {[string match $pattern $elem]} { lappend return $elem }
+            }
+            if {$mode == 2} {
+                if {[regexp $pattern $elem]} { lappend return $elem }
+            }
+        }
+        return $return
     }
-    return $return
 }
diff --git a/rivet/rivet-tcl/load_cookies.tcl b/rivet/rivet-tcl/load_cookies.tcl
index aed8922..61ce062 100644
--- a/rivet/rivet-tcl/load_cookies.tcl
+++ b/rivet/rivet-tcl/load_cookies.tcl
@@ -7,15 +7,20 @@
 ## $Id$
 ##
 ###
-proc load_cookies {{arrayName cookies}} {
-    upvar 1 $arrayName cookies
 
-    set HTTP_COOKIE [env HTTP_COOKIE]
+namespace eval ::rivet {
 
-    foreach pair [split $HTTP_COOKIE ";"] {
-	set pair [split [string trim $pair] "="]
-	set key [lindex $pair 0]
-	set value [lindex $pair 1]
-	set cookies($key) [list $value]
+    proc load_cookies {{arrayName cookies}} {
+        upvar 1 $arrayName cookies
+
+        set HTTP_COOKIE [env HTTP_COOKIE]
+
+        foreach pair [split $HTTP_COOKIE ";"] {
+            set pair [split [string trim $pair] "="]
+            set key [lindex $pair 0]
+            set value [lindex $pair 1]
+            set cookies($key) [list $value]
+        }
     }
+
 }
diff --git a/rivet/rivet-tcl/load_response.tcl b/rivet/rivet-tcl/load_response.tcl
index cfb5a97..d1b1290 100644
--- a/rivet/rivet-tcl/load_response.tcl
+++ b/rivet/rivet-tcl/load_response.tcl
@@ -9,20 +9,24 @@
 ##
 ###
 
-proc load_response {{arrayName response}} {
-    upvar 1 $arrayName response
+namespace eval ::rivet {
 
-    foreach {var elem} [var all] {
-	if {[info exists response(__$var)]} {
-		# we have seen var multiple times already, add to the list
-		lappend response($var) $elem
-	} elseif {[info exists response($var)]} {
-		# second occurence of var,  convert response(var) list:
-		set response($var) [list $response($var) $elem]
-		set response(__$var) ""
-	} else {
-		# first time seeing this var
-		set response($var) $elem
-	}
+    proc load_response {{arrayName response}} {
+        upvar 1 $arrayName response
+
+        foreach {var elem} [::rivet::var all] {
+            if {[info exists response(__$var)]} {
+                # we have seen var multiple times already, add to the list
+                lappend response($var) $elem
+            } elseif {[info exists response($var)]} {
+                # second occurence of var,  convert response(var) list:
+                set response($var) [list $response($var) $elem]
+                set response(__$var) ""
+            } else {
+                # first time seeing this var
+                set response($var) $elem
+            }
+        }
     }
+
 }
diff --git a/rivet/rivet-tcl/parray.tcl b/rivet/rivet-tcl/parray.tcl
index d3012e7..1f7ce80 100644
--- a/rivet/rivet-tcl/parray.tcl
+++ b/rivet/rivet-tcl/parray.tcl
@@ -11,22 +11,27 @@
 ##
 ###
 
-proc parray {arrayName {pattern *}} {
-    upvar 1 $arrayName array
-    if {![array exists array]} {
-        return -code error "\"$arrayName\" isn't an array"
-    }
-    set maxl 0
-    foreach name [lsort [array names array $pattern]] {
-        if {[string length $name] > $maxl} {
-            set maxl [string length $name]
+namespace eval ::rivet {
+
+    proc parray {arrayName {pattern *}} {
+        upvar 1 $arrayName array
+        if {![array exists array]} {
+            return -code error "\"$arrayName\" isn't an array"
         }
+        set maxl 0
+        foreach name [lsort [array names array $pattern]] {
+            if {[string length $name] > $maxl} {
+                set maxl [string length $name]
+            }
+        }
+        puts stdout "<PRE><B>$arrayName</B>"
+        set maxl [expr {$maxl + [string length $arrayName] + 2}]
+        foreach name [lsort [array names array $pattern]] {
+            set nameString [format %s(%s) $arrayName $name]
+            puts stdout [format "%-*s = %s" $maxl $nameString $array($name)]
+        }
+        puts stdout "</PRE>"
     }
-    puts stdout "<PRE><B>$arrayName</B>"
-    set maxl [expr {$maxl + [string length $arrayName] + 2}]
-    foreach name [lsort [array names array $pattern]] {
-        set nameString [format %s(%s) $arrayName $name]
-        puts stdout [format "%-*s = %s" $maxl $nameString $array($name)]
-    }
-    puts stdout "</PRE>"
+
+    namespace export parray
 }
diff --git a/rivet/rivet-tcl/parray_table.tcl b/rivet/rivet-tcl/parray_table.tcl
new file mode 100644
index 0000000..add25ba
--- /dev/null
+++ b/rivet/rivet-tcl/parray_table.tcl
@@ -0,0 +1,39 @@
+##
+## -- parray_table <arrayName> ?pattern? ?html-attibutes?
+##
+##	tablearray prints an array data in HTML table
+##	This is good when a table is enough to print consistently
+##	related data. 
+##
+##	arrayName - Name of the array to display
+##	pattern   - Wildcard pattern of variables. An empty string 
+##		        is tantamout a "*" and prints the whole array
+##	html-attributes - 
+##              list attribute-value pairs to be given
+##              to the <table> element tag
+##
+## $Id$
+##
+##
+
+namespace eval ::rivet {
+
+    proc parray_table {arrayName {pattern "*"} {htmlAttributes ""}} {
+        upvar 1 $arrayName array
+        if {![array exists array]} {
+            return -code error "\"$arrayName\" isn't an array"
+        }
+        puts -nonewline stdout "<table"
+	    foreach {attr attrval} $htmlAttributes {
+	        puts -nonewline " $attr=\"$attrval\""
+	    }
+
+	    puts "><thead><tr><th colspan=\"2\">$arrayName</th></tr></thead>"
+        puts stdout "<tbody>"
+        foreach name [lsort [array names array $pattern]] {
+            puts stdout [format "<tr><td>%s</td><td>%s</td></tr>" $name $array($name)]
+        }
+        puts stdout "</tbody></table>"
+    }
+
+}
diff --git a/rivet/rivet-tcl/putsnnl.tcl b/rivet/rivet-tcl/putsnnl.tcl
new file mode 100644
index 0000000..238b30a
--- /dev/null
+++ b/rivet/rivet-tcl/putsnnl.tcl
@@ -0,0 +1,75 @@
+##
+## putsnnl ?-sgml? <string> <width>
+##
+## Shorthand for 'puts -nonewline' with the extra feature
+## of being able to print a string padded with spaces.
+## The ouput has a fixed width <width> and string in <string>
+## is left (width > 0) or right (width < 0) aligned.
+##
+## When the switch -sgml is passed in as first argument
+## the padding is done with &nbsp; SGML entities.
+##
+## $Id$
+##
+
+namespace eval ::rivet {
+    proc putsnnl {args } {
+
+        set nargs [llength $args]
+
+        if {$nargs == 1} {
+            set width undefined
+            set output_string [lindex $args 0]
+        } elseif {$nargs == 2} {
+            if {[string match "-sgml" [lindex $args 0]]} {
+                set output_string [lindex $args 1]
+                set padding "&nbsp;"
+                set width undefined
+            } else {
+                set output_string [lindex $args 0]
+                set width [lindex $args 1]
+                set padding " "
+            }
+        } elseif {$nargs == 3} {
+            if {![string match "-sgml" [lindex $args 0]]} {
+                return -code error -error_code wrong_param \
+                                   -error_info "Expected -sgml switch" \
+                                               "Expected -sgml switch"
+            }
+
+            set output_string [lindex $args 1]
+            set width [lindex $args 2]
+	    set padding "&nbsp;"
+        } else {
+            return -code error -error_code wrong_num_param \
+                               -error_info "Expected at most 3 args, got $nargs ($args)" \
+                                           "Expected at most 3 args, got $nargs ($args)"
+        }
+
+        if {[string is integer $width]} {
+            if {$width == 0} {
+                set final_string ""
+            } else {
+
+                set string_l [string length $output_string]
+
+                if { $string_l > abs($width)} {
+                    set final_string [string range $output_string 0 [expr abs($width)-1]]
+                } else {
+
+                    set padding [string repeat $padding [expr abs($width) - $string_l]]
+                    if {$width > 0} {
+                        set final_string [format "%s%s" $padding $output_string]
+                    } else {
+                        set final_string [format "%s%s" $output_string $padding]
+                    }
+                }
+            }
+        } else {
+            set final_string $output_string
+        }
+
+        puts -nonewline $final_string
+    }
+}
+##
diff --git a/rivet/rivet-tcl/random.tcl b/rivet/rivet-tcl/random.tcl
index e65d911..1b5e8d5 100644
--- a/rivet/rivet-tcl/random.tcl
+++ b/rivet/rivet-tcl/random.tcl
@@ -12,18 +12,23 @@
 ## $Id$
 ##
 ###
-proc random {args} {
-    global _ran
 
-    if {[llength $args] > 1} {
-	set _ran [lindex $args 1]
-    } else {
-	set period 233280
-	if {[info exists _ran]} {
-	    set _ran [expr { ($_ran*9301 + 49297) % $period }]
-	} else {
-	    set _ran [expr { [clock seconds] % $period } ]
-	}
-	return [expr { int($args*($_ran/double($period))) } ]
+namespace eval ::rivet {
+
+    proc random {args} {
+        global _ran
+
+        if {[llength $args] > 1} {
+            set _ran [lindex $args 1]
+        } else {
+            set period 233280
+            if {[info exists _ran]} {
+                set _ran [expr { ($_ran*9301 + 49297) % $period }]
+            } else {
+                set _ran [expr { [clock seconds] % $period } ]
+            }
+            return [expr { int($args*($_ran/double($period))) } ]
+        }
     }
+
 }
diff --git a/rivet/rivet-tcl/read_file.tcl b/rivet/rivet-tcl/read_file.tcl
index d6042c8..8146362 100644
--- a/rivet/rivet-tcl/read_file.tcl
+++ b/rivet/rivet-tcl/read_file.tcl
@@ -8,9 +8,13 @@
 ##
 ###
 
-proc read_file {file} {
-    set fp [open $file]
-    set x [read $fp]
-    close $fp
-    return $x
+namespace eval ::rivet {
+
+    proc read_file {file} {
+        set fp [open $file]
+        set x [read $fp]
+        close $fp
+        return $x
+    }
+
 }
diff --git a/rivet/rivet-tcl/rivet_command_document.tcl b/rivet/rivet-tcl/rivet_command_document.tcl
index 5464590..c18b5e8 100644
--- a/rivet/rivet-tcl/rivet_command_document.tcl
+++ b/rivet/rivet-tcl/rivet_command_document.tcl
@@ -9,44 +9,48 @@
 ## $Id$
 ##
 ###
-proc rivet_command_document {list} {
-    array set info $list
+namespace eval ::rivet {
 
-    puts "<HEAD>"
-    puts "<TITLE>$info(name) Documentation</TITLE>"
-    puts "</HEAD>"
-    puts "<BODY BGCOLOR=WHITE VLINK=blue>"
+    proc rivet_command_document {list} {
+        array set info $list
 
-    puts "<CENTER>"
-    puts {<FONT SIZE="+3">}
-    puts "$info(name) - $info(package)"
-    puts "</FONT>"
-    puts "<BR>"
-    puts "<B>"
-    puts {<A HREF="#synopsis">Synopsis</A>}
-    puts " * "
-    puts {<A HREF="#description">Description</A>}
-    if {[info exists info(seealso)]} {
-	puts " * "
-	puts {<A HREF="#seealso">See Also</A>}
+        puts "<HEAD>"
+        puts "<TITLE>$info(name) Documentation</TITLE>"
+        puts "</HEAD>"
+        puts "<BODY BGCOLOR=WHITE VLINK=blue>"
+
+        puts "<CENTER>"
+        puts {<FONT SIZE="+3">}
+        puts "$info(name) - $info(package)"
+        puts "</FONT>"
+        puts "<BR>"
+        puts "<B>"
+        puts {<A HREF="#synopsis">Synopsis</A>}
+        puts " * "
+        puts {<A HREF="#description">Description</A>}
+        if {[info exists info(seealso)]} {
+            puts " * "
+            puts {<A HREF="#seealso">See Also</A>}
+        }
+        puts "</B>"
+        puts "</CENTER>"
+
+        puts {<H3><A NAME="name" HREF="#name">Name</A></H3>}
+        puts "<B>$info(name) - $info(short)</B>"
+
+        if {![info exists info(command)]} { set info(command) $info(name) }
+
+        puts {<H3><A NAME="synopsis" HREF="#synopsis">Synopsis</A></H3>}
+        puts "$info(command)"
+        if {[info exists info(arguments)]} { puts "<I>$info(arguments)</I>" }
+
+        puts {<H3><A NAME="description" HREF="#description">Description</A></H3>}
+        puts $info(description)
+
+        if {[info exists info(seealso)]} {
+            puts {<H3><A NAME="seealso" HREF="#seealso">See Also</A></H3>}
+            puts $info(seealso)
+        }
     }
-    puts "</B>"
-    puts "</CENTER>"
 
-    puts {<H3><A NAME="name" HREF="#name">Name</A></H3>}
-    puts "<B>$info(name) - $info(short)</B>"
-
-    if {![info exists info(command)]} { set info(command) $info(name) }
-
-    puts {<H3><A NAME="synopsis" HREF="#synopsis">Synopsis</A></H3>}
-    puts "$info(command)"
-    if {[info exists info(arguments)]} { puts "<I>$info(arguments)</I>" }
-
-    puts {<H3><A NAME="description" HREF="#description">Description</A></H3>}
-    puts $info(description)
-
-    if {[info exists info(seealso)]} {
-	puts {<H3><A NAME="seealso" HREF="#seealso">See Also</A></H3>}
-	puts $info(seealso)
-    }
 }
diff --git a/rivet/rivet-tcl/tclIndex b/rivet/rivet-tcl/tclIndex
index e9a9cdb..d54d8d2 100644
--- a/rivet/rivet-tcl/tclIndex
+++ b/rivet/rivet-tcl/tclIndex
@@ -6,20 +6,23 @@
 # element name is the name of a command and the value is
 # a script that loads the command.
 
-set auto_index(debug) [list source [file join $dir debug.tcl]]
-set auto_index(lassign) [list source [file join $dir lassign.tcl]]
-set auto_index(html) [list source [file join $dir html.tcl]]
-set auto_index(incr0) [list source [file join $dir incr0.tcl]]
-set auto_index(load_response) [list source [file join $dir load_response.tcl]]
-set auto_index(parray) [list source [file join $dir parray.tcl]]
-set auto_index(read_file) [list source [file join $dir read_file.tcl]]
-set auto_index(wrap) [list source [file join $dir wrap.tcl]]
-set auto_index(wrapline) [list source [file join $dir wrap.tcl]]
-set auto_index(lempty) [list source [file join $dir lempty.tcl]]
-set auto_index(load_cookies) [list source [file join $dir load_cookies.tcl]]
-set auto_index(clock_to_rfc850_gmt) [list source [file join $dir cookie.tcl]]
-set auto_index(make_cookie_attributes) [list source [file join $dir cookie.tcl]]
-set auto_index(cookie) [list source [file join $dir cookie.tcl]]
-set auto_index(import_keyvalue_pairs) [list source [file join $dir import_keyvalue_pairs.tcl]]
-set auto_index(import_switch_args) [list source [file join $dir import_switch_args.tcl]]
-set auto_index(rivet_command_document) [list source [file join $dir rivet_command_document.tcl]]
+set auto_index(::rivet::html) [list source [file join $dir html.tcl]]
+set auto_index(::rivet::lassign) [list source [file join $dir lassign.tcl]]
+set auto_index(::rivet::random) [list source [file join $dir random.tcl]]
+set auto_index(::rivet::rivet_command_document) [list source [file join $dir rivet_command_document.tcl]]
+set auto_index(::rivet::putsnnl) [list source [file join $dir putsnnl.tcl]]
+set auto_index(::rivet::load_response) [list source [file join $dir load_response.tcl]]
+set auto_index(::rivet::debug) [list source [file join $dir debug.tcl]]
+set auto_index(::rivet::clock_to_rfc850_gmt) [list source [file join $dir cookie.tcl]]
+set auto_index(::rivet::make_cookie_attributes) [list source [file join $dir cookie.tcl]]
+set auto_index(::rivet::cookie) [list source [file join $dir cookie.tcl]]
+set auto_index(::rivet::lempty) [list source [file join $dir lempty.tcl]]
+set auto_index(::rivet::import_switch_args) [list source [file join $dir import_switch_args.tcl]]
+set auto_index(::rivet::lmatch) [list source [file join $dir lmatch.tcl]]
+set auto_index(::rivet::read_file) [list source [file join $dir read_file.tcl]]
+set auto_index(::rivet::import_keyvalue_pairs) [list source [file join $dir import_keyvalue_pairs.tcl]]
+set auto_index(::rivet::parray) [list source [file join $dir parray.tcl]]
+set auto_index(::rivet::wrap) [list source [file join $dir wrap.tcl]]
+set auto_index(::rivet::wrapline) [list source [file join $dir wrap.tcl]]
+set auto_index(::rivet::parray_table) [list source [file join $dir parray_table.tcl]]
+set auto_index(::rivet::load_cookies) [list source [file join $dir load_cookies.tcl]]
diff --git a/rivet/rivet-tcl/wrap.tcl b/rivet/rivet-tcl/wrap.tcl
index 8352a09..6b512e8 100644
--- a/rivet/rivet-tcl/wrap.tcl
+++ b/rivet/rivet-tcl/wrap.tcl
@@ -10,17 +10,19 @@
 ##
 ###
 
-proc wrap {string maxlen {html ""}} {
-    set splitstring {}
-    foreach line [split $string "\n"] {
-	lappend splitstring [wrapline $line $maxlen $html]
+namespace eval ::rivet {
+
+    proc wrap {string maxlen {html ""}} {
+        set splitstring {}
+        foreach line [split $string "\n"] {
+            lappend splitstring [wrapline $line $maxlen $html]
+        }
+        if {$html == "-html"} {
+            return [join $splitstring "<br>"]
+        } else {
+            return [join $splitstring "\n"]
+        }
     }
-    if {$html == "-html"} {
-	return [join $splitstring "<br>"]
-    } else {
-	return [join $splitstring "\n"]
-    }
-}
 
 ##
 ## wrapline -- Given a line and a maximum length and option "-html"
@@ -31,20 +33,22 @@
 ## the lines separated by html <br> line breaks, otherwise the lines
 ## are returned separated by newline characters.
 ##
-proc wrapline {line maxlen {html ""}} {
-    set string [split $line " "]
-    set newline [list [lindex $string 0]]
-    foreach word [lrange $string 1 end] {
-	if {[string length $newline]+[string length $word] > $maxlen} {
-	    lappend lines [join $newline " "]
-	    set newline {}
-	}
-	lappend newline $word
+    proc wrapline {line maxlen {html ""}} {
+        set string [split $line " "]
+        set newline [list [lindex $string 0]]
+        foreach word [lrange $string 1 end] {
+            if {[string length $newline]+[string length $word] > $maxlen} {
+                lappend lines [join $newline " "]
+                set newline {}
+            }
+            lappend newline $word
+        }
+        lappend lines [join $newline " "]
+        if {$html == "-html"} {
+            return [join $lines <br>]
+        } else {
+            return [join $lines "\n"]
+        }
     }
-    lappend lines [join $newline " "]
-    if {$html == "-html"} {
-	return [join $lines <br>]
-    } else {
-	return [join $lines "\n"]
-    }
+
 }
diff --git a/src/Makefile.am b/src/Makefile.am
index db91777..3c5b294 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,7 +26,7 @@
 # ... and these two.  We want to put the libs in the package path,
 # rather than the standard library location for the system.
 lib_libexecdir = @RIVET_TCL_TARGET@
-lib_libexec_LTLIBRARIES = librivet.la librivetparser.la
+lib_libexec_LTLIBRARIES = librivetlib.la librivetparser.la
 
 #
 # Apache Rivet Module, mod_rivet.so / mod_rivet.dll
@@ -50,19 +50,19 @@
 #
 # Rivet Library
 #
-librivet_la_SOURCES = rivetList.c rivetCrypt.c rivetWWW.c rivetPkgInit.c
-librivet_la_LDFLAGS = @TCL_LIB_SPEC@ @APXS_LDFLAGS@ @APR_LDFLAGS@ -module -avoid-version
-librivet_la_LIBADD = @TCL_LIBS@ @APXS_LIBS@
-librivet_la_CPPFLAGS = @TCL_INCLUDES@ @APXS_CPPFLAGS@ @APXS_INCLUDES@ @APR_INCLUDES@ @APR_CPPFLAGS@ -DSTART_TAG='"<?"' -DEND_TAG='"?>"'
+librivetlib_la_SOURCES = rivetList.c rivetCrypt.c rivetWWW.c rivetPkgInit.c
+librivetlib_la_LDFLAGS = @TCL_STUB_LIB_SPEC@ @APXS_LDFLAGS@ @APR_LDFLAGS@ -module -avoid-version
+librivetlib_la_LIBADD =  @APXS_LIBS@
+librivetlib_la_CPPFLAGS = @MOD_RIVET_INCLUDES@ @TCL_INCLUDES@ @APXS_CPPFLAGS@ @APXS_INCLUDES@ @APR_INCLUDES@ @APR_CPPFLAGS@ -DSTART_TAG='"<?"' -DEND_TAG='"?>"' -DUSE_TCL_STUBS
 
 #
 # Rivet Parser Library
 #
 librivetparser_la_SOURCES = rivetParser.c parserPkgInit.c
-librivetparser_la_LDFLAGS = @TCL_LIB_SPEC@ @APXS_LDFLAGS@ -module -avoid-version
-librivetparser_la_LIBADD = @TCL_LIBS@ @APXS_LIBS@
-librivetparser_la_CPPFLAGS = @TCL_INCLUDES@ @APXS_CPPFLAGS@ @APXS_INCLUDES@ -DSTART_TAG='"<?"' -DEND_TAG='"?>"'
-
+librivetparser_la_LDFLAGS = @TCL_STUB_LIB_SPEC@ @APXS_LDFLAGS@ -module -avoid-version
+librivetparser_la_LIBADD = @APXS_LIBS@
+librivetparser_la_CPPFLAGS = @TCL_INCLUDES@ @APXS_CPPFLAGS@ @APXS_INCLUDES@ -DSTART_TAG='"<?"' -DEND_TAG='"?>"' -DUSE_TCL_STUBS
+ 
 SUBDIRS = @apache_version_dir@
 
 # Removing libtool .la files from installation
diff --git a/src/apache-2/Makefile.am b/src/apache-2/Makefile.am
index 8d101c6..66e53c4 100644
--- a/src/apache-2/Makefile.am
+++ b/src/apache-2/Makefile.am
@@ -31,20 +31,20 @@
 #
 # Apache Rivet Module, mod_rivet.so / mod_rivet.dll
 #
-mod_rivet_la_SOURCES = 			\
-	apache_multipart_buffer.c 	\
-	apache_request.c			\
-	mod_rivet.c 				\
-	TclWebapache.c 				\
-	rivetCore.c					\
-	../rivetChannel.c 			\
-	../rivetParser.c
+mod_rivet_la_SOURCES = 			        \
+	        apache_multipart_buffer.c 	\
+	        apache_request.c			\
+	        mod_rivet.c 				\
+	        TclWebapache.c 				\
+	        rivetCore.c					\
+	        ../rivetChannel.c 			\
+            ../rivetParser.c
 
 ##mod_rivet_la_SOURCES = mod_rivet.c mod_rivet.h
 
 mod_rivet_la_LDFLAGS = @TCL_LIB_SPEC@ @APXS_LDFLAGS@  @APR_LDFLAGS@ -module -avoid-version
 mod_rivet_la_LIBADD = @TCL_LIBS@ @APXS_LIBS@
-mod_rivet_la_CPPFLAGS = @TCL_INCLUDES@  @APXS_CPPFLAGS@ @APXS_INCLUDES@ @APR_CPPFLAGS@  @APR_INCLUDES@ -DSTART_TAG='"<?"' -DEND_TAG='"?>"'
+mod_rivet_la_CPPFLAGS = @TCL_INCLUDES@ @APXS_CPPFLAGS@ @APXS_INCLUDES@ @APR_CPPFLAGS@ @APR_INCLUDES@ -DSTART_TAG='"<?"' -DEND_TAG='"?>"'
 
 # APXS_CPPFLAGS_SHLIB
 
diff --git a/src/apache-2/apache_request.c b/src/apache-2/apache_request.c
index a1a01bc..0b4c7f7 100644
--- a/src/apache-2/apache_request.c
+++ b/src/apache-2/apache_request.c
@@ -46,11 +46,8 @@
         long length = r->remaining;
 
         if (length > req->post_max && req->post_max > 0) {
-            //TODO: fix logging apr_log_rerror
-            //ap_log_error(REQ_ERROR, "[libapreq] entity too large (%d, max=%d)",
-            //        (int)length, req->post_max);
-            //apr_log_rerror(REQ_ERROR, "[libapreq] entity too large (%d, max=%d)",
-            //        (int)length, req->post_max);
+            ap_log_rerror(REQ_ERROR,"entity too large (%d, max=%d)",
+					(int)length, req->post_max);
             return HTTP_REQUEST_ENTITY_TOO_LARGE;
         }
 
@@ -391,7 +388,6 @@
         } else if (ct && strncaseEQ(ct, MULTIPART_ENCTYPE, MULTIPART_ENCTYPE_LENGTH)) {
             result = ApacheRequest_parse_multipart(req,ct);
         } else {
-            //TODO: fix logging apr_log_rerror
             ap_log_rerror(REQ_ERROR, "unknown content-type: `%s'", ct);
             result = HTTP_INTERNAL_SERVER_ERROR;
         }
@@ -493,14 +489,14 @@
 int
 ApacheRequest_parse_multipart(ApacheRequest *req,const char* ct)
 {
-    request_rec *r = req->r;
-    int rc = OK;
-    long length;
-    char *boundary;
-    multipart_buffer *mbuff;
-    ApacheUpload *upload = NULL;
-    apr_status_t  status;
-    char error[1024];
+    request_rec 	*r = req->r;
+    int 		rc = OK;
+    long 		length;
+    char 		*boundary;
+    multipart_buffer 	*mbuff;
+    ApacheUpload 	*upload = NULL;
+    apr_status_t  	status;
+    char 		error[1024];
 
     if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) {
         return rc;
@@ -511,9 +507,8 @@
     }
 
     if ((length = r->remaining) > req->post_max && req->post_max > 0) {
-        //TODO: fix logging apr_log_rerror
-        //apr_log_rerror(REQ_ERROR, "entity too large (%d, max=%d)",
-        //        (int)length, req->post_max);
+        ap_log_rerror(REQ_ERROR,"entity too large (%d, max=%d)",
+				(int)length,req->post_max);
         return HTTP_REQUEST_ENTITY_TOO_LARGE;
     }
 
@@ -542,7 +537,7 @@
 
         if (!header) {
 #ifdef DEBUG
-            apr_log_rerror(REQ_ERROR,"Silently dropping remaining '%ld' bytes", r->remaining);
+            ap_log_rerror(REQ_ERROR,"Silently dropping remaining '%ld' bytes", r->remaining);
 #endif
 	    do { } while ( ap_get_client_block(r, buff, sizeof(buff)) > 0 );
             	
@@ -576,8 +571,9 @@
             if (!param) continue; /* shouldn't happen, but just in case. */
 
             if (req->disable_uploads) {
-                //TODO: fix logging apr_log_rerror
-                //apr_log_rerror(REQ_ERROR, "[libapreq] file upload forbidden");
+#if DEBUG
+                ap_log_rerror(REQ_ERROR, "[libapreq] file upload forbidden");
+#endif
                 return HTTP_FORBIDDEN;
             }
 
diff --git a/src/apache-2/mod_rivet.c b/src/apache-2/mod_rivet.c
index cbd790d..4d30942 100644
--- a/src/apache-2/mod_rivet.c
+++ b/src/apache-2/mod_rivet.c
@@ -28,6 +28,8 @@
 /* as long as we need to emulate ap_chdir_file we need to include unistd.h */
 #include <unistd.h>
 
+#include <dlfcn.h>
+
 /* Apache includes */
 #include <httpd.h>
 #include <http_config.h>
@@ -56,6 +58,8 @@
 #include "rivetParser.h"
 #include "rivetChannel.h"
 
+#define MODNAME "mod_rivet"
+
 //module AP_MODULE_DECLARE_DATA rivet_module;
 
 /* This is used *only* in the PanicProc.  Otherwise, don't touch it! */
@@ -89,9 +93,9 @@
  
 static int Rivet_chdir_file (const char *file)
 {
-    const  char *x;
-    int    chdir_retval = 0;
-    char chdir_buf[HUGE_STRING_LEN];
+    const char  *x;
+    int         chdir_retval = 0;
+    char        chdir_buf[HUGE_STRING_LEN];
 
     x = strrchr(file, '/');
     if (x == NULL) {
@@ -268,6 +272,17 @@
             obj,
             TCL_GLOBAL_ONLY);
     Tcl_DecrRefCount(obj);
+
+#if RIVET_DISPLAY_VERSION
+    obj = Tcl_NewStringObj(RIVET_PACKAGE_VERSION, -1);
+    Tcl_IncrRefCount(obj);
+    Tcl_SetVar2Ex(interp,
+            "server",
+            "RIVET_PACKAGE_VERSION",
+            obj,
+            TCL_GLOBAL_ONLY);
+    Tcl_DecrRefCount(obj);
+#endif
 }
 
 static void
@@ -368,9 +383,7 @@
             }
         }
 
-        Tcl_SetVar( interp, "errorOutbuf",
-                Tcl_GetStringFromObj( outbuf, NULL ),
-                TCL_GLOBAL_ONLY );
+        Tcl_SetVar( interp, "errorOutbuf",Tcl_GetStringFromObj( outbuf, NULL ),TCL_GLOBAL_ONLY );
 
         /* If we don't have an error script, use the default error handler. */
         if (conf->rivet_error_script ) {
@@ -502,7 +515,6 @@
         if (toplevel) {
             if (rsc->rivet_before_script) {
                 Tcl_AppendObjToObj(outbuf,rsc->rivet_before_script);
-//              Tcl_NewStringObj(rsc->rivet_before_script, -1));
             }
         }
 
@@ -529,7 +541,6 @@
         }
         if (toplevel) {
             if (rsc->rivet_after_script) {
-//              Tcl_AppendObjToObj(outbuf,Tcl_NewStringObj(rsc->rivet_after_script, -1));
                 Tcl_AppendObjToObj(outbuf,rsc->rivet_after_script);
             }
         }
@@ -586,8 +597,6 @@
 static void
 Rivet_CleanupRequest( request_rec *r )
 {
-
-
 #if 0
     apr_table_t *t;
     apr_array_header_t *arr;
@@ -886,16 +895,10 @@
 
     Tcl_SetStdChannel(*(rsc->outchannel), TCL_STDOUT);
 
-    /* Initialize the interpreter with Rivet's Tcl commands. */
-    Rivet_InitCore( interp );
-
-    /* Create a global array with information about the server. */
-    Rivet_InitServerVariables( interp, p );
-    Rivet_PropagateServerConfArray( interp, rsc );
-
     /* Set up interpreter associated data */
+
     globals = apr_pcalloc(p, sizeof(rivet_interp_globals));
-    Tcl_SetAssocData(interp, "rivet", NULL, globals);
+    Tcl_SetAssocData(interp,"rivet",NULL,globals);
     
     /* 
      * abort_page status variables in globals are set here and then 
@@ -903,6 +906,9 @@
      * completed 
      */
 
+    /* Rivet commands namespace is created */
+    globals->rivet_ns = Tcl_CreateNamespace (interp,RIVET_NS,NULL,
+                                            (Tcl_NamespaceDeleteProc *)NULL);
     globals->page_aborting = 0;
     globals->abort_code = NULL;
 
@@ -916,26 +922,70 @@
 
     rivet_tcl = Tcl_NewStringObj(RIVET_DIR,-1);
     Tcl_IncrRefCount(rivet_tcl);
+
     if (Tcl_ListObjReplace(interp,auto_path,0,0,1,&rivet_tcl) == TCL_ERROR)
     {
-        ap_log_error( APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
-                    "error setting auto_path: %s",Tcl_GetStringFromObj(auto_path,NULL));
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
+                     MODNAME ": error setting auto_path: %s",
+		     Tcl_GetStringFromObj(auto_path,NULL));
     } 
     Tcl_DecrRefCount(rivet_tcl);
-    
-    if (Tcl_PkgRequire(interp, "RivetTcl", "1.1", 1) == NULL)
+
+    /* Initialize the interpreter with Rivet's Tcl commands. */
+    Rivet_InitCore(interp);
+
+    /* Create a global array with information about the server. */
+    Rivet_InitServerVariables(interp, p );
+    Rivet_PropagateServerConfArray( interp, rsc );
+
+    /* Eval Rivet's init.tcl file to load in the Tcl-level commands. */
+
+    /* Watch out! Calling Tcl_PkgRequire with a version number binds this module to
+     * the 'package provide' statement in rivet/init.tcl 
+     */
+
+    /*  If rivet was configured to export the ::rivet namespace commands we have to
+     *  set the array variable ::rivet::module_conf(export_namespace_commands) before calling init.tcl
+     *  This array will be unset after commands are exported.
+     */
+
+    Tcl_SetVar2Ex(interp,"module_conf","export_namespace_commands",Tcl_NewIntObj(RIVET_NAMESPACE_EXPORT),0);
+    Tcl_SetVar2Ex(interp,"module_conf","import_rivet_commands",Tcl_NewIntObj(RIVET_NAMESPACE_IMPORT),0);
+
+    if (Tcl_PkgRequire(interp, "RivetTcl", "2.1", 1) == NULL)
     {
-        ap_log_error( APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
-                "init.tcl must be installed correctly for Apache Rivet to function: %s",
-                Tcl_GetStringResult(interp) );
+        ap_log_error (APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
+                      MODNAME ": init.tcl must be installed correctly for Apache Rivet to function: %s (%s)",
+                      Tcl_GetStringResult(interp), RIVET_DIR );
+        exit(1);
+    }
+
+    /* Loading into the interpreter the commands provided by librivet.so */
+
+   /* It would be nice to have to whole set of Rivet commands
+    * loaded into the interpreter at this stage. Unfortunately
+    * a problem with the dynamic loader of some OS prevents us 
+    * from callingTcl_PkgRequire for 'rivetlib' because Apache segfaults
+    * shortly after the extension library is loaded.
+    * The problem was investigated on Linux and it became clear 
+    * that it's linked to the way Tcl calls dlopen (Bug #3216070)
+    * The problem could be solved in Tcl8.6 
+    */
+
+    if (Tcl_PkgRequire(interp, RIVETLIB_TCL_PACKAGE, "1.2", 1) == NULL)
+    {
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
+                     MODNAME ": Error loading rivetlib package: %s",
+		     Tcl_GetStringResult(interp) );
         exit(1);
     } 
+    /* */
 
     /* Set the output buffer size to the largest allowed value, so that we 
      * won't send any result packets to the browser unless the Rivet
      * programmer does a "flush stdout" or the page is completed.
      */
-//  Tcl_SetChannelOption(interp, *(rsc->outchannel), "-buffersize", "1000000");
+
     Tcl_SetChannelBufferSize (*(rsc->outchannel), 1000000);
     Tcl_RegisterChannel(interp, *(rsc->outchannel));
     Tcl_Release(interp);
@@ -1001,8 +1051,7 @@
 
 
 static const char *
-Rivet_SetScript (apr_pool_t *pool, rivet_server_conf *rsc, 
-                 const char *script, const char *string)
+Rivet_SetScript (apr_pool_t *pool, rivet_server_conf *rsc, const char *script, const char *string)
 {
     Tcl_Obj *objarg = NULL;
 
@@ -1035,6 +1084,7 @@
  * Implements the RivetServerConf Apache Directive
  *
  * Command Arguments:
+ *
  *  RivetServerConf GlobalInitScript <script>
  *  RivetServerConf ChildInitScript <script>
  *  RivetServerConf ChildExitScript <script>
@@ -1180,13 +1230,15 @@
 
         if (Tcl_EvalObjEx(interp, rsc->rivet_server_init_script, 0) != TCL_OK)
         {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, "%s",
-                    Tcl_GetVar(interp, "errorInfo", 0));
+            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
+			 MODNAME ": Error running ServerInitScript '%s': %s",
+			 Tcl_GetString(rsc->rivet_server_init_script),
+                         Tcl_GetVar(interp, "errorInfo", 0));
         } else {
-            ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_EGENERAL, s, 
-                        "RivetServerInit has run");
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, 
+		         MODNAME ": ServerInitScript '%s' successful", 
+			 Tcl_GetString(rsc->rivet_server_init_script));
         }
-
     }
     
     return OK;
@@ -1338,14 +1390,14 @@
     buf = (char *) apr_pvsprintf(rivet_panic_pool, format, argList);
 
     if (rivet_panic_request_rec != NULL) {
-    ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL, 
-         rivet_panic_server_rec,
-         "Critical error in request: %s", 
-         rivet_panic_request_rec->unparsed_uri);
+        ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL, 
+                     rivet_panic_server_rec,
+                     MODNAME ": Critical error in request: %s", 
+                     rivet_panic_request_rec->unparsed_uri);
     }
 
     ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL, 
-         rivet_panic_server_rec, buf);
+                 rivet_panic_server_rec, "%s", buf);
 
     abort();
 }
@@ -1380,11 +1432,11 @@
     top = RIVET_SERVER_CONF(s->module_config);
     if (init == 1) {
         parentfunction = top->rivet_child_init_script;
-        errmsg = "Error in Child init script: %s";
+        errmsg = MODNAME ": Error in Child init script: %s";
         //errmsg = (char *) apr_pstrdup(p, "Error in child init script: %s");
     } else {
         parentfunction = top->rivet_child_exit_script;
-        errmsg = "Error in Child exit script: %s";
+        errmsg = MODNAME ": Error in Child exit script: %s";
         //errmsg = (char *) apr_pstrdup(p, "Error in child exit script: %s");
     }
 
@@ -1408,12 +1460,13 @@
             Tcl_Preserve (rsc->server_interp);
             if (Tcl_EvalObjEx(rsc->server_interp,function, 0) != TCL_OK) {
                 ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
-                        errmsg, Tcl_GetString(function));
+                             errmsg, 
+			     Tcl_GetString(function));
                 ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
-                        "errorCode: %s",
+                             "errorCode: %s",
                         Tcl_GetVar(rsc->server_interp, "errorCode", 0));
                 ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
-                        "errorInfo: %s",
+                             "errorInfo: %s",
                         Tcl_GetVar(rsc->server_interp, "errorInfo", 0));
             }
             Tcl_Release (rsc->server_interp);
@@ -1485,14 +1538,15 @@
     if (interp == NULL)
     {
         ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
-                "Error in Tcl_CreateInterp, aborting\n");
+                     MODNAME ": Error in Tcl_CreateInterp, aborting\n");
         exit(1);
     }
 
     if (Tcl_Init(interp) == TCL_ERROR)
     {
         ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
-                Tcl_GetStringResult(interp));
+                     MODNAME ": Error in Tcl_Init: %s, aborting\n",
+		     Tcl_GetStringResult(interp));
         exit(1);
     }
     Tcl_SetPanicProc(Rivet_Panic);
@@ -1550,7 +1604,6 @@
     }
 }
 
-
 /*
  *-----------------------------------------------------------------------------
  *
@@ -1581,8 +1634,14 @@
     if (rsc->rivet_global_init_script != NULL) {
         if (Tcl_EvalObjEx(interp, rsc->rivet_global_init_script, 0) != TCL_OK)
         {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, "%s",
+            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
+			 MODNAME ": Error running GlobalInitScript '%s': %s",
+			 Tcl_GetString(rsc->rivet_global_init_script),
                          Tcl_GetVar(interp, "errorInfo", 0));
+        } else {
+            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, 
+		         MODNAME ": GlobalInitScript '%s' successful",
+		         Tcl_GetString(rsc->rivet_global_init_script));
         }
     }
 
@@ -1610,12 +1669,17 @@
                         sr->port,
                         interpCount++);
 
+		ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, 
+			    MODNAME ": Rivet_InitTclStuff: creating slave interpreter '%s', hostname '%s', port '%d', separate interpreters %d",
+			    slavename, sr->server_hostname, sr->port, 
+			    rsc->separate_virtual_interps);
+
                 /* Separate virtual interps. */
                 myrsc->server_interp = Tcl_CreateSlave(interp, slavename, 0);
                 if (myrsc->server_interp == NULL) {
-                    ap_log_error( APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
-                                    "slave interp create failed: %s",
-                                    Tcl_GetStringResult(interp) );
+                    ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
+                                 MODNAME ": slave interp create failed: %s",
+                                 Tcl_GetStringResult(interp) );
                     exit(1);
                 }
                 Rivet_PerInterpInit(s, myrsc, p);
@@ -1651,6 +1715,7 @@
  *-----------------------------------------------------------------------------
  */
 
+
 static void
 Rivet_ChildInit(apr_pool_t *pChild, server_rec *s)
 {
@@ -1663,6 +1728,11 @@
     apr_pool_cleanup_register (pChild, s, Rivet_ChildExit, Rivet_ChildExit);
 }
 
+
+//TODO: clarify whether rsc or rdc
+
+#define USE_APACHE_RSC
+
 /* Set things up to execute a file, then execute */
 static int
 Rivet_SendContent(request_rec *r)
@@ -1676,8 +1746,11 @@
     static Tcl_Obj  *request_cleanup = NULL;
 
     rivet_interp_globals *globals = NULL;
+#ifdef USE_APACHE_RSC
     rivet_server_conf    *rsc = NULL;
+#else
     rivet_server_conf    *rdc;
+#endif
 
     ctype = Rivet_CheckType(r);  
     if (ctype == CTYPE_NOT_HANDLED) {
@@ -1700,10 +1773,12 @@
 
     globals->req->charset = NULL;
 
+#ifndef USE_APACHE_RSC
     if (r->per_dir_config != NULL)
         rdc = RIVET_SERVER_CONF( r->per_dir_config );
     else
         rdc = rsc;
+#endif
 
     r->allowed |= (1 << M_GET);
     r->allowed |= (1 << M_POST);
@@ -1714,9 +1789,10 @@
 
     if (r->finfo.filetype == 0)
     {
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, APR_EGENERAL, r->server,
-                        "File does not exist: %s",
-        (r->path_info ? (char*)apr_pstrcat(r->pool, r->filename, r->path_info, NULL) : r->filename));
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, APR_EGENERAL, 
+	             r->server,
+                     MODNAME ": File does not exist: %s",
+                     (r->path_info ? (char*)apr_pstrcat(r->pool, r->filename, r->path_info, NULL) : r->filename));
         retval = HTTP_NOT_FOUND;
         goto sendcleanup;
     }
@@ -1740,15 +1816,18 @@
          * at this. We simply emit an internal server error and print a log message
          */
         ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, APR_EGENERAL, r->server, 
-                    "Error accessing %s, could not chdir into directory", r->filename);
+                     MODNAME ": Error accessing %s, could not chdir into directory", 
+		     r->filename);
 
         retval = HTTP_INTERNAL_SERVER_ERROR;
         goto sendcleanup;
     }
 
-    //TODO: clarify whether rsc or rdc
-    //Rivet_PropagatePerDirConfArrays( interp, rdc );
+#ifdef USE_APACHE_RSC
     Rivet_PropagatePerDirConfArrays( interp, rsc );
+#else
+    Rivet_PropagatePerDirConfArrays( interp, rdc );
+#endif
 
     /* Initialize this the first time through and keep it around. */
     if (request_init == NULL) {
@@ -1759,7 +1838,7 @@
     if (Tcl_EvalObjEx(interp, request_init, 0) == TCL_ERROR)
     {
         ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server,
-                "Could not create request namespace\n");
+                     MODNAME ": Could not create request namespace\n");
         retval = HTTP_BAD_REQUEST;
         goto sendcleanup;
     }
@@ -1849,8 +1928,10 @@
 
     if (Rivet_ParseExecFile(globals->req, r->filename, 1) != TCL_OK)
     {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server, "%s",
-                Tcl_GetVar(interp, "errorInfo", 0));
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server, 
+	             MODNAME ": Error parsing exec file '%s': %s",
+		     r->filename,
+                     Tcl_GetVar(interp, "errorInfo", 0));
     }
 
     if (request_cleanup == NULL) {
@@ -1859,8 +1940,9 @@
     }
 
     if (Tcl_EvalObjEx(interp, request_cleanup, 0) == TCL_ERROR) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server, "%s",
-                Tcl_GetVar(interp, "errorInfo", 0));
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server, 
+	             MODNAME ": Error evaluating cleanup request: %s",
+                     Tcl_GetVar(interp, "errorInfo", 0));
     }
 
     /* Reset globals */
diff --git a/src/apache-2/mod_rivet.h b/src/apache-2/mod_rivet.h
index ac69036..7a0b384 100644
--- a/src/apache-2/mod_rivet.h
+++ b/src/apache-2/mod_rivet.h
@@ -1,3 +1,21 @@
+/* mod_rivet.h -- The apache module itself, for Apache 2.x. */
+
+/* Copyright 2000-2005 The Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   	http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+/* $Id$ */
 
 #ifndef MOD_RIVET_H
 #define MOD_RIVET_H 1
@@ -56,11 +74,11 @@
     Tcl_Obj *rivet_global_init_script;	/* run once when apache is started */
     Tcl_Obj *rivet_child_init_script;
     Tcl_Obj *rivet_child_exit_script;
-    Tcl_Obj *rivet_before_script;	/* script run before each page      */
-    Tcl_Obj *rivet_after_script;	/*            after                 */
-    Tcl_Obj *rivet_error_script;	/*            for errors            */
-    Tcl_Obj *rivet_abort_script;	/* script run upon abort_page call  */
-    Tcl_Obj *after_every_script;	/* script to be run always	    */
+    Tcl_Obj *rivet_before_script;	    /* script run before each page	    */
+    Tcl_Obj *rivet_after_script;	    /*            after                 */
+    Tcl_Obj *rivet_error_script;	    /*            for errors            */
+    Tcl_Obj *rivet_abort_script;	    /* script run upon abort_page call  */
+    Tcl_Obj *after_every_script;	    /* script to be run always	        */
 
     /*  This flag is used with the above directives.  
         If any of them have changed, it gets set. */
@@ -73,26 +91,26 @@
     int upload_max;
     int upload_files_to_var;
     int separate_virtual_interps;
-    int honor_header_only_reqs;		/* default: 0 */
+    int honor_header_only_reqs;
     char *server_name;
     const char *upload_dir;
     apr_table_t *rivet_server_vars;
     apr_table_t *rivet_dir_vars;
     apr_table_t *rivet_user_vars;
-    char **objCacheList;		/* Array of cached objects (for priority handling) */
-    Tcl_HashTable *objCache;		/* Objects cache - the key is the script name */
+    char **objCacheList;		        /* Array of cached objects (for priority handling) */
+    Tcl_HashTable *objCache;		    /* Objects cache - the key is the script name */
 
-    Tcl_Channel *outchannel;		/* stuff for buffering output */
+    Tcl_Channel *outchannel;		    /* stuff for buffering output */
 } rivet_server_conf;
 
-/* eventually we will transfer 'global' variables in here and
-   'de-globalize' them */
+/* eventually we will transfer 'global' variables in here and 'de-globalize' them */
 
 typedef struct _rivet_interp_globals {
-    request_rec*    r;			/* request rec */
-    TclWebRequest*  req;		/* TclWeb API request */
+    request_rec     *r;			    /* request rec */
+    TclWebRequest   *req;			/* TclWeb API request */
+    Tcl_Namespace   *rivet_ns;      /* Rivet commands namespace */
     int             page_aborting;	/* set by abort_page. */
-					/* to be reset by Rivet_SendContent */
+					                /* to be reset by Rivet_SendContent */
     Tcl_Obj*        abort_code;
 } rivet_interp_globals;
 
@@ -113,6 +131,5 @@
 #define RIVET_NEW_CONF(p) \
 	(rivet_server_conf *)apr_pcalloc(p, sizeof(rivet_server_conf))
 
-
 #endif /* MOD_RIVET_H */
 
diff --git a/src/apache-2/rivetCore.c b/src/apache-2/rivetCore.c
index c3f1692..85fa537 100644
--- a/src/apache-2/rivetCore.c
+++ b/src/apache-2/rivetCore.c
@@ -8,7 +8,7 @@
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
-    http://www.apache.org/licenses/LICENSE-2.0
+        http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
@@ -34,10 +34,8 @@
 #include "http_log.h"
 #include "http_main.h"
 #include "util_script.h"
-//#include "http_conf_globals.h"
 #include "http_config.h"
 
-
 #include <tcl.h>
 #include <string.h>
 #include <stdio.h>
@@ -63,13 +61,13 @@
  *
  * Rivet_MakeURL --
  *
- *  Make a self-referencing URL.
+ *      Make a self-referencing URL.
  *
  * Results:
- *  Standard Tcl result.
+ *      Standard Tcl result.
  *
  * Side Effects:
- *  None.
+ *      None.
  *
  *-----------------------------------------------------------------------------
  */
@@ -105,13 +103,13 @@
             char* script_name = TclWeb_GetEnvVar (globals->req,"SCRIPT_NAME");
             int   script_name_l = strlen(script_name);
 
-            // regardless the reason for SCRIPT_NAME being undefined we
+            // regardless the reason for a SCRIPT_NAME being undefined we
             // prevent a segfault and we revert the behavior of makeurl
             // to the case of an absolute path
 
             if (script_name_l > 0)
             {
-                // script name may have the form of a directory path (and mod_rewrite 
+                // script name may have the form a directory path (and mod_rewrite 
                 // could have mapped it to a .tcl or .rvt script)
                 
                 if (script_name[script_name_l-1] == '/')
@@ -142,20 +140,20 @@
  *
  * Rivet_Parse --
  *
- *  Include and parse a Rivet file.
+ *      Include and parse a Rivet file.
  *
  * Results:
- *  Standard Tcl result.
+ *      Standard Tcl result.
  *
  * Side Effects:
- *  Whatever occurs in the Rivet page parsed.
+ *      Whatever occurs in the Rivet page parsed.
  *
  *-----------------------------------------------------------------------------
  */
 
 TCL_CMD_HEADER( Rivet_Parse )
 {
-    char        *filename;
+    char            *filename;
     apr_status_t    stat_s;
     apr_finfo_t     finfo_b;
 
@@ -186,7 +184,7 @@
     stat_s = apr_stat(&finfo_b,filename,APR_FINFO_NORM,globals->r->pool);
     if (stat_s != APR_SUCCESS)
     {
-    char apr_error_message[256];
+        char apr_error_message[256];
 
         Tcl_AddErrorInfo(interp,apr_strerror(stat_s,apr_error_message,256));
         return TCL_ERROR;
@@ -204,14 +202,14 @@
  *
  * Rivet_Include --
  *
- *  Includes a file literally in the output stream.  Useful for
- *  images, plain HTML and the like.
+ *      Includes a file literally in the output stream.  Useful for
+ *      images, plain HTML and the like.
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  Adds to the output stream.
+ *      Adds to the output stream.
  *
  *-----------------------------------------------------------------------------
  */
@@ -230,19 +228,19 @@
 
     if( objc < 2 || objc > 3 )
     {
-    Tcl_WrongNumArgs(interp, 1, objv, "?-virtual? filename");
-    return TCL_ERROR;
+        Tcl_WrongNumArgs(interp, 1, objv, "?-virtual? filename");
+        return TCL_ERROR;
     }
 
     if( objc == 2 ) {
-    filename = Tcl_GetStringFromObj( objv[1], (int *)NULL );
+        filename = Tcl_GetStringFromObj( objv[1], (int *)NULL );
     } else {
-    if( !STREQU( Tcl_GetStringFromObj(objv[1], (int *)NULL), "-virtual") ) {
-        Tcl_WrongNumArgs( interp, 1, objv, "?-virtual? filename" );
-        return TCL_ERROR;
-    }
-    filename = TclWeb_GetVirtualFile( globals->req,
-                      Tcl_GetStringFromObj(objv[2], (int *)NULL) );
+        if( !STREQU( Tcl_GetStringFromObj(objv[1], (int *)NULL), "-virtual") ) {
+            Tcl_WrongNumArgs( interp, 1, objv, "?-virtual? filename" );
+            return TCL_ERROR;
+        }
+        filename = TclWeb_GetVirtualFile( globals->req,
+                                          Tcl_GetStringFromObj(objv[2], (int *)NULL) );
     }
 
     fd = Tcl_OpenFileChannel(interp, filename, "r", 0664);
@@ -258,9 +256,9 @@
     sz = Tcl_ReadChars(fd, outobj, -1, 0);
     if (sz == -1)
     {
-    Tcl_AddErrorInfo(interp, Tcl_PosixError(interp));
-    Tcl_DecrRefCount(outobj);
-    return TCL_ERROR;
+        Tcl_AddErrorInfo(interp, Tcl_PosixError(interp));
+        Tcl_DecrRefCount(outobj);
+        return TCL_ERROR;
     }
 
     /* What we are doing is saving the translation and encoding
@@ -286,13 +284,13 @@
  *
  * Rivet_Headers --
  *
- *  Command to manipulate HTTP headers from Tcl.
+ *      Command to manipulate HTTP headers from Tcl.
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  None.
+ *      None.
  *
  *-----------------------------------------------------------------------------
  */
@@ -304,72 +302,72 @@
 
     if (objc < 2)
     {
-    Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");
-    return TCL_ERROR;
+        Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");
+        return TCL_ERROR;
     }
     if (globals->req->headers_printed != 0)
     {
-    Tcl_AddObjErrorInfo(interp,
-                "Cannot manipulate headers - already sent", -1);
-    return TCL_ERROR;
+        Tcl_AddObjErrorInfo(interp,
+                            "Cannot manipulate headers - already sent", -1);
+        return TCL_ERROR;
     }
     opt = Tcl_GetStringFromObj(objv[1], NULL);
 
     if (!strcmp("redirect", opt)) /* ### redirect ### */
     {
-    if (objc != 3)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "new-url");
-        return TCL_ERROR;
-    }
-    apr_table_set(globals->r->headers_out, "Location",
-             Tcl_GetStringFromObj (objv[2], (int *)NULL));
-    TclWeb_SetStatus(301, globals->req);
-    return TCL_RETURN;
+        if (objc != 3)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "new-url");
+            return TCL_ERROR;
+        }
+        apr_table_set(globals->r->headers_out, "Location",
+                     Tcl_GetStringFromObj (objv[2], (int *)NULL));
+        TclWeb_SetStatus(301, globals->req);
+        return TCL_RETURN;
     }
     else if (!strcmp("set", opt)) /* ### set ### */
     {
-    if (objc != 4)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "headername value");
-        return TCL_ERROR;
-    }
-    TclWeb_HeaderSet(Tcl_GetString(objv[2]), Tcl_GetString(objv[3]), globals->req);
+        if (objc != 4)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "headername value");
+            return TCL_ERROR;
+        }
+        TclWeb_HeaderSet(Tcl_GetString(objv[2]), Tcl_GetString(objv[3]), globals->req);
     }
     else if (!strcmp("add", opt)) /* ### set ### */
     {
-    if (objc != 4)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "headername value");
-        return TCL_ERROR;
-    }
-    TclWeb_HeaderAdd(Tcl_GetString(objv[2]), Tcl_GetString(objv[3]), globals->req);
+        if (objc != 4)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "headername value");
+            return TCL_ERROR;
+        }
+        TclWeb_HeaderAdd(Tcl_GetString(objv[2]), Tcl_GetString(objv[3]), globals->req);
     }
     else if (!strcmp("type", opt)) /* ### set ### */
     {
-    if (objc != 3)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "mime/type");
-        return TCL_ERROR;
-    }
-    TclWeb_SetHeaderType(Tcl_GetString(objv[2]), globals->req);
+        if (objc != 3)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "mime/type");
+            return TCL_ERROR;
+        }
+        TclWeb_SetHeaderType(Tcl_GetString(objv[2]), globals->req);
     } else if (!strcmp("numeric", opt)) /* ### numeric ### */
     {
-    int st = 200;
+        int st = 200;
 
-    if (objc != 3)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "response_code_number");
-        return TCL_ERROR;
-    }
-    if (Tcl_GetIntFromObj(interp, objv[2], &st) != TCL_ERROR) {
-        TclWeb_SetStatus(st, globals->req);
+        if (objc != 3)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "response_code_number");
+            return TCL_ERROR;
+        }
+        if (Tcl_GetIntFromObj(interp, objv[2], &st) != TCL_ERROR) {
+            TclWeb_SetStatus(st, globals->req);
+        } else {
+            return TCL_ERROR;
+        }
     } else {
         return TCL_ERROR;
     }
-    } else {
-    return TCL_ERROR;
-    }
     return TCL_OK;
 }
 
@@ -378,16 +376,16 @@
  *
  * Rivet_LoadEnv --
  *
- *  Load the "environmental variables" - those variables that are
- *  set in the environment in a standard CGI program.  If no array
- *  name is supplied, they are loaded into an array whose name is
- *  the value of the ENV_ARRAY_NAME #define.
+ *      Load the "environmental variables" - those variables that are
+ *      set in the environment in a standard CGI program.  If no array
+ *      name is supplied, they are loaded into an array whose name is
+ *      the value of the ENV_ARRAY_NAME #define.
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  None.
+ *      None.
  *
  *-----------------------------------------------------------------------------
  */
@@ -398,14 +396,14 @@
     rivet_interp_globals *globals = Tcl_GetAssocData(interp, "rivet", NULL);
 
     if( objc > 2 ) {
-    Tcl_WrongNumArgs( interp, 1, objv, "?arrayName?" );
-    return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv, "?arrayName?" );
+        return TCL_ERROR;
     }
 
     if( objc == 2 ) {
-    ArrayObj = objv[1];
+        ArrayObj = objv[1];
     } else {
-    ArrayObj = Tcl_NewStringObj( ENV_ARRAY_NAME, -1 );
+        ArrayObj = Tcl_NewStringObj( ENV_ARRAY_NAME, -1 );
     }
 
     return TclWeb_GetEnvVars(ArrayObj, globals->req);
@@ -416,15 +414,15 @@
  *
  * Rivet_LoadHeaders --
  *
- *  Load the HTTP headers supplied by the client into a Tcl array,
- *  whose name defaults to the value of the HEADERS_ARRAY_NAME
- *  #define.
+ *      Load the HTTP headers supplied by the client into a Tcl array,
+ *      whose name defaults to the value of the HEADERS_ARRAY_NAME
+ *      #define.
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  Creates an array variable if none exists.
+ *      Creates an array variable if none exists.
  *
  *-----------------------------------------------------------------------------
  */
@@ -435,14 +433,14 @@
     rivet_interp_globals *globals = Tcl_GetAssocData(interp, "rivet", NULL);
 
     if( objc > 2 ) {
-    Tcl_WrongNumArgs( interp, 1, objv, "?arrayName?" );
-    return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv, "?arrayName?" );
+        return TCL_ERROR;
     }
 
     if( objc == 2 ) {
-    ArrayObj = objv[1];
+        ArrayObj = objv[1];
     } else {
-    ArrayObj = Tcl_NewStringObj( HEADERS_ARRAY_NAME, -1 );
+        ArrayObj = Tcl_NewStringObj( HEADERS_ARRAY_NAME, -1 );
     }
 
     return TclWeb_GetHeaderVars(ArrayObj, globals->req);
@@ -458,19 +456,19 @@
  *
  *  Rivet_Var --
  *
- *  Returns information about GET or POST variables:
+ *      Returns information about GET or POST variables:
  *
- *  var get foo ?default?
- *  var list foo
- *  var names
- *  var number
- *  var all
+ *      var get foo ?default?
+ *      var list foo
+ *      var names
+ *      var number
+ *      var all
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  None.
+ *      None.
  *
  *-----------------------------------------------------------------------------
  */
@@ -485,10 +483,10 @@
 
     if (objc < 2 || objc > 4)
     {
-    Tcl_WrongNumArgs(interp, 1, objv,
-             "(get varname ?default?|list varname|exists varname|names"
-             "|number|all)");
-    return TCL_ERROR;
+        Tcl_WrongNumArgs(interp, 1, objv,
+                         "(get varname ?default?|list varname|exists varname|names"
+                         "|number|all)");
+        return TCL_ERROR;
     }
     cmd = Tcl_GetString(objv[0]);
     command = Tcl_GetString(objv[1]);
@@ -501,84 +499,84 @@
 
     if (!strcmp(command, "get"))
     {
-    char *key = NULL;
-    char *deflt = NULL;
-    if (objc != 3 && objc != 4)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "variablename ?defaultval?");
-        return TCL_ERROR;
-    }
-    key = Tcl_GetStringFromObj(objv[2], NULL);
-    if (objc == 4)
-    {
-        deflt = Tcl_GetString(objv[3]);
-    }
-
-    if (TclWeb_GetVar(result, key, source, globals->req) != TCL_OK)
-    {
-        if (deflt == NULL) {
-        Tcl_SetStringObj(result, "", -1);
-        } else {
-        Tcl_SetStringObj(result, deflt, -1);
+        char *key = NULL;
+        char *deflt = NULL;
+        if (objc != 3 && objc != 4)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "variablename ?defaultval?");
+            return TCL_ERROR;
         }
-    }
+        key = Tcl_GetStringFromObj(objv[2], NULL);
+        if (objc == 4)
+        {
+            deflt = Tcl_GetString(objv[3]);
+        }
+
+        if (TclWeb_GetVar(result, key, source, globals->req) != TCL_OK)
+        {
+            if (deflt == NULL) {
+                Tcl_SetStringObj(result, "", -1);
+            } else {
+                Tcl_SetStringObj(result, deflt, -1);
+            }
+        }
     } else if(!strcmp(command, "exists")) {
-    char *key;
-    if (objc != 3)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "variablename");
-        return TCL_ERROR;
-    }
-    key = Tcl_GetString(objv[2]);
+        char *key;
+        if (objc != 3)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "variablename");
+            return TCL_ERROR;
+        }
+        key = Tcl_GetString(objv[2]);
 
-    TclWeb_VarExists(result, key, source, globals->req);
+        TclWeb_VarExists(result, key, source, globals->req);
     } else if(!strcmp(command, "list")) {
-    char *key;
-    if (objc != 3)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, "variablename");
-        return TCL_ERROR;
-    }
-    key = Tcl_GetStringFromObj(objv[2], NULL);
+        char *key;
+        if (objc != 3)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, "variablename");
+            return TCL_ERROR;
+        }
+        key = Tcl_GetStringFromObj(objv[2], NULL);
 
-    if (TclWeb_GetVarAsList(result, key, source, globals->req) != TCL_OK)
-    {
-        result = Tcl_NewStringObj("", -1);
-    }
+        if (TclWeb_GetVarAsList(result, key, source, globals->req) != TCL_OK)
+        {
+            result = Tcl_NewStringObj("", -1);
+        }
     } else if(!strcmp(command, "names")) {
-    if (objc != 2)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, NULL);
-        return TCL_ERROR;
-    }
+        if (objc != 2)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, NULL);
+            return TCL_ERROR;
+        }
 
-    if (TclWeb_GetVarNames(result, source, globals->req) != TCL_OK)
-    {
-        result = Tcl_NewStringObj("", -1);
-    }
+        if (TclWeb_GetVarNames(result, source, globals->req) != TCL_OK)
+        {
+            result = Tcl_NewStringObj("", -1);
+        }
     } else if(!strcmp(command, "number")) {
-    if (objc != 2)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, NULL);
-        return TCL_ERROR;
-    }
+        if (objc != 2)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, NULL);
+            return TCL_ERROR;
+        }
 
-    TclWeb_VarNumber(result, source, globals->req);
+        TclWeb_VarNumber(result, source, globals->req);
     } else if(!strcmp(command, "all")) {
-    if (objc != 2)
-    {
-        Tcl_WrongNumArgs(interp, 2, objv, NULL);
-        return TCL_ERROR;
-    }
-    if (TclWeb_GetAllVars(result, source, globals->req) != TCL_OK)
-    {
-        result = Tcl_NewStringObj("", -1);
-    }
+        if (objc != 2)
+        {
+            Tcl_WrongNumArgs(interp, 2, objv, NULL);
+            return TCL_ERROR;
+        }
+        if (TclWeb_GetAllVars(result, source, globals->req) != TCL_OK)
+        {
+            result = Tcl_NewStringObj("", -1);
+        }
     } else {
-    /* bad command  */
-    Tcl_AppendResult(interp, "bad option: must be one of ",
-             "'get, list, names, number, all'", NULL);
-    return TCL_ERROR;
+        /* bad command  */
+        Tcl_AppendResult(interp, "bad option: must be one of ",
+                         "'get, list, names, number, all'", NULL);
+        return TCL_ERROR;
     }
     Tcl_SetObjResult(interp, result);
 
@@ -611,9 +609,9 @@
  *
  * Rivet_ApacheTable --
  *
- *  Deals with Rivet key-value tables in the request structure
+ *      Deals with Rivet key-value tables in the request structure
  *
- *  apache_table get tablename key
+ *      apache_table get tablename key
  *      apache_table set tablename key value
  *      apache_table set tablename list
  *      apache_table exists tablename key
@@ -626,7 +624,7 @@
  *      "err_headers_out", and "subprocess_env".
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
  *
@@ -685,7 +683,7 @@
         return TCL_ERROR;
     }
 
-    if (Tcl_GetIndexFromObj(interp, objv[1],SubCommand,
+    if (Tcl_GetIndexFromObj(interp, objv[1], SubCommand,
                         "get|set|unset|list",
                         0, &subcommandindex) == TCL_ERROR) {
         return TCL_ERROR;
@@ -694,7 +692,7 @@
     if (Tcl_GetIndexFromObj (interp, objv[2], tableNames,
                     "notes|headers_in|headers_out|err_header_out|subprocess_env",
                     0, &tableindex) == TCL_ERROR) {
-        return TCL_ERROR;
+	    return TCL_ERROR;
     }
 
     switch ((enum tablename)tableindex)
@@ -732,26 +730,24 @@
             const char *value;
 
             if (objc != 4) {
-            Tcl_WrongNumArgs(interp, 2, objv, "tablename key");
-            return TCL_ERROR;
+                Tcl_WrongNumArgs(interp, 2, objv, "tablename key");
+                return TCL_ERROR;
             }
-
             key = Tcl_GetString (objv[3]);
             value = apr_table_get (table, key);
 
             if (value != NULL) {
-            Tcl_SetObjResult (interp, Tcl_NewStringObj (value, -1));
+                Tcl_SetObjResult (interp, Tcl_NewStringObj (value, -1));
             }
             break;
         }
-
         case SUB_EXISTS: {
             const char *key;
             const char *value;
 
             if (objc != 4) {
-            Tcl_WrongNumArgs(interp, 2, objv, "tablename key");
-            return TCL_ERROR;
+                Tcl_WrongNumArgs(interp, 2, objv, "tablename key");
+                return TCL_ERROR;
             }
 
             key = Tcl_GetString (objv[3]);
@@ -760,8 +756,6 @@
             Tcl_SetObjResult (interp, Tcl_NewBooleanObj (value != NULL));
             break;
         }
-
-
         case SUB_SET: {
             int i;
             char *key;
@@ -844,23 +838,23 @@
  *
  * Rivet_Upload --
  *
- *  Deals with file uploads (multipart/form-data) like so:
+ *      Deals with file uploads (multipart/form-data) like so:
  *
- *  upload channel uploadname
- *  upload save name uploadname
- *  upload data uploadname
- *  upload exists uploadname
- *  upload size uploadname
- *  upload type uploadname
- *  upload filename uploadname
- *  upload names
+ *      upload channel uploadname
+ *      upload save name uploadname
+ *      upload data uploadname
+ *      upload exists uploadname
+ *      upload size uploadname
+ *      upload type uploadname
+ *      upload filename uploadname
+ *      upload names
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  Has the potential to create files on the file system, or work
- *  with large amounts of data.
+ *      Has the potential to create files on the file system, or work
+ *      with large amounts of data.
  *
  *-----------------------------------------------------------------------------
  */
@@ -900,10 +894,10 @@
 
     rivet_interp_globals *globals = Tcl_GetAssocData(interp, "rivet", NULL);
     if (Tcl_GetIndexFromObj(interp, objv[1], SubCommand,
-            "channel|save|data|exists|size|type|filename|names|tempname"
-            "|tempname|names",
-            0, &subcommandindex) == TCL_ERROR) {
-    return TCL_ERROR;
+                        "channel|save|data|exists|size|type|filename|names|tempname"
+                        "|tempname|names",
+                        0, &subcommandindex) == TCL_ERROR) {
+        return TCL_ERROR;
     }
 
     /* If it's any of these, we need to find a specific name. */
@@ -924,8 +918,8 @@
         {
             if (TclWeb_PrepareUpload(varname, globals->req) != TCL_OK)
             {
-            Tcl_AddErrorInfo(interp, "Unable to find variable");
-            return TCL_ERROR;
+                Tcl_AddErrorInfo(interp, "Unable to find variable");
+                return TCL_ERROR;
             }
         }
 
@@ -942,84 +936,65 @@
 
     switch ((enum subcommand)subcommandindex)
     {
-        case CHANNEL: 
-        {
-            Tcl_Channel chan;
-            char *channelname = NULL;
+    case CHANNEL: {
+        Tcl_Channel chan;
+        char *channelname = NULL;
 
-            if (TclWeb_UploadChannel(varname, &chan, globals->req) != TCL_OK) {
-                return TCL_ERROR;
-            }
-            channelname = (char *)Tcl_GetChannelName(chan);
-            Tcl_SetStringObj(result, channelname, -1);
-            break;
+        if (TclWeb_UploadChannel(varname, &chan, globals->req) != TCL_OK) {
+            return TCL_ERROR;
         }
-        case SAVE:
-        {
-            /* save data to a specified filename  */
-            if (objc != 4) {
-                Tcl_WrongNumArgs(interp, 2, objv, "uploadname filename");
-                return TCL_ERROR;
-            }
+        channelname = (char *)Tcl_GetChannelName(chan);
+        Tcl_SetStringObj(result, channelname, -1);
+        break;
+    }
+    case SAVE:
+        /* save data to a specified filename  */
+        if (objc != 4) {
+            Tcl_WrongNumArgs(interp, 2, objv, "uploadname filename");
+            return TCL_ERROR;
+        }
 
-            if (TclWeb_UploadSave(varname, objv[3], globals->req) != TCL_OK)
-            {
-                return TCL_ERROR;
-            }
-            break;
-        }
-        case DATA:
+        if (TclWeb_UploadSave(varname, objv[3], globals->req) != TCL_OK)
         {
-            if (TclWeb_UploadData(varname, result, globals->req) != TCL_OK) {
-                return TCL_ERROR;
-            }
-            break;
+            return TCL_ERROR;
         }
-        case EXISTS:
+        break;
+    case DATA:
+        if (TclWeb_UploadData(varname, result, globals->req) != TCL_OK) {
+            return TCL_ERROR;
+        }
+        break;
+    case EXISTS:
+        if (TclWeb_PrepareUpload(varname, globals->req) != TCL_OK)
         {
-            if (TclWeb_PrepareUpload(varname, globals->req) != TCL_OK)
-            {
-                Tcl_SetIntObj(result, 0);
-            } else {
-                Tcl_SetIntObj(result, 1);
-            }
-            break;
+            Tcl_SetIntObj(result, 0);
+        } else {
+            Tcl_SetIntObj(result, 1);
         }
-        case SIZE:
+        break;
+    case SIZE:
+        TclWeb_UploadSize(result, globals->req);
+        break;
+    case TYPE:
+        TclWeb_UploadType(result, globals->req);
+        break;
+    case FILENAME:
+        TclWeb_UploadFilename(result, globals->req);
+        break;
+    case TEMPNAME:
+        TclWeb_UploadTempname(result,globals->req);
+        break;
+    case NAMES:
+        if (objc != 2)
         {
-            TclWeb_UploadSize(result, globals->req);
-            break;
+            Tcl_WrongNumArgs(interp, 1, objv, "names");
+            return TCL_ERROR;
         }
-        case TYPE:
-        {
-            TclWeb_UploadType(result, globals->req);
-            break;
-        }
-        case FILENAME:
-        {
-            TclWeb_UploadFilename(result, globals->req);
-            break;
-        }
-        case TEMPNAME:
-        {
-            TclWeb_UploadTempname(result,globals->req);
-            break;
-        }
-        case NAMES:
-        {
-            if (objc != 2)
-            {
-                Tcl_WrongNumArgs(interp, 1, objv, "names");
-                return TCL_ERROR;
-            }
-            TclWeb_UploadNames(result, globals->req);
-            break;
-        }
-        default:
-        {
-            Tcl_WrongNumArgs(interp, 1, objv,
-                 "channel|save ?name?|data|exists|size|type|filename|names|tempname");
-        }
+        TclWeb_UploadNames(result, globals->req);
+        break;
+    default:
+        Tcl_WrongNumArgs(interp, 1, objv,
+                         "channel|save ?name?|data|exists|size|type|filename|names|tempname");
     }
     Tcl_SetObjResult(interp, result);
     return TCL_OK;
@@ -1030,13 +1005,13 @@
  *
  * Rivet_RawPost --
  *
- *  Returns the raw POST data.
+ *      Returns the raw POST data.
  *
  * Results:
- *  The raw post data, or an empty string if there is none.
+ *      The raw post data, or an empty string if there is none.
  *
  * Side Effects:
- *  None.
+ *      None.
  *
  *-----------------------------------------------------------------------------
  */
@@ -1062,14 +1037,14 @@
  *
  * Rivet_NoBody --
  *
- *  Tcl command to erase body, so that only header is returned.
- *  Necessary for 304 responses.
+ *      Tcl command to erase body, so that only header is returned.
+ *      Necessary for 304 responses.
  *
  * Results:
- *  A standard Tcl return value.
+ *      A standard Tcl return value.
  *
  * Side Effects:
- *  Eliminates any body returned in the HTTP response.
+ *      Eliminates any body returned in the HTTP response.
  *
  *-----------------------------------------------------------------------------
  */
@@ -1092,16 +1067,16 @@
  *
  * Rivet_AbortPageCmd --
  *
- *  Similar in purpose to PHP's "die" command, which halts all
- *  further output to the user.  Like an "exit" for web pages, but
- *  without actually exiting the apache child.
+ *      Similar in purpose to PHP's "die" command, which halts all
+ *      further output to the user.  Like an "exit" for web pages, but
+ *      without actually exiting the apache child.
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  Flushes the standard (apache) output channel, and tells apache
- *  to stop sending data.
+ *      Flushes the standard (apache) output channel, and tells apache
+ *      to stop sending data.
  *
  *-----------------------------------------------------------------------------
  */
@@ -1186,14 +1161,14 @@
  *
  * Rivet_EnvCmd --
  *
- *  Loads a single environmental variable, to avoid the overhead
- *  of storing all of them when only one is needed.
+ *      Loads a single environmental variable, to avoid the overhead
+ *      of storing all of them when only one is needed.
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  None.
+ *      None.
  *
  *-----------------------------------------------------------------------------
  */
@@ -1222,14 +1197,14 @@
  *
  * Rivet_VirtualFilenameCmd --
  *
- *  Gets file according to its relationship with the request's
- *  root. (FIXME - check this).
+ *      Gets file according to its relationship with the request's
+ *      root. (FIXME - check this).
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  None.
+ *      None.
  *
  *-----------------------------------------------------------------------------
  */
@@ -1257,9 +1232,9 @@
  *
  * Rivet_LogError --
  *
- *  Log an error from Rivet
+ *      Log an error from Rivet
  *
- *  log_error priority message
+ *      log_error priority message
  *
  *        priority can be one of "emerg", "alert", "crit", "err",
  *            "warning", "notice", "info", "debug"
@@ -1280,40 +1255,40 @@
     int  apLogLevel = 0;
 
     static CONST84 char *logLevel[] = {
-    "emerg",
-    "alert",
-    "crit",
-    "err",
-    "warning",
-    "notice",
-    "info",
-    "debug",
-    NULL
+        "emerg",
+        "alert",
+        "crit",
+        "err",
+        "warning",
+        "notice",
+        "info",
+        "debug",
+        NULL
     };
 
     enum loglevel {
-    EMERG,
-    ALERT,
-    CRIT,
-    ERR,
-    WARNING,
-    NOTICE,
-    INFO,
-    DEBUG
+        EMERG,
+        ALERT,
+        CRIT,
+        ERR,
+        WARNING,
+        NOTICE,
+        INFO,
+        DEBUG
     };
 
     rivet_interp_globals *globals = Tcl_GetAssocData(interp, "rivet", NULL);
 
     if( objc != 3 ) {
-    Tcl_WrongNumArgs( interp, 1, objv, "loglevel message" );
-    return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv, "loglevel message" );
+        return TCL_ERROR;
     }
 
     message = Tcl_GetString (objv[2]);
     if (Tcl_GetIndexFromObj(interp, objv[1], logLevel,
-            "emerg|alert|crit|err|warning|notice|info|debug",
-            0, &loglevelindex) == TCL_ERROR) {
-    return TCL_ERROR;
+                        "emerg|alert|crit|err|warning|notice|info|debug",
+                        0, &loglevelindex) == TCL_ERROR) {
+        return TCL_ERROR;
     }
 
     switch ((enum loglevel)loglevelindex)
@@ -1368,23 +1343,23 @@
  *
  * TestpanicCmd --
  *
- *  Calls the panic routine.
+ *      Calls the panic routine.
  *
  * Results:
  *      Always returns TCL_OK. 
  *
  * Side effects:
- *  May exit application.
+ *      May exit application.
  *
  *----------------------------------------------------------------------
  */
 
 static int
 TestpanicCmd(dummy, interp, argc, argv)
-    ClientData dummy;           /* Not used. */
-    Tcl_Interp *interp;         /* Current interpreter. */
-    int argc;               /* Number of arguments. */
-    CONST char **argv;          /* Argument strings. */
+    ClientData dummy;                   /* Not used. */
+    Tcl_Interp *interp;                 /* Current interpreter. */
+    int argc;                           /* Number of arguments. */
+    CONST char **argv;                  /* Argument strings. */
 {
     CONST char *argString;
 
@@ -1406,13 +1381,13 @@
  *
  * Rivet_InitCore --
  *
- *  Creates the core rivet commands.
+ *      Creates the core rivet commands.
  *
  * Results:
- *  A standard Tcl result.
+ *      A standard Tcl result.
  *
  * Side Effects:
- *  Creates new commands.
+ *      Creates new commands.
  *
  *-----------------------------------------------------------------------------
  */
@@ -1420,104 +1395,41 @@
 int
 Rivet_InitCore( Tcl_Interp *interp )
 {
-    Tcl_CreateObjCommand(interp,
-             "makeurl",
-             Rivet_MakeURL,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
+#if RIVET_NAMESPACE_EXPORT == 1
+    rivet_interp_globals *globals = NULL;
+    Tcl_Namespace *rivet_ns;
 
-    Tcl_CreateObjCommand(interp,
-             "headers",
-             Rivet_Headers,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "load_env",
-             Rivet_LoadEnv,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "load_headers",
-             Rivet_LoadHeaders,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "var",
-             Rivet_Var,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "apache_table",
-             Rivet_ApacheTable,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "var_qs",
-             Rivet_Var,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "var_post",
-             Rivet_Var,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "raw_post",
-             Rivet_RawPost,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "upload",
-             Rivet_Upload,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "include",
-             Rivet_Include,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "parse",
-             Rivet_Parse,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "no_body",
-             Rivet_NoBody,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "env",
-             Rivet_EnvCmd,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-             "apache_log_error",
-             Rivet_LogErrorCmd,
-             NULL,
-             (Tcl_CmdDeleteProc *)NULL);
-
-#ifdef TESTPANIC
-    Tcl_CreateCommand(interp, "testpanic", TestpanicCmd, (ClientData) 0,
-            (Tcl_CmdDeleteProc *) NULL);
+    globals = Tcl_GetAssocData(interp, "rivet", NULL);
+    rivet_ns = globals->rivet_ns;
 #endif
 
-    TCL_OBJ_CMD( "abort_page", Rivet_AbortPageCmd );
-    TCL_OBJ_CMD( "abort_code", Rivet_AbortCodeCmd );
-    TCL_OBJ_CMD( "virtual_filename", Rivet_VirtualFilenameCmd );
+    RIVET_OBJ_CMD ("makeurl",Rivet_MakeURL);
+    RIVET_OBJ_CMD ("headers",Rivet_Headers);
+    RIVET_OBJ_CMD ("load_env",Rivet_LoadEnv);
+    RIVET_OBJ_CMD ("load_headers",Rivet_LoadHeaders);
+    RIVET_OBJ_CMD ("var",Rivet_Var);
+    RIVET_OBJ_CMD ("abort_page",Rivet_AbortPageCmd);
+    RIVET_OBJ_CMD ("abort_code", Rivet_AbortCodeCmd);
+    RIVET_OBJ_CMD ("virtual_filename",Rivet_VirtualFilenameCmd);
+    RIVET_OBJ_CMD ("apache_table",Rivet_ApacheTable);
+    RIVET_OBJ_CMD ("var_qs",Rivet_Var);
+    RIVET_OBJ_CMD ("var_post",Rivet_Var);
+    RIVET_OBJ_CMD ("raw_post",Rivet_RawPost);
+    RIVET_OBJ_CMD ("upload",Rivet_Upload);
+    RIVET_OBJ_CMD ("include",Rivet_Include);
+    RIVET_OBJ_CMD ("parse",Rivet_Parse);
+    RIVET_OBJ_CMD ("no_body",Rivet_NoBody);
+    RIVET_OBJ_CMD ("env",Rivet_EnvCmd);
+    RIVET_OBJ_CMD ("apache_log_error",Rivet_LogErrorCmd);
 
+#ifdef TESTPANIC
+    RIVET_OBJ_CMD ("testpanic",TestpanicCmd);
+#endif
+
+#if RIVET_NAMESPACE_EXPORT == 1
+    Tcl_Export(interp,rivet_ns,"*",0);
+#endif
+
+//  return Tcl_PkgProvide( interp,RIVET_TCL_PACKAGE,"1.2");
     return TCL_OK;
 }
diff --git a/src/parserPkgInit.c b/src/parserPkgInit.c
index 609931e..7b2c863 100644
--- a/src/parserPkgInit.c
+++ b/src/parserPkgInit.c
@@ -116,6 +116,14 @@
 EXTERN int
 Rivetparser_Init( Tcl_Interp *interp )
 {
+#ifdef USE_TCL_STUBS
+    if (Tcl_InitStubs(interp, "8.5", 0) == NULL) { 
+#else
+	if (Tcl_PkgRequire(interp, "Tcl", "8.5", 0) == NULL) { 
+#endif    
+	    return TCL_ERROR;
+    }
+
     Tcl_CreateObjCommand(interp,
 			 "rivet::parserivet",
 			 Parse_Rivet,
@@ -144,6 +152,15 @@
      * target string, which should by design prevent buffer overflow
      * attacks, etc.
      */
+
+#ifdef USE_TCL_STUBS
+    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { 
+#else
+	if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) { 
+#endif    
+	    return TCL_ERROR;
+    }
+
     Tcl_CreateObjCommand(interp,
 			 "rivet::parserivetdata",
 			 Parse_RivetData,
diff --git a/src/rivet.h b/src/rivet.h
index 490923b..995a213 100644
--- a/src/rivet.h
+++ b/src/rivet.h
@@ -1,3 +1,19 @@
+/* Copyright 2002-2004 The Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   	http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+/* $Id$ */
 
 /* This is for windows. */
 #ifdef BUILD_rivet
@@ -7,6 +23,9 @@
 
 #define STREQU(s1, s2)  (s1[0] == s2[0] && strcmp(s1, s2) == 0)
 #define STRNEQU(s1, s2) (s1[0] == s2[0] && strncmp(s1, s2, strlen(s2)) == 0)
+#define RIVET_NS                "::rivet"
+#define RIVET_TCL_PACKAGE       "rivet"
+#define RIVETLIB_TCL_PACKAGE    "rivetlib"
 
 #define TCL_CMD_HEADER(cmd)	\
 static int cmd(\
@@ -22,8 +41,21 @@
 		      NULL,   /* Client Data */\
 		      (Tcl_CmdDeleteProc *)NULL /* Tcl Delete Prov */)
 
-EXTERN int Rivet_Init( Tcl_Interp *interp );
-EXTERN int Rivet_InitList( Tcl_Interp *interp );
-EXTERN int Rivet_InitCrypt( Tcl_Interp *interp );
-EXTERN int Rivet_InitWWW( Tcl_Interp *interp );
-EXTERN int Rivet_InitCore( Tcl_Interp *interp );
+/* RIVET_OBJ_CMD creates a command in the RIVET_NS namespace. Commands
+ * are exported from the RIVET_NS (::rivet) namespace in the init.tcl 
+ * script accordingly to configuration switches passed to ./configure
+ * (see configure.ac)
+ */
+
+#define RIVET_OBJ_CMD(name,func) \
+Tcl_CreateObjCommand( interp, /* Tcl interpreter */\
+		      RIVET_NS "::" name,   /* Function name in Tcl */\
+		      func,   /* C function name */\
+		      NULL,   /* Client Data */\
+		      (Tcl_CmdDeleteProc *)NULL /* Tcl Delete Prov */); 
+
+EXTERN int Rivet_Init(Tcl_Interp *interp);
+EXTERN int Rivet_InitList(Tcl_Interp *interp);
+EXTERN int Rivet_InitCrypt(Tcl_Interp *interp);
+EXTERN int Rivet_InitWWW(Tcl_Interp *interp);
+EXTERN int Rivet_InitCore(Tcl_Interp *interp); 
diff --git a/src/rivetCrypt.c b/src/rivetCrypt.c
index 58e1951..3f89380 100644
--- a/src/rivetCrypt.c
+++ b/src/rivetCrypt.c
@@ -8,7 +8,7 @@
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
-   	http://www.apache.org/licenses/LICENSE-2.0
+    http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
@@ -45,19 +45,19 @@
 
     while (*string != '\0')
     {
-	if (*string >= 32 && *string <= 126)
-	{
-	    if (mode)
-		*string = (((*string - 32) + (*kp - 32)) % 94) + 32;
-	    else
-		*string = (((*string - 32) - (*kp - 32) + 94) % 94) + 32;
-	}
+        if (*string >= 32 && *string <= 126)
+        {
+            if (mode)
+                *string = (((*string - 32) + (*kp - 32)) % 94) + 32;
+            else
+                *string = (((*string - 32) - (*kp - 32) + 94) % 94) + 32;
+        }
 
-	string++;
-	kp++;
-	if (*kp == '\0') {
-	    kp = key;
-	}
+        string++;
+        kp++;
+        if (*kp == '\0') {
+            kp = key;
+        }
     }
 }
 
@@ -69,7 +69,7 @@
     int keyIndex;
 
     if( objc < 3 ) {
-	Tcl_WrongNumArgs( interp, 1, objv, "data key" );
+        Tcl_WrongNumArgs( interp, 1, objv, "data key" );
         return TCL_ERROR;
     }
 
@@ -80,7 +80,7 @@
 
     for( keyIndex = 2; keyIndex < objc; keyIndex++ )
     {
-	key = Tcl_GetStringFromObj( objv[keyIndex], NULL );
+        key = Tcl_GetStringFromObj( objv[keyIndex], NULL );
         Rivet_Crypt( resultBuffer, key, 0L, MODE_ENCRYPT );
     }
 
@@ -97,7 +97,7 @@
     int keyIndex;
 
     if( objc < 3 ) {
-	Tcl_WrongNumArgs( interp, 1, objv, "data key" );
+    Tcl_WrongNumArgs( interp, 1, objv, "data key" );
         return TCL_ERROR;
     }
 
@@ -108,7 +108,7 @@
 
     for( keyIndex = 2; keyIndex < objc; keyIndex++ )
     {
-	key = Tcl_GetStringFromObj( objv[keyIndex], NULL );
+        key = Tcl_GetStringFromObj( objv[keyIndex], NULL );
         Rivet_Crypt( resultBuffer, key, 0L, MODE_DECRYPT );
     }
 
@@ -124,7 +124,7 @@
     const char *resultBuffer;
 
     if( objc != 3 ) {
-	Tcl_WrongNumArgs( interp, 1, objv, "key salt" );
+        Tcl_WrongNumArgs( interp, 1, objv, "key salt" );
         return TCL_ERROR;
     }
 
@@ -134,17 +134,16 @@
     resultBuffer = crypt((const char *)key, (const char *)salt);
 
     if( resultBuffer == NULL ) {
-	Tcl_AppendResult (interp,
-		"crypt function failed: ",
-		Tcl_GetStringFromObj(objv[1], NULL),
-		(char *)NULL );
-	return TCL_ERROR;
+        Tcl_AppendResult (interp,
+                            "crypt function failed: ",
+                            Tcl_GetStringFromObj(objv[1], NULL),
+                            (char *)NULL );
+        return TCL_ERROR;
     }
     Tcl_SetObjResult( interp, Tcl_NewStringObj( resultBuffer, -1 ) );
     return TCL_OK;
 #else /* ! crypt */
-    Tcl_SetObjResult(interp, 
-                     Tcl_NewStringObj("error: command not available", -1));
+    Tcl_SetObjResult(interp,Tcl_NewStringObj("error: command not available", -1));
     return TCL_ERROR;
 #endif /* ! crypt */
 }
@@ -162,11 +161,10 @@
  *-----------------------------------------------------------------------------
  */
 int
-Rivet_InitCrypt( Tcl_Interp *interp )
+Rivet_InitCrypt( Tcl_Interp *interp)
 {
-    TCL_OBJ_CMD( "encrypt", Rivet_EncryptCmd );
-    TCL_OBJ_CMD( "decrypt", Rivet_DecryptCmd );
-    TCL_OBJ_CMD( "crypt", Rivet_CryptCmd );
-
+    RIVET_OBJ_CMD("encrypt", Rivet_EncryptCmd);
+    RIVET_OBJ_CMD("decrypt", Rivet_DecryptCmd);
+    RIVET_OBJ_CMD("crypt", Rivet_CryptCmd);
     return TCL_OK;
 }
diff --git a/src/rivetList.c b/src/rivetList.c
index b500913..783c503 100644
--- a/src/rivetList.c
+++ b/src/rivetList.c
@@ -8,7 +8,7 @@
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
 
-   	http://www.apache.org/licenses/LICENSE-2.0
+    http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,7 +21,7 @@
 
 /* Rivet config */
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include <rivet_config.h>
 #endif
 
 #include <tcl.h>
@@ -55,9 +55,9 @@
     Tcl_Obj **listObjv, *matchedListPtr = NULL;
 
     if( objc < 3 ) {
-	Tcl_WrongNumArgs( interp, 1, objv,
-	    "?mode? ?-all? list ?pattern?.. ?pattern?..");
-	return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv,
+            "?mode? ?-all? list ?pattern?.. ?pattern?..");
+        return TCL_ERROR;
     }
 
     list = 1;
@@ -69,35 +69,35 @@
      */
     for( i = 1; i < objc; ++i )
     {
-	modeStr = Tcl_GetStringFromObj(objv[i], NULL);
-	if( modeStr[0] != '-' ) break;
+        modeStr = Tcl_GetStringFromObj(objv[i], NULL);
+        if( modeStr[0] != '-' ) break;
 
-	if( STREQU(modeStr, "-exact") ) {
-	    mode = EXACT;
-	    list++;
-	} else if( STREQU(modeStr, "-glob") ) {
-	    mode = GLOB;
-	    list++;
-	} else if( STREQU(modeStr, "-regexp") ) {
-	    mode = REGEXP;
-	    list++;
-	} else if( STREQU(modeStr, "-all") ) {
-	    all = 1;
-	    list++;
-	} else if( STREQU(modeStr, "--") ) {
-	    list++;
-	    break;
-	} else {
-	    Tcl_AppendResult( interp, "bad switch \"", modeStr,
-				"\": must be -exact, -glob, -regexp or -all",
-				(char *)NULL);
-	    return TCL_ERROR;
-	}
+        if( STREQU(modeStr, "-exact") ) {
+            mode = EXACT;
+            list++;
+        } else if( STREQU(modeStr, "-glob") ) {
+            mode = GLOB;
+            list++;
+        } else if( STREQU(modeStr, "-regexp") ) {
+            mode = REGEXP;
+            list++;
+        } else if( STREQU(modeStr, "-all") ) {
+            all = 1;
+            list++;
+        } else if( STREQU(modeStr, "--") ) {
+            list++;
+            break;
+        } else {
+            Tcl_AppendResult( interp, "bad switch \"", modeStr,
+                    "\": must be -exact, -glob, -regexp or -all",
+                    (char *)NULL);
+            return TCL_ERROR;
+        }
     }
 
     if( list >= objc - 1 )  {
-	Tcl_WrongNumArgs(interp, 1, objv, "?mod? ?-all? list pattern");
-	return TCL_ERROR;
+        Tcl_WrongNumArgs(interp, 1, objv, "?mod? ?-all? list pattern");
+        return TCL_ERROR;
     }
 
     if( Tcl_ListObjGetElements(interp, objv[list],
@@ -108,80 +108,80 @@
     for(i = 0; i < listObjc; i++)
     {
         match = 0;
-	value = Tcl_GetStringFromObj(listObjv[i], &valueLen);
+        value = Tcl_GetStringFromObj(listObjv[i], &valueLen);
 
-	/* We're done.  Append the rest of the elements and return */
-	if( done ) {
-	    if (matchedListPtr == NULL) {
-		matchedListPtr = Tcl_NewListObj(0, NULL);
-	    }
-	    if (Tcl_ListObjAppendElement(interp, matchedListPtr,
-					 listObjv[i]) != TCL_OK) {
-		goto errorExit;
-	    }
-	    continue;
-	}
+    /* We're done.  Append the rest of the elements and return */
+        if( done ) {
+            if (matchedListPtr == NULL) {
+                matchedListPtr = Tcl_NewListObj(0, NULL);
+            }
+            if (Tcl_ListObjAppendElement(interp, matchedListPtr,
+                         listObjv[i]) != TCL_OK) {
+                goto errorExit;
+            }
+            continue;
+        }
 
-	append = list + 1;
-	for( j = list + 1; j < objc; ++j )
-	{
-	    pattern = Tcl_GetStringFromObj(objv[j], &patternLen);
-	    if( (mode != EXACT) && (strlen(pattern) != (size_t)patternLen) ) {
-		goto binData;
-	    }
+        append = list + 1;
+        for( j = list + 1; j < objc; ++j )
+        {
+            pattern = Tcl_GetStringFromObj(objv[j], &patternLen);
+            if( (mode != EXACT) && (strlen(pattern) != (size_t)patternLen) ) {
+                goto binData;
+            }
 
-	    switch(mode) {
-	      case EXACT:
-		match = (valueLen == patternLen) &&
-		    (memcmp(value, pattern, (unsigned)valueLen) == 0);
-		break;
+            switch(mode) {
+              case EXACT:
+                match = (valueLen == patternLen) &&
+                        (memcmp(value, pattern, (unsigned)valueLen) == 0);
+                break;
 
-	      case GLOB:
-		if( strlen(value) != (size_t)valueLen ) {
-		    goto binData;
-		}
-		match = Tcl_StringMatch(value, pattern);
-		break;
+              case GLOB:
+                if( strlen(value) != (size_t)valueLen ) {
+                    goto binData;
+                }
+                match = Tcl_StringMatch(value, pattern);
+                break;
 
-	      case REGEXP:
-		if( strlen(value) != (size_t)valueLen ) {
-		    goto binData;
-		}
-		match = Tcl_RegExpMatch(interp, value, pattern);
-		if( match < 0 ) {
-		    goto errorExit;
-		}
-		break;
-	    }
-	    /* It's not in the pattern we're looking for.
-	     * Check the next pattern.
-	     */
-	    if( !match ) {
-		append++;
-		continue;
-	    }
+              case REGEXP:
+                if( strlen(value) != (size_t)valueLen ) {
+                    goto binData;
+                }
+                match = Tcl_RegExpMatch(interp, value, pattern);
+                if( match < 0 ) {
+                    goto errorExit;
+                }
+                break;
+            }
+            /* It's not in the pattern we're looking for.
+             * Check the next pattern.
+             */
+            if( !match ) {
+                append++;
+                continue;
+            }
 
-	    /* We found a match, and we're not looking for anymore */
-	    if( !all ) {
-		done = 1;
-		break;
-	    }
-	}
+            /* We found a match, and we're not looking for anymore */
+            if( !all ) {
+                done = 1;
+                break;
+            }
+        }
 
-	/* We're done.  Append the rest of the elements and return */
-	if( done ) continue;
+    /* We're done.  Append the rest of the elements and return */
+        if( done ) continue;
 
-	/* If append is equal to j, the value made it through all the patterns
-	 * without matching, so we append it to our return list.
-	 */
-	if( append == j ) {
-	    if (matchedListPtr == NULL) {
-		matchedListPtr = Tcl_NewListObj(0, NULL);
-	    }
-	    if (Tcl_ListObjAppendElement(interp, matchedListPtr,
-					 listObjv[i]) != TCL_OK)
-		goto errorExit;
-	}
+    /* If append is equal to j, the value made it through all the patterns
+     * without matching, so we append it to our return list.
+     */
+        if( append == j ) {
+            if (matchedListPtr == NULL) {
+                matchedListPtr = Tcl_NewListObj(0, NULL);
+            }
+            if (Tcl_ListObjAppendElement(interp, matchedListPtr,
+                         listObjv[i]) != TCL_OK)
+            goto errorExit;
+        }
     }
 
     if( matchedListPtr != NULL ) {
@@ -196,7 +196,7 @@
 
   binData:
     Tcl_AppendResult(interp, "Binary data is not supported in this mode.",
-				(char *) NULL);
+                (char *) NULL);
     return TCL_ERROR;
 }
 
@@ -251,8 +251,8 @@
     int          quotePairsWithinStrings = 1;
 
     if( objc != 2 ) {
-	Tcl_WrongNumArgs( interp, 1, objv, "string" );
-	return TCL_ERROR;
+    Tcl_WrongNumArgs( interp, 1, objv, "string" );
+    return TCL_ERROR;
     }
 
     /* get access to a textual representation of the object */
@@ -267,113 +267,111 @@
     /* this loop walks through the comma-separated string we've been passed */
     while (1) {
 
-	/* grab the next character in the buffer */
+    /* grab the next character in the buffer */
         c = *next;
 
-	/* if we've got a quote at this point, it is at the start
-	 * of a field, scan to the closing quote, make that a field, 
-	 * and update */
+    /* if we've got a quote at this point, it is at the start
+     * of a field, scan to the closing quote, make that a field, 
+     * and update */
 
-	if (c == '"') {
-	    next = ++first;
-	    while (1) {
-	        c = *next;
-		/*
-		 * if we're at the end, we've got an unterminated quoted string
-		 */
-	        if (c == '\0') goto format_error;
-
-                /*
-		 * If we get a double quote, first see if it's a pair of double 
-		 * quotes, i.e. a quoted quote, and handle that.
-		 */
-	        if (c == '"') {
-		    /* if consecutive pairs of quotes as quotes of quotes
-		     * is enabled and the following char is a double quote,
-		     * turn the pair into a single by zooming on down */
-		    if (quotequoteQuotesQuote && (*(next + 1) == '"')) {
-			next += 2;
-			continue;
-		    }
-
-		    /* If double quotes within strings is enabled and the
-		     * char following this quote is not a comma, scan forward
-		     * for a quote */
-		    if (quotePairsWithinStrings && (*(next + 1) != ',')) {
-			next++;
-			continue;
-		    }
-		    /* It's a solo double-quote, not a pair of double-quotes, 
-		     * so terminate the element
-		     * at the current quote (the closing quote).
-		     */
-		    Rivet_ListObjAppendString (interp,
-			      resultList, first, next - first);
-
-		    /* skip the closing quote that we overwrote, and the
-		     * following comma if there is one.
-		     */
-
-		    ++next;
-		    c = *next;
-
-		    /* 
-		     *if we get end-of-line here, it's fine... and we're done
-		     */
-
-		    if (c == '\0')
-			return TCL_OK;
+        if (c == '"') {
+            next = ++first;
+            while (1) {
+                c = *next;
+            /*
+             * if we're at the end, we've got an unterminated quoted string
+             */
+                if (c == '\0') goto format_error;
 
                     /*
-		     * It's not end-of-line.  If the next character is
-		     * not a comma, it's an error.
-		     */
-		    if (c != ',') {
-		      format_error:
-			Tcl_ResetResult (interp);
-			Tcl_AppendResult (interp,
-					  "format error in string: \"", 
-					   first, "\"", (char *) NULL);
-			return TCL_ERROR;
-		    }
+             * If we get a double quote, first see if it's a pair of double 
+             * quotes, i.e. a quoted quote, and handle that.
+             */
+                if (c == '"') {
+                /* if consecutive pairs of quotes as quotes of quotes
+                 * is enabled and the following char is a double quote,
+                 * turn the pair into a single by zooming on down */
+                    if (quotequoteQuotesQuote && (*(next + 1) == '"')) {
+                        next += 2;
+                        continue;
+                    }
 
-		    /* We're done with that field.  The next one starts one
-		     * character past the current one, which is (was) a
-		     * comma */
-		    first = ++next;
-		    break;
-		}
-		/* It wasn't a quote, look at the next character. */
-		next++;
-	    }
-	    continue;
-	}
+                /* If double quotes within strings is enabled and the
+                 * char following this quote is not a comma, scan forward
+                 * for a quote */
+                    if (quotePairsWithinStrings && (*(next + 1) != ',')) {
+                        next++;
+                        continue;
+                    }
+                /* It's a solo double-quote, not a pair of double-quotes, 
+                 * so terminate the element
+                 * at the current quote (the closing quote).
+                 */
+                    Rivet_ListObjAppendString (interp,resultList, first, next - first);
 
-	/* If we get here, we're at the start of a field that didn't
-	 * start with a quote */
-	next = first;
-	while (1) {
-	    c = *next;
+                /* skip the closing quote that we overwrote, and the
+                 * following comma if there is one.
+                 */
 
-            /* If we reach end of the string, append the last element
-	     * and return to our caller. */
-	    if (c == '\0') {
-		Rivet_ListObjAppendString (interp, resultList, first, -1);
-		return TCL_OK;
-	    }
+                    ++next;
+                    c = *next;
 
-            /* If we get a comma, that's the end of this piece,
-	     * stick it into the list.
-	     */
-	    if (c == ',') {
-		Rivet_ListObjAppendString (interp,
-			  resultList,
-			  first, next - first);
-		first = ++next;
-		break;
-	    }
-	    next++;
-	}
+                /* 
+                 *if we get end-of-line here, it's fine... and we're done
+                 */
+
+                    if (c == '\0') return TCL_OK;
+
+                        /*
+                 * It's not end-of-line.  If the next character is
+                 * not a comma, it's an error.
+                 */
+                    if (c != ',') {
+                      format_error:
+                        Tcl_ResetResult (interp);
+                        Tcl_AppendResult (interp,
+                                  "format error in string: \"", 
+                                   first, "\"", (char *) NULL);
+                        return TCL_ERROR;
+                    }
+
+                /* We're done with that field.  The next one starts one
+                 * character past the current one, which is (was) a
+                 * comma */
+                    first = ++next;
+                    break;
+                }
+            /* It wasn't a quote, look at the next character. */
+                next++;
+            }
+            continue;
+        }
+
+    /* If we get here, we're at the start of a field that didn't
+     * start with a quote */
+        next = first;
+        while (1) {
+            c = *next;
+
+                /* If we reach end of the string, append the last element
+             * and return to our caller. */
+            if (c == '\0') {
+                Rivet_ListObjAppendString (interp, resultList, first, -1);
+                return TCL_OK;
+            }
+
+                /* If we get a comma, that's the end of this piece,
+             * stick it into the list.
+             */
+            if (c == ',') {
+                Rivet_ListObjAppendString (interp,
+                      resultList,
+                      first, next - first);
+                first = ++next;
+                break;
+            }
+            next++;
+        }
     }
     Rivet_ListObjAppendString (interp, resultList, first, -1);
     return TCL_OK;
@@ -412,54 +410,54 @@
     int         stringLength;
 
     if( objc != 2 ) {
-	Tcl_WrongNumArgs( interp, 1, objv,
-			"list arrayName elementName ?elementName..?" );
+    Tcl_WrongNumArgs( interp, 1, objv,
+            "list arrayName elementName ?elementName..?" );
         return TCL_ERROR;
     }
 
     resultPtr = Tcl_GetObjResult (interp);
 
     if (Tcl_ListObjGetElements  (interp, 
-				 objv[1], 
-				 &listObjc, 
-				 &listObjv) != TCL_OK) {
-	return TCL_ERROR;
+                 objv[1], 
+                 &listObjc, 
+                 &listObjv) != TCL_OK) {
+        return TCL_ERROR;
     }
 
     didField = 0;
     for (listIdx = 0; listIdx < listObjc; listIdx++) {
-	/* If it's the first thing we've output, start it out
-	 * with a double quote.  If not, terminate the last
-	 * element with a double quote, then put out a comma,
-	 * then open the next element with a double quote
-	 */
-	if (didField) {
-	    Tcl_AppendToObj (resultPtr, "\",\"", 3);
-	} else {
-	    Tcl_AppendToObj (resultPtr, "\"", 1);
-	    didField = 1;
-	}
-	walkPtr = strPtr  = Tcl_GetStringFromObj (listObjv[listIdx], &stringLength);
-	/* Walk the string of the list element that we're about to
-	 * append to the result object.
-	 *
-	 * For each character, if it isn't a double quote, move on to
-	 * the next character until the string is exhausted.
-	 */
-	for (;stringLength; stringLength--) {
-	    if (*walkPtr++ != '"') continue;
+        /* If it's the first thing we've output, start it out
+         * with a double quote.  If not, terminate the last
+         * element with a double quote, then put out a comma,
+         * then open the next element with a double quote
+         */
+        if (didField) {
+            Tcl_AppendToObj (resultPtr, "\",\"", 3);
+        } else {
+            Tcl_AppendToObj (resultPtr, "\"", 1);
+            didField = 1;
+        }
+        walkPtr = strPtr  = Tcl_GetStringFromObj (listObjv[listIdx], &stringLength);
+        /* Walk the string of the list element that we're about to
+         * append to the result object.
+         *
+         * For each character, if it isn't a double quote, move on to
+         * the next character until the string is exhausted.
+         */
+        for (;stringLength; stringLength--) {
+            if (*walkPtr++ != '"') continue;
 
-	    /* OK, we saw a double quote.  Emit everything up to and
-	     * including the double quote, then reset the string to
-	     * start at the same double quote (to issue it twice and
-	     * pick up where we left off.  Be sure to get the length
-	     * calculations right!
-	     */
+            /* OK, we saw a double quote.  Emit everything up to and
+             * including the double quote, then reset the string to
+             * start at the same double quote (to issue it twice and
+             * pick up where we left off.  Be sure to get the length
+             * calculations right!
+             */
 
-	     Tcl_AppendToObj (resultPtr, strPtr, walkPtr - strPtr);
-	     strPtr = walkPtr - 1;
-	}
-	Tcl_AppendToObj (resultPtr, strPtr, walkPtr - strPtr);
+             Tcl_AppendToObj (resultPtr, strPtr, walkPtr - strPtr);
+             strPtr = walkPtr - 1;
+        }
+        Tcl_AppendToObj (resultPtr, strPtr, walkPtr - strPtr);
     }
     Tcl_AppendToObj (resultPtr, "\"", 1);
     return TCL_OK;
@@ -480,13 +478,13 @@
  */
 TCL_CMD_HEADER( Rivet_LassignArrayObjCmd )
 {
-    int	    listObjc, listIdx, idx;
+    int     listObjc, listIdx, idx;
     Tcl_Obj **listObjv;
     Tcl_Obj *varValue;
 
     if( objc < 4 ) {
-	Tcl_WrongNumArgs( interp, 1, objv,
-			"list arrayName elementName ?elementName..?");
+    Tcl_WrongNumArgs( interp, 1, objv,
+            "list arrayName elementName ?elementName..?");
         return TCL_ERROR;
     }
 
@@ -495,27 +493,27 @@
         return TCL_ERROR;
 
     for (idx = 3, listIdx = 0; idx < objc; idx++, listIdx++) {
-	varValue = (listIdx < listObjc) ?
-		listObjv[listIdx] : Tcl_NewStringObj("", -1);
+    varValue = (listIdx < listObjc) ?
+        listObjv[listIdx] : Tcl_NewStringObj("", -1);
 
-	if( Tcl_ObjSetVar2( interp, objv[2], objv[idx],
-				varValue, TCL_LEAVE_ERR_MSG ) == NULL ) {
-	    return TCL_ERROR;
+    if( Tcl_ObjSetVar2( interp, objv[2], objv[idx],
+                varValue, TCL_LEAVE_ERR_MSG ) == NULL ) {
+        return TCL_ERROR;
         }
     }
 
     /* We have some left over items.  Return them in a list. */
     if( listIdx < listObjc ) {
-	Tcl_Obj *list = Tcl_NewListObj( 0, NULL );
-	int i;
+    Tcl_Obj *list = Tcl_NewListObj( 0, NULL );
+    int i;
 
-	for( i = listIdx; i < listObjc; ++i )
-	{
-	    if (Tcl_ListObjAppendElement(interp, list, listObjv[i]) != TCL_OK) {
-		return TCL_ERROR;
-	    }
-	}
-	Tcl_SetObjResult( interp, list );
+    for( i = listIdx; i < listObjc; ++i )
+    {
+        if (Tcl_ListObjAppendElement(interp, list, listObjv[i]) != TCL_OK) {
+        return TCL_ERROR;
+        }
+    }
+    Tcl_SetObjResult( interp, list );
     }
     return TCL_OK;
 }
@@ -530,16 +528,18 @@
  *
  * Parameters:
  *   o interp - Interpreter to add commands to.
+ *   o rivet_ns - Tcl_Namespace pointer to the RIVET_NS namespace.
+ *
  *-----------------------------------------------------------------------------
  */
-int
-Rivet_InitList( interp )
-    Tcl_Interp *interp;
+
+int 
+Rivet_InitList( Tcl_Interp *interp)
 {
-    TCL_OBJ_CMD( "lremove", Rivet_LremoveObjCmd );
-    TCL_OBJ_CMD( "comma_split", Rivet_CommaSplitObjCmd );
-    TCL_OBJ_CMD( "comma_join", Rivet_CommaJoinObjCmd );
-    TCL_OBJ_CMD( "lassign_array", Rivet_LassignArrayObjCmd );
+    RIVET_OBJ_CMD("lremove",Rivet_LremoveObjCmd);
+    RIVET_OBJ_CMD("comma_split",Rivet_CommaSplitObjCmd);
+    RIVET_OBJ_CMD("comma_join",Rivet_CommaJoinObjCmd);
+    RIVET_OBJ_CMD("lassign_array",Rivet_LassignArrayObjCmd);
 
     return TCL_OK;
 }
diff --git a/src/rivetPkgInit.c b/src/rivetPkgInit.c
index 98b8b0f..b41b5a8 100644
--- a/src/rivetPkgInit.c
+++ b/src/rivetPkgInit.c
@@ -19,54 +19,129 @@
 
 /* Rivet config */
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include <rivet_config.h>
 #endif
 
-
 #include <tcl.h>
 #include "rivet.h"
+#include "mod_rivet.h"
 
-
 /*-----------------------------------------------------------------------------
- * Rivet_Init --
+ * Rivet_GetNamespace --
+ *
+ *   Get the rivet namespace pointer. The procedure attempts to retrieve a
+ *  pointer to the Tcl_Namespace structure for the ::rivet namespace. This
+ *  pointer is stored in the interpreter's associated data (pointing to a
+ *  rivet_interp_globals structure) if the interpreter is passed by mod_rivet.
+ *  Otherwise a new ::rivet namespace is created and its Tcl_Namespace
+ *  pointer is returned 
+ *
+ * Parameters:
+ *
+ *   o interp - Interpreter to add commands to.
+ *
+ * Returned value:
+ *
+ *   o rivet_ns - Tcl_Namespace* pointer to the RIVET_NS (::rivet) namespace
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+#if RIVET_NAMESPACE_EXPORT == 1
+
+static Tcl_Namespace* 
+Rivet_GetNamespace( Tcl_Interp* interp)
+{
+    rivet_interp_globals *globals; 
+    Tcl_Namespace *rivet_ns;
+
+    globals = Tcl_GetAssocData(interp, "rivet", NULL);
+    if (globals != NULL)
+    {
+        rivet_ns = globals->rivet_ns;
+    }
+    else
+    {
+//      fprintf(stderr,"no Associated data found, running standalone\n");
+        rivet_ns = Tcl_CreateNamespace (interp,RIVET_NS,NULL,(Tcl_NamespaceDeleteProc *)NULL);
+    }
+
+    return rivet_ns;
+}
+#endif
+
+/*-----------------------------------------------------------------------------
+ * Rivetlib_Init --
+ *
  *   Install the commands provided by librivet into an interpreter.
  *
  * Parameters:
+ *
  *   o interp - Interpreter to add commands to.
+ *
  *-----------------------------------------------------------------------------
  */
+
 int
-Rivet_Init( Tcl_Interp *interp )
+Rivetlib_Init( Tcl_Interp *interp )
 {
-    Rivet_InitList( interp );
+#if RIVET_NAMESPACE_EXPORT == 1
+    Tcl_Namespace *rivet_ns = Rivet_GetNamespace(interp);; 
+#endif
 
-    Rivet_InitCrypt( interp );
+#ifdef RIVET_USE_TCL_STUBS
+    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { 
+#else
+	if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) { 
+#endif    
+	    return TCL_ERROR;
+    }
 
-    Rivet_InitWWW( interp );
+    Rivet_InitList (interp);
+    Rivet_InitCrypt(interp);
+    Rivet_InitWWW  (interp);
+#if RIVET_NAMESPACE_EXPORT == 1
+    Tcl_Export(interp,rivet_ns,"*",0);
+#endif
 
-    return Tcl_PkgProvide( interp, "Rivet", "1.1" );
+    return Tcl_PkgProvide( interp, RIVETLIB_TCL_PACKAGE, "1.2" );
 }
 
-
 /*-----------------------------------------------------------------------------
- * Rivet_SafeInit --
+ * Rivetlib_SafeInit --
  *   Install the commands provided by librivet that are believed to be
  *   safe for use in safe interpreters, into a safe interpreter.
  *
  * Parameters:
+ *
  *   o interp - Interpreter to add commands to.
+ *
  *-----------------------------------------------------------------------------
  */
+
+/*
 int
-Rivet_SafeInit( Tcl_Interp *interp )
+Rivetlib_SafeInit( Tcl_Interp *interp )
 {
-    Rivet_InitList( interp );
+#if RIVET_NAMESPACE_EXPORT == 1
+    Tcl_Namespace *rivet_ns = Rivet_GetNamespace(interp);
+#endif
 
-    Rivet_InitCrypt( interp );
+#ifdef RIVET_USE_TCL_STUBS
+    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { 
+#else
+	if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) { 
+#endif    
+	    return TCL_ERROR;
+    }
 
-    Rivet_InitWWW( interp );
+    Rivet_InitList(interp);
+    Rivet_InitCrypt(interp);
+    Rivet_InitWWW(interp);
 
-    return Tcl_PkgProvide( interp, "Rivet", "1.1" );
+#if RIVET_NAMESPACE_EXPORT == 1
+    Tcl_Export(interp,rivet_ns,"*",0);
+#endif
+    return Tcl_PkgProvide( interp, RIVETLIB_TCL_PACKAGE, "1.2" );
 }
-
-
+*/
diff --git a/src/rivetWWW.c b/src/rivetWWW.c
index 2147271..c6f3f47 100644
--- a/src/rivetWWW.c
+++ b/src/rivetWWW.c
@@ -21,7 +21,7 @@
 
 /* Rivet config */
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include <rivet_config.h>
 #endif
 
 #include <tcl.h>
@@ -47,16 +47,17 @@
 Rivet_HexToDigit(int c) {
 
     if (c >= 'a' && c <= 'f') {
-	return (c - 'a' + 10);
+        return (c - 'a' + 10);
     }
 
     if (c >= 'A' && c <= 'F') {
-	return (c - 'A' + 10);
+        return (c - 'A' + 10);
     }
 
     if (c >= '0' && c <= '9') {
-	return (c - '0');
+        return (c - '0');
     }
+
     return (-1);
 }
 
@@ -79,8 +80,8 @@
     int digit1, digit2;
 
     if ( objc != 2 ) {
-	Tcl_WrongNumArgs( interp, 1, objv, "string" );
-	return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv, "string" );
+        return TCL_ERROR;
     }
 
     origString = Tcl_GetStringFromObj( objv[1], &origLength );
@@ -88,39 +89,40 @@
 
     /* for all the characters in the source string */
     for (origStringP = origString, newStringP = newString;
-	 *origStringP != '\0';
-	 origStringP++) {
-	 char c = *origStringP;
-	 char c2;
+	        *origStringP != '\0';
+	        origStringP++) {
 
-         /* map plus to space */
-	 if (c == '+') {
-	     *newStringP++ = ' ';
-	     continue;
-	 }
+        char c = *origStringP;
+        char c2;
 
-         /* if there's a percent sign, decode the two-character
-	  * hex sequence that follows and copy it to the target
-	  * string */
-	 if (c == '%') {
-	     digit1 = Rivet_HexToDigit(c = *++origStringP);
-	     digit2 = Rivet_HexToDigit(c2 = *++origStringP);
+             /* map plus to space */
+        if (c == '+') {
+            *newStringP++ = ' ';
+             continue;
+        }
 
-	    if (digit1 == -1 || digit2 == -1) {
-		char buf[2];
-		snprintf( buf, 2, "%c%c", c, c2 );
-		Tcl_AppendResult( interp,
-			Tcl_GetStringFromObj( objv[0], NULL ),
-			": bad char in hex sequence %", buf, (char *)NULL );
-		return TCL_ERROR;
-	     }
+             /* if there's a percent sign, decode the two-character
+          * hex sequence that follows and copy it to the target
+          * string */
+        if (c == '%') {
+            digit1 = Rivet_HexToDigit(c = *++origStringP);
+            digit2 = Rivet_HexToDigit(c2 = *++origStringP);
 
-	     *newStringP++ = (digit1 * 16 + digit2);
-	     continue;
-	 }
+            if (digit1 == -1 || digit2 == -1) {
+                char buf[2];
+                snprintf( buf, 2, "%c%c", c, c2 );
+                Tcl_AppendResult( interp,
+                    Tcl_GetStringFromObj( objv[0], NULL ),
+                    ": bad char in hex sequence %", buf, (char *)NULL );
+                return TCL_ERROR;
+            }
 
-         /* it wasn't a plus or percent, just copy the char across */
-	 *newStringP++ = c;
+             *newStringP++ = (digit1 * 16 + digit2);
+             continue;
+         }
+
+             /* it wasn't a plus or percent, just copy the char across */
+         *newStringP++ = c;
     }
     /* Don't forget to null-terminate the target string */
     *newStringP = '\0';
@@ -169,8 +171,8 @@
     int origLength;
 
     if ( objc != 2 ) {
-	Tcl_WrongNumArgs( interp, 1, objv, "string" );
-	return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv, "string" );
+        return TCL_ERROR;
     }
 
     origString = Tcl_GetStringFromObj( objv[1], &origLength );
@@ -182,19 +184,19 @@
 
     /* for all the characters in the source string */
     for (origStringP = origString, newStringP = newString;
-	*origStringP != '\0';
-	origStringP++) {
-	char c = *origStringP;
+	    *origStringP != '\0';
+	    origStringP++) {
+        char c = *origStringP;
 
-        if (isalnum ((int)c)) {
-	    *newStringP++ = c;
-	} else if (c == ' ') {
-	    *newStringP++ = '+';
-	} else {
-	    *newStringP++ = '%';
-	    *newStringP++ = Rivet_DigitToHex((c >> 4) & 0x0f);
-	    *newStringP++ = Rivet_DigitToHex(c & 0x0f);
-	}
+            if (isalnum ((int)c)) {
+            *newStringP++ = c;
+        } else if (c == ' ') {
+            *newStringP++ = '+';
+        } else {
+            *newStringP++ = '%';
+            *newStringP++ = Rivet_DigitToHex((c >> 4) & 0x0f);
+            *newStringP++ = Rivet_DigitToHex(c & 0x0f);
+        }
     }
     /* Don't forget to null-terminate the target string */
     *newStringP = '\0';
@@ -222,8 +224,8 @@
     int origLength;
 
     if( objc != 2 ) {
-	Tcl_WrongNumArgs( interp, 1, objv, "string" );
-	return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv, "string" );
+        return TCL_ERROR;
     }
 
     origString = Tcl_GetStringFromObj( objv[1], &origLength );
@@ -235,49 +237,50 @@
 
     /* for all the characters in the source string */
     for (origStringP = origString, newStringP = newString;
-	*origStringP != '\0';
-	origStringP++) {
-	char c = *origStringP;
+	    *origStringP != '\0';
+	    origStringP++) {
 
-	switch(c) {
-	    case '&':
-		*newStringP++ = '&';
-		*newStringP++ = 'a';
-		*newStringP++ = 'm';
-		*newStringP++ = 'p';
-		*newStringP++ = ';';
-		break;
-	    case '<':
-		*newStringP++ = '&';
-		*newStringP++ = 'l';
-		*newStringP++ = 't';
-		*newStringP++ = ';';
-		break;
-	    case '>':
-		*newStringP++ = '&';
-		*newStringP++ = 'g';
-		*newStringP++ = 't';
-		*newStringP++ = ';';
-		break;
-	    case '\'':
-		*newStringP++ = '&';
-		*newStringP++ = '#';
-		*newStringP++ = '3';
-		*newStringP++ = '9';
-		*newStringP++ = ';';
-		break;
-	    case '"':
-		*newStringP++ = '&';
-		*newStringP++ = 'q';
-		*newStringP++ = 'u';
-		*newStringP++ = 'o';
-		*newStringP++ = 't';
-		*newStringP++ = ';';
-		break;
-	    default:
-		*newStringP++ = c;
-		break;
-	}
+        char c = *origStringP;
+
+        switch(c) {
+            case '&':
+                *newStringP++ = '&';
+                *newStringP++ = 'a';
+                *newStringP++ = 'm';
+                *newStringP++ = 'p';
+                *newStringP++ = ';';
+                break;
+            case '<':
+                *newStringP++ = '&';
+                *newStringP++ = 'l';
+                *newStringP++ = 't';
+                *newStringP++ = ';';
+                break;
+            case '>':
+                *newStringP++ = '&';
+                *newStringP++ = 'g';
+                *newStringP++ = 't';
+                *newStringP++ = ';';
+                break;
+            case '\'':
+                *newStringP++ = '&';
+                *newStringP++ = '#';
+                *newStringP++ = '3';
+                *newStringP++ = '9';
+                *newStringP++ = ';';
+                break;
+            case '"':
+                *newStringP++ = '&';
+                *newStringP++ = 'q';
+                *newStringP++ = 'u';
+                *newStringP++ = 'o';
+                *newStringP++ = 't';
+                *newStringP++ = ';';
+                break;
+            default:
+                *newStringP++ = c;
+                break;
+        }
     }
     /* Don't forget to null-terminate the target string */
     *newStringP = '\0';
@@ -305,8 +308,8 @@
     int  origLength;
 
     if( objc != 2) {
-	Tcl_WrongNumArgs( interp, 1, objv, "string" );
-	return TCL_ERROR;
+        Tcl_WrongNumArgs( interp, 1, objv, "string" );
+        return TCL_ERROR;
     }
 
     origString = Tcl_GetStringFromObj( objv[1], &origLength );
@@ -315,19 +318,19 @@
 
     /* for all the characters in the source string */
     for (origStringP = origString, newStringP = newString;
-	*origStringP != '\0';
-	origStringP++) {
-	char c = *origStringP;
+	                                 *origStringP != '\0';
+	                                 origStringP++) {
+        char c = *origStringP;
 
-	/* if the character is a shell metacharacter, quote it */
-	for (checkP = "&;`'|*?-~<>^()[]{}$\\"; *checkP != '\0'; checkP++) {
-	    if (c == *checkP) {
-		*newStringP++ = '\\';
-		break;
-	    }
-	}
+        /* if the character is a shell metacharacter, quote it */
+        for (checkP = "&;`'|*?-~<>^()[]{}$\\"; *checkP != '\0'; checkP++) {
+            if (c == *checkP) {
+                *newStringP++ = '\\';
+                break;
+            }
+        }
 
-	*newStringP++ = c;
+        *newStringP++ = c;
     }
     /* Don't forget to null-terminate the target string */
     *newStringP = '\0';
@@ -347,33 +350,13 @@
  *   in safe interpreters, as they process strings only.
  *-----------------------------------------------------------------------------
  */
-int
-Rivet_InitWWW( interp )
-    Tcl_Interp *interp;
+
+int 
+Rivet_InitWWW( Tcl_Interp *interp)
 {
-    Tcl_CreateObjCommand(interp,
-			"unescape_string",
-			Rivet_UnescapeStringCmd,
-			NULL,
-			(Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-			"escape_string",
-			Rivet_EscapeStringCmd,
-			NULL,
-			(Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-			"escape_sgml_chars",
-			Rivet_EscapeSgmlCharsCmd,
-			NULL,
-			(Tcl_CmdDeleteProc *)NULL);
-
-    Tcl_CreateObjCommand(interp,
-			"escape_shell_command",
-			Rivet_EscapeShellCommandCmd,
-			NULL,
-			(Tcl_CmdDeleteProc *)NULL);
-
+    RIVET_OBJ_CMD ("unescape_string",Rivet_UnescapeStringCmd);
+    RIVET_OBJ_CMD ("escape_string",Rivet_EscapeStringCmd);
+    RIVET_OBJ_CMD ("escape_sgml_chars",Rivet_EscapeSgmlCharsCmd);
+    RIVET_OBJ_CMD ("escape_shell_command",Rivet_EscapeShellCommandCmd);
     return TCL_OK;
 }
diff --git a/tclconfig/config.guess b/tclconfig/config.guess
index c2246a4..0e30d56 100755
--- a/tclconfig/config.guess
+++ b/tclconfig/config.guess
@@ -1,10 +1,9 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-#   Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
-timestamp='2009-12-30'
+timestamp='2003-07-02'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -18,25 +17,23 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
-# 02110-1301, USA.
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
-
-# Originally written by Per Bothner.  Please send patches (context
-# diff format) to <config-patches@gnu.org> and include a ChangeLog
-# entry.
+# Originally written by Per Bothner <per@bothner.com>.
+# Please send patches to <config-patches@gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
 #
 # This script attempts to guess a canonical system name similar to
 # config.sub.  If it succeeds, it prints the system name on stdout, and
 # exits with 0.  Otherwise, it exits with 1.
 #
-# You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit build system type.
 
 me=`echo "$0" | sed -e 's,.*/,,'`
 
@@ -56,9 +53,8 @@
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
-Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -70,11 +66,11 @@
 while test $# -gt 0 ; do
   case $1 in
     --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit ;;
+       echo "$timestamp" ; exit 0 ;;
     --version | -v )
-       echo "$version" ; exit ;;
+       echo "$version" ; exit 0 ;;
     --help | --h* | -h )
-       echo "$usage"; exit ;;
+       echo "$usage"; exit 0 ;;
     -- )     # Stop option processing
        shift; break ;;
     - )	# Use stdin as input.
@@ -108,7 +104,7 @@
 trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
 trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
 : ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
  { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
  { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
  { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
@@ -127,7 +123,7 @@
 	;;
  ,,*)   CC_FOR_BUILD=$CC ;;
  ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
-esac ; set_cc_for_build= ;'
+esac ;'
 
 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
 # (ghazi@noc.rutgers.edu 1994-08-24)
@@ -162,7 +158,6 @@
 	    arm*) machine=arm-unknown ;;
 	    sh3el) machine=shl-unknown ;;
 	    sh3eb) machine=sh-unknown ;;
-	    sh5el) machine=sh5le-unknown ;;
 	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
 	esac
 	# The Operating System including object format, if it has switched
@@ -171,7 +166,7 @@
 	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
 		eval $set_cc_for_build
 		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
-			| grep -q __ELF__
+			| grep __ELF__ >/dev/null
 		then
 		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
 		    # Return netbsd for either.  FIX?
@@ -201,32 +196,50 @@
 	# contains redundant information, the shorter form:
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
 	echo "${machine}-${os}${release}"
-	exit ;;
+	exit 0 ;;
+    amiga:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    arc:OpenBSD:*:*)
+	echo mipsel-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    hp300:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mac68k:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    macppc:OpenBSD:*:*)
+	echo powerpc-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mvme68k:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mvme88k:OpenBSD:*:*)
+	echo m88k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    mvmeppc:OpenBSD:*:*)
+	echo powerpc-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    pmax:OpenBSD:*:*)
+	echo mipsel-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    sgi:OpenBSD:*:*)
+	echo mipseb-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    sun3:OpenBSD:*:*)
+	echo m68k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
+    wgrisc:OpenBSD:*:*)
+	echo mipsel-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
     *:OpenBSD:*:*)
-	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
-	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
-	exit ;;
-    *:ekkoBSD:*:*)
-	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
-	exit ;;
-    *:SolidBSD:*:*)
-	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
-	exit ;;
-    macppc:MirBSD:*:*)
-	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
-	exit ;;
-    *:MirBSD:*:*)
-	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
-	exit ;;
+	echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
     alpha:OSF1:*:*)
-	case $UNAME_RELEASE in
-	*4.0)
+	if test $UNAME_RELEASE = "V4.0"; then
 		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
-		;;
-	*5.*)
-	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
-		;;
-	esac
+	fi
 	# According to Compaq, /usr/sbin/psrinfo has been available on
 	# OSF/1 and Tru64 systems produced since 1995.  I hope that
 	# covers most systems running today.  This code pipes the CPU
@@ -264,49 +277,42 @@
 	    "EV7.9 (21364A)")
 		UNAME_MACHINE="alphaev79" ;;
 	esac
-	# A Pn.n version is a patched version.
 	# A Vn.n version is a released version.
 	# A Tn.n version is a released field test version.
 	# A Xn.n version is an unreleased experimental baselevel.
 	# 1.2 uses "1.2" for uname -r.
-	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-	exit ;;
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	exit 0 ;;
+    Alpha*:OpenVMS:*:*)
+	echo alpha-hp-vms
+	exit 0 ;;
     Alpha\ *:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# Should we change UNAME_MACHINE based on the output of uname instead
 	# of the specific Alpha model?
 	echo alpha-pc-interix
-	exit ;;
+	exit 0 ;;
     21064:Windows_NT:50:3)
 	echo alpha-dec-winnt3.5
-	exit ;;
+	exit 0 ;;
     Amiga*:UNIX_System_V:4.0:*)
 	echo m68k-unknown-sysv4
-	exit ;;
+	exit 0;;
     *:[Aa]miga[Oo][Ss]:*:*)
 	echo ${UNAME_MACHINE}-unknown-amigaos
-	exit ;;
+	exit 0 ;;
     *:[Mm]orph[Oo][Ss]:*:*)
 	echo ${UNAME_MACHINE}-unknown-morphos
-	exit ;;
+	exit 0 ;;
     *:OS/390:*:*)
 	echo i370-ibm-openedition
-	exit ;;
-    *:z/VM:*:*)
-	echo s390-ibm-zvmoe
-	exit ;;
-    *:OS400:*:*)
-        echo powerpc-ibm-os400
-	exit ;;
+	exit 0 ;;
     arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
 	echo arm-acorn-riscix${UNAME_RELEASE}
-	exit ;;
-    arm:riscos:*:*|arm:RISCOS:*:*)
-	echo arm-unknown-riscos
-	exit ;;
+	exit 0;;
     SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
 	echo hppa1.1-hitachi-hiuxmpp
-	exit ;;
+	exit 0;;
     Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
 	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
 	if test "`(/bin/universe) 2>/dev/null`" = att ; then
@@ -314,51 +320,32 @@
 	else
 		echo pyramid-pyramid-bsd
 	fi
-	exit ;;
+	exit 0 ;;
     NILE*:*:*:dcosx)
 	echo pyramid-pyramid-svr4
-	exit ;;
+	exit 0 ;;
     DRS?6000:unix:4.0:6*)
 	echo sparc-icl-nx6
-	exit ;;
-    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+	exit 0 ;;
+    DRS?6000:UNIX_SV:4.2*:7*)
 	case `/usr/bin/uname -p` in
-	    sparc) echo sparc-icl-nx7; exit ;;
+	    sparc) echo sparc-icl-nx7 && exit 0 ;;
 	esac ;;
-    s390x:SunOS:*:*)
-	echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit ;;
     sun4H:SunOS:5.*:*)
 	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit ;;
+	exit 0 ;;
     sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
 	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit ;;
-    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
-	echo i386-pc-auroraux${UNAME_RELEASE}
-	exit ;;
-    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
-	eval $set_cc_for_build
-	SUN_ARCH="i386"
-	# If there is a compiler, see if it is configured for 64-bit objects.
-	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
-	# This test works for both compilers.
-	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
-	    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
-		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
-		grep IS_64BIT_ARCH >/dev/null
-	    then
-		SUN_ARCH="x86_64"
-	    fi
-	fi
-	echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit ;;
+	exit 0 ;;
+    i86pc:SunOS:5.*:*)
+	echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit 0 ;;
     sun4*:SunOS:6*:*)
 	# According to config.sub, this is the proper way to canonicalize
 	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
 	# it's likely to be more like Solaris than SunOS4.
 	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit ;;
+	exit 0 ;;
     sun4*:SunOS:*:*)
 	case "`/usr/bin/arch -k`" in
 	    Series*|S4*)
@@ -367,10 +354,10 @@
 	esac
 	# Japanese Language versions have a version number like `4.1.3-JL'.
 	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
-	exit ;;
+	exit 0 ;;
     sun3*:SunOS:*:*)
 	echo m68k-sun-sunos${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     sun*:*:4.2BSD:*)
 	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
 	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
@@ -382,10 +369,10 @@
 		echo sparc-sun-sunos${UNAME_RELEASE}
 		;;
 	esac
-	exit ;;
+	exit 0 ;;
     aushp:SunOS:*:*)
 	echo sparc-auspex-sunos${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     # The situation for MiNT is a little confusing.  The machine name
     # can be virtually everything (everything which is not
     # "atarist" or "atariste" at least should have a processor
@@ -396,40 +383,37 @@
     # be no problem.
     atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
         echo m68k-atari-mint${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
 	echo m68k-atari-mint${UNAME_RELEASE}
-        exit ;;
+        exit 0 ;;
     *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
         echo m68k-atari-mint${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
         echo m68k-milan-mint${UNAME_RELEASE}
-        exit ;;
+        exit 0 ;;
     hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
         echo m68k-hades-mint${UNAME_RELEASE}
-        exit ;;
+        exit 0 ;;
     *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
         echo m68k-unknown-mint${UNAME_RELEASE}
-        exit ;;
-    m68k:machten:*:*)
-	echo m68k-apple-machten${UNAME_RELEASE}
-	exit ;;
+        exit 0 ;;
     powerpc:machten:*:*)
 	echo powerpc-apple-machten${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     RISC*:Mach:*:*)
 	echo mips-dec-mach_bsd4.3
-	exit ;;
+	exit 0 ;;
     RISC*:ULTRIX:*:*)
 	echo mips-dec-ultrix${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     VAX*:ULTRIX*:*:*)
 	echo vax-dec-ultrix${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     2020:CLIX:*:* | 2430:CLIX:*:*)
 	echo clipper-intergraph-clix${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     mips:*:*:UMIPS | mips:*:*:RISCos)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -453,33 +437,32 @@
 	  exit (-1);
 	}
 EOF
-	$CC_FOR_BUILD -o $dummy $dummy.c &&
-	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
-	  SYSTEM_NAME=`$dummy $dummyarg` &&
-	    { echo "$SYSTEM_NAME"; exit; }
+	$CC_FOR_BUILD -o $dummy $dummy.c \
+	  && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
+	  && exit 0
 	echo mips-mips-riscos${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     Motorola:PowerMAX_OS:*:*)
 	echo powerpc-motorola-powermax
-	exit ;;
+	exit 0 ;;
     Motorola:*:4.3:PL8-*)
 	echo powerpc-harris-powermax
-	exit ;;
+	exit 0 ;;
     Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
 	echo powerpc-harris-powermax
-	exit ;;
+	exit 0 ;;
     Night_Hawk:Power_UNIX:*:*)
 	echo powerpc-harris-powerunix
-	exit ;;
+	exit 0 ;;
     m88k:CX/UX:7*:*)
 	echo m88k-harris-cxux7
-	exit ;;
+	exit 0 ;;
     m88k:*:4*:R4*)
 	echo m88k-motorola-sysv4
-	exit ;;
+	exit 0 ;;
     m88k:*:3*:R3*)
 	echo m88k-motorola-sysv3
-	exit ;;
+	exit 0 ;;
     AViiON:dgux:*:*)
         # DG/UX returns AViiON for all architectures
         UNAME_PROCESSOR=`/usr/bin/uname -p`
@@ -495,29 +478,29 @@
 	else
 	    echo i586-dg-dgux${UNAME_RELEASE}
 	fi
- 	exit ;;
+ 	exit 0 ;;
     M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
 	echo m88k-dolphin-sysv3
-	exit ;;
+	exit 0 ;;
     M88*:*:R3*:*)
 	# Delta 88k system running SVR3
 	echo m88k-motorola-sysv3
-	exit ;;
+	exit 0 ;;
     XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
 	echo m88k-tektronix-sysv3
-	exit ;;
+	exit 0 ;;
     Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
 	echo m68k-tektronix-bsd
-	exit ;;
+	exit 0 ;;
     *:IRIX*:*:*)
 	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
-	exit ;;
+	exit 0 ;;
     ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
-	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
-	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
+	echo romp-ibm-aix      # uname -m gives an 8 hex-code CPU id
+	exit 0 ;;              # Note that: echo "'`uname -s`'" gives 'AIX '
     i*86:AIX:*:*)
 	echo i386-ibm-aix
-	exit ;;
+	exit 0 ;;
     ia64:AIX:*:*)
 	if [ -x /usr/bin/oslevel ] ; then
 		IBM_REV=`/usr/bin/oslevel`
@@ -525,7 +508,7 @@
 		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
 	fi
 	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
-	exit ;;
+	exit 0 ;;
     *:AIX:2:3)
 	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
 		eval $set_cc_for_build
@@ -540,19 +523,15 @@
 			exit(0);
 			}
 EOF
-		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
-		then
-			echo "$SYSTEM_NAME"
-		else
-			echo rs6000-ibm-aix3.2.5
-		fi
+		$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
+		echo rs6000-ibm-aix3.2.5
 	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
 		echo rs6000-ibm-aix3.2.4
 	else
 		echo rs6000-ibm-aix3.2
 	fi
-	exit ;;
-    *:AIX:*:[456])
+	exit 0 ;;
+    *:AIX:*:[45])
 	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
 	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
 		IBM_ARCH=rs6000
@@ -565,28 +544,28 @@
 		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
 	fi
 	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
-	exit ;;
+	exit 0 ;;
     *:AIX:*:*)
 	echo rs6000-ibm-aix
-	exit ;;
+	exit 0 ;;
     ibmrt:4.4BSD:*|romp-ibm:BSD:*)
 	echo romp-ibm-bsd4.4
-	exit ;;
+	exit 0 ;;
     ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
 	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
-	exit ;;                             # report: romp-ibm BSD 4.3
+	exit 0 ;;                           # report: romp-ibm BSD 4.3
     *:BOSX:*:*)
 	echo rs6000-bull-bosx
-	exit ;;
+	exit 0 ;;
     DPX/2?00:B.O.S.:*:*)
 	echo m68k-bull-sysv3
-	exit ;;
+	exit 0 ;;
     9000/[34]??:4.3bsd:1.*:*)
 	echo m68k-hp-bsd
-	exit ;;
+	exit 0 ;;
     hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
 	echo m68k-hp-bsd4.4
-	exit ;;
+	exit 0 ;;
     9000/[34678]??:HP-UX:*:*)
 	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
 	case "${UNAME_MACHINE}" in
@@ -648,19 +627,9 @@
 	esac
 	if [ ${HP_ARCH} = "hppa2.0w" ]
 	then
-	    eval $set_cc_for_build
-
-	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
-	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
-	    # generating 64-bit code.  GNU and HP use different nomenclature:
-	    #
-	    # $ CC_FOR_BUILD=cc ./config.guess
-	    # => hppa2.0w-hp-hpux11.23
-	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
-	    # => hppa64-hp-hpux11.23
-
-	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
-		grep -q __LP64__
+	    # avoid double evaluation of $set_cc_for_build
+	    test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
 	    then
 		HP_ARCH="hppa2.0w"
 	    else
@@ -668,11 +637,11 @@
 	    fi
 	fi
 	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
-	exit ;;
+	exit 0 ;;
     ia64:HP-UX:*:*)
 	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
 	echo ia64-hp-hpux${HPUX_REV}
-	exit ;;
+	exit 0 ;;
     3050*:HI-UX:*:*)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -700,164 +669,197 @@
 	  exit (0);
 	}
 EOF
-	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
-		{ echo "$SYSTEM_NAME"; exit; }
+	$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
 	echo unknown-hitachi-hiuxwe2
-	exit ;;
+	exit 0 ;;
     9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
 	echo hppa1.1-hp-bsd
-	exit ;;
+	exit 0 ;;
     9000/8??:4.3bsd:*:*)
 	echo hppa1.0-hp-bsd
-	exit ;;
+	exit 0 ;;
     *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
 	echo hppa1.0-hp-mpeix
-	exit ;;
+	exit 0 ;;
     hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
 	echo hppa1.1-hp-osf
-	exit ;;
+	exit 0 ;;
     hp8??:OSF1:*:*)
 	echo hppa1.0-hp-osf
-	exit ;;
+	exit 0 ;;
     i*86:OSF1:*:*)
 	if [ -x /usr/sbin/sysversion ] ; then
 	    echo ${UNAME_MACHINE}-unknown-osf1mk
 	else
 	    echo ${UNAME_MACHINE}-unknown-osf1
 	fi
-	exit ;;
+	exit 0 ;;
     parisc*:Lites*:*:*)
 	echo hppa1.1-hp-lites
-	exit ;;
+	exit 0 ;;
     C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
 	echo c1-convex-bsd
-        exit ;;
+        exit 0 ;;
     C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
 	if getsysinfo -f scalar_acc
 	then echo c32-convex-bsd
 	else echo c2-convex-bsd
 	fi
-        exit ;;
+        exit 0 ;;
     C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
 	echo c34-convex-bsd
-        exit ;;
+        exit 0 ;;
     C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
 	echo c38-convex-bsd
-        exit ;;
+        exit 0 ;;
     C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
 	echo c4-convex-bsd
-        exit ;;
+        exit 0 ;;
     CRAY*Y-MP:*:*:*)
 	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit ;;
+	exit 0 ;;
     CRAY*[A-Z]90:*:*:*)
 	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
 	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
 	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
 	      -e 's/\.[^.]*$/.X/'
-	exit ;;
+	exit 0 ;;
     CRAY*TS:*:*:*)
 	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit ;;
+	exit 0 ;;
     CRAY*T3E:*:*:*)
 	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit ;;
+	exit 0 ;;
     CRAY*SV1:*:*:*)
 	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit ;;
+	exit 0 ;;
     *:UNICOS/mp:*:*)
-	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit ;;
+	echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 
+	exit 0 ;;
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
 	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
         FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
         FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
         echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-        exit ;;
-    5000:UNIX_System_V:4.*:*)
-        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
-        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
-        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-	exit ;;
+        exit 0 ;;
     i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
 	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     sparc*:BSD/OS:*:*)
 	echo sparc-unknown-bsdi${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     *:BSD/OS:*:*)
 	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
-	exit ;;
-    *:FreeBSD:*:*)
-	case ${UNAME_MACHINE} in
-	    pc98)
-		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
-	    amd64)
-		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
-	    *)
-		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
-	esac
-	exit ;;
+	exit 0 ;;
+    *:FreeBSD:*:*|*:GNU/FreeBSD:*:*)
+	# Determine whether the default compiler uses glibc.
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <features.h>
+	#if __GLIBC__ >= 2
+	LIBC=gnu
+	#else
+	LIBC=
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
+	# GNU/FreeBSD systems have a "k" prefix to indicate we are using
+	# FreeBSD's kernel, but not the complete OS.
+	case ${LIBC} in gnu) kernel_only='k' ;; esac
+	echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
+	exit 0 ;;
     i*:CYGWIN*:*)
 	echo ${UNAME_MACHINE}-pc-cygwin
-	exit ;;
-    *:MINGW*:*)
+	exit 0 ;;
+    i*:MINGW*:*)
 	echo ${UNAME_MACHINE}-pc-mingw32
-	exit ;;
-    i*:windows32*:*)
-    	# uname -m includes "-pc" on this system.
-    	echo ${UNAME_MACHINE}-mingw32
-	exit ;;
+	exit 0 ;;
     i*:PW*:*)
 	echo ${UNAME_MACHINE}-pc-pw32
-	exit ;;
-    *:Interix*:*)
-    	case ${UNAME_MACHINE} in
-	    x86)
-		echo i586-pc-interix${UNAME_RELEASE}
-		exit ;;
-	    authenticamd | genuineintel | EM64T)
-		echo x86_64-unknown-interix${UNAME_RELEASE}
-		exit ;;
-	    IA64)
-		echo ia64-unknown-interix${UNAME_RELEASE}
-		exit ;;
-	esac ;;
+	exit 0 ;;
+    x86:Interix*:[34]*)
+	echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
+	exit 0 ;;
     [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
 	echo i${UNAME_MACHINE}-pc-mks
-	exit ;;
-    8664:Windows_NT:*)
-	echo x86_64-pc-mks
-	exit ;;
+	exit 0 ;;
     i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
 	# UNAME_MACHINE based on the output of uname instead of i386?
 	echo i586-pc-interix
-	exit ;;
+	exit 0 ;;
     i*:UWIN*:*)
 	echo ${UNAME_MACHINE}-pc-uwin
-	exit ;;
-    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
-	echo x86_64-unknown-cygwin
-	exit ;;
+	exit 0 ;;
     p*:CYGWIN*:*)
 	echo powerpcle-unknown-cygwin
-	exit ;;
+	exit 0 ;;
     prep*:SunOS:5.*:*)
 	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit ;;
+	exit 0 ;;
     *:GNU:*:*)
-	# the GNU system
 	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
-	exit ;;
-    *:GNU/*:*:*)
-	# other systems with GNU libc and userland
-	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
-	exit ;;
+	exit 0 ;;
     i*86:Minix:*:*)
 	echo ${UNAME_MACHINE}-pc-minix
-	exit ;;
+	exit 0 ;;
+    arm*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    cris:Linux:*:*)
+	echo cris-axis-linux-gnu
+	exit 0 ;;
+    ia64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    m68*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
+    mips:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips
+	#undef mipsel
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mipsel
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
+	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	;;
+    mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips64
+	#undef mips64el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mips64el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips64
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
+	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	;;
+    ppc:Linux:*:*)
+	echo powerpc-unknown-linux-gnu
+	exit 0 ;;
+    ppc64:Linux:*:*)
+	echo powerpc64-unknown-linux-gnu
+	exit 0 ;;
     alpha:Linux:*:*)
 	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
 	  EV5)   UNAME_MACHINE=alphaev5 ;;
@@ -868,80 +870,10 @@
 	  EV67)  UNAME_MACHINE=alphaev67 ;;
 	  EV68*) UNAME_MACHINE=alphaev68 ;;
         esac
-	objdump --private-headers /bin/sh | grep -q ld.so.1
+	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
 	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
 	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
-	exit ;;
-    arm*:Linux:*:*)
-	eval $set_cc_for_build
-	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
-	    | grep -q __ARM_EABI__
-	then
-	    echo ${UNAME_MACHINE}-unknown-linux-gnu
-	else
-	    echo ${UNAME_MACHINE}-unknown-linux-gnueabi
-	fi
-	exit ;;
-    avr32*:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
-    cris:Linux:*:*)
-	echo cris-axis-linux-gnu
-	exit ;;
-    crisv32:Linux:*:*)
-	echo crisv32-axis-linux-gnu
-	exit ;;
-    frv:Linux:*:*)
-    	echo frv-unknown-linux-gnu
-	exit ;;
-    i*86:Linux:*:*)
-	LIBC=gnu
-	eval $set_cc_for_build
-	sed 's/^	//' << EOF >$dummy.c
-	#ifdef __dietlibc__
-	LIBC=dietlibc
-	#endif
-EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
-	echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
-	exit ;;
-    ia64:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
-    m32r*:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
-    m68*:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
-    mips:Linux:*:* | mips64:Linux:*:*)
-	eval $set_cc_for_build
-	sed 's/^	//' << EOF >$dummy.c
-	#undef CPU
-	#undef ${UNAME_MACHINE}
-	#undef ${UNAME_MACHINE}el
-	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
-	CPU=${UNAME_MACHINE}el
-	#else
-	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
-	CPU=${UNAME_MACHINE}
-	#else
-	CPU=
-	#endif
-	#endif
-EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
-	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
-	;;
-    or32:Linux:*:*)
-	echo or32-unknown-linux-gnu
-	exit ;;
-    padre:Linux:*:*)
-	echo sparc-unknown-linux-gnu
-	exit ;;
-    parisc64:Linux:*:* | hppa64:Linux:*:*)
-	echo hppa64-unknown-linux-gnu
-	exit ;;
+	exit 0 ;;
     parisc:Linux:*:* | hppa:Linux:*:*)
 	# Look for CPU level
 	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
@@ -949,40 +881,84 @@
 	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
 	  *)    echo hppa-unknown-linux-gnu ;;
 	esac
-	exit ;;
-    ppc64:Linux:*:*)
-	echo powerpc64-unknown-linux-gnu
-	exit ;;
-    ppc:Linux:*:*)
-	echo powerpc-unknown-linux-gnu
-	exit ;;
+	exit 0 ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+	echo hppa64-unknown-linux-gnu
+	exit 0 ;;
     s390:Linux:*:* | s390x:Linux:*:*)
 	echo ${UNAME_MACHINE}-ibm-linux
-	exit ;;
+	exit 0 ;;
     sh64*:Linux:*:*)
     	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
+	exit 0 ;;
     sh*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
+	exit 0 ;;
     sparc:Linux:*:* | sparc64:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
-    vax:Linux:*:*)
-	echo ${UNAME_MACHINE}-dec-linux-gnu
-	exit ;;
+	exit 0 ;;
     x86_64:Linux:*:*)
 	echo x86_64-unknown-linux-gnu
-	exit ;;
-    xtensa*:Linux:*:*)
-    	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit ;;
+	exit 0 ;;
+    i*86:Linux:*:*)
+	# The BFD linker knows what the default object file format is, so
+	# first see if it will tell us. cd to the root directory to prevent
+	# problems with other programs or directories called `ld' in the path.
+	# Set LC_ALL=C to ensure ld outputs messages in English.
+	ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
+			 | sed -ne '/supported targets:/!d
+				    s/[ 	][ 	]*/ /g
+				    s/.*supported targets: *//
+				    s/ .*//
+				    p'`
+        case "$ld_supported_targets" in
+	  elf32-i386)
+		TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
+		;;
+	  a.out-i386-linux)
+		echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+		exit 0 ;;
+	  coff-i386)
+		echo "${UNAME_MACHINE}-pc-linux-gnucoff"
+		exit 0 ;;
+	  "")
+		# Either a pre-BFD a.out linker (linux-gnuoldld) or
+		# one that does not give us useful --help.
+		echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
+		exit 0 ;;
+	esac
+	# Determine whether the default compiler is a.out or elf
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <features.h>
+	#ifdef __ELF__
+	# ifdef __GLIBC__
+	#  if __GLIBC__ >= 2
+	LIBC=gnu
+	#  else
+	LIBC=gnulibc1
+	#  endif
+	# else
+	LIBC=gnulibc1
+	# endif
+	#else
+	#ifdef __INTEL_COMPILER
+	LIBC=gnu
+	#else
+	LIBC=gnuaout
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
+	test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
+	test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
+	;;
     i*86:DYNIX/ptx:4*:*)
 	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
 	# earlier versions are messed up and put the nodename in both
 	# sysname and nodename.
 	echo i386-sequent-sysv4
-	exit ;;
+	exit 0 ;;
     i*86:UNIX_SV:4.2MP:2.*)
         # Unixware is an offshoot of SVR4, but it has its own version
         # number series starting with 2...
@@ -990,27 +966,24 @@
 	# I just have to hope.  -- rms.
         # Use sysv4.2uw... so that sysv4* matches it.
 	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
-	exit ;;
+	exit 0 ;;
     i*86:OS/2:*:*)
 	# If we were able to find `uname', then EMX Unix compatibility
 	# is probably installed.
 	echo ${UNAME_MACHINE}-pc-os2-emx
-	exit ;;
+	exit 0 ;;
     i*86:XTS-300:*:STOP)
 	echo ${UNAME_MACHINE}-unknown-stop
-	exit ;;
+	exit 0 ;;
     i*86:atheos:*:*)
 	echo ${UNAME_MACHINE}-unknown-atheos
-	exit ;;
-    i*86:syllable:*:*)
-	echo ${UNAME_MACHINE}-pc-syllable
-	exit ;;
-    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
+	exit 0 ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
 	echo i386-unknown-lynxos${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     i*86:*DOS:*:*)
 	echo ${UNAME_MACHINE}-pc-msdosdjgpp
-	exit ;;
+	exit 0 ;;
     i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
 	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
 	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
@@ -1018,16 +991,15 @@
 	else
 		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
 	fi
-	exit ;;
-    i*86:*:5:[678]*)
-    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
+	exit 0 ;;
+    i*86:*:5:[78]*)
 	case `/bin/uname -X | grep "^Machine"` in
 	    *486*)	     UNAME_MACHINE=i486 ;;
 	    *Pentium)	     UNAME_MACHINE=i586 ;;
 	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
 	esac
 	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
-	exit ;;
+	exit 0 ;;
     i*86:*:3.2:*)
 	if test -f /usr/options/cb.name; then
 		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
@@ -1045,86 +1017,73 @@
 	else
 		echo ${UNAME_MACHINE}-pc-sysv32
 	fi
-	exit ;;
+	exit 0 ;;
     pc:*:*:*)
 	# Left here for compatibility:
         # uname -m prints for DJGPP always 'pc', but it prints nothing about
-        # the processor, so we play safe by assuming i586.
-	# Note: whatever this is, it MUST be the same as what config.sub
-	# prints for the "djgpp" host, or else GDB configury will decide that
-	# this is a cross-build.
-	echo i586-pc-msdosdjgpp
-        exit ;;
+        # the processor, so we play safe by assuming i386.
+	echo i386-pc-msdosdjgpp
+        exit 0 ;;
     Intel:Mach:3*:*)
 	echo i386-pc-mach3
-	exit ;;
+	exit 0 ;;
     paragon:*:*:*)
 	echo i860-intel-osf1
-	exit ;;
+	exit 0 ;;
     i860:*:4.*:*) # i860-SVR4
 	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
 	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
 	else # Add other i860-SVR4 vendors below as they are discovered.
 	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
 	fi
-	exit ;;
+	exit 0 ;;
     mini*:CTIX:SYS*5:*)
 	# "miniframe"
 	echo m68010-convergent-sysv
-	exit ;;
+	exit 0 ;;
     mc68k:UNIX:SYSTEM5:3.51m)
 	echo m68k-convergent-sysv
-	exit ;;
+	exit 0 ;;
     M680?0:D-NIX:5.3:*)
 	echo m68k-diab-dnix
-	exit ;;
-    M68*:*:R3V[5678]*:*)
-	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
-    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+	exit 0 ;;
+    M68*:*:R3V[567]*:*)
+	test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
+    3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
 	OS_REL=''
 	test -r /etc/.relid \
 	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
 	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	  && echo i486-ncr-sysv4.3${OS_REL} && exit 0
 	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
-	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+	  && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
     3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
         /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-          && { echo i486-ncr-sysv4; exit; } ;;
-    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
-	OS_REL='.3'
-	test -r /etc/.relid \
-	    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
-	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-	    && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
-	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
-	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
-	/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
-	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+          && echo i486-ncr-sysv4 && exit 0 ;;
     m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
 	echo m68k-unknown-lynxos${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     mc68030:UNIX_System_V:4.*:*)
 	echo m68k-atari-sysv4
-	exit ;;
+	exit 0 ;;
     TSUNAMI:LynxOS:2.*:*)
 	echo sparc-unknown-lynxos${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     rs6000:LynxOS:2.*:*)
 	echo rs6000-unknown-lynxos${UNAME_RELEASE}
-	exit ;;
-    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
+	exit 0 ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
 	echo powerpc-unknown-lynxos${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     SM[BE]S:UNIX_SV:*:*)
 	echo mips-dde-sysv${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     RM*:ReliantUNIX-*:*:*)
 	echo mips-sni-sysv4
-	exit ;;
+	exit 0 ;;
     RM*:SINIX-*:*:*)
 	echo mips-sni-sysv4
-	exit ;;
+	exit 0 ;;
     *:SINIX-*:*:*)
 	if uname -p 2>/dev/null >/dev/null ; then
 		UNAME_MACHINE=`(uname -p) 2>/dev/null`
@@ -1132,94 +1091,68 @@
 	else
 		echo ns32k-sni-sysv
 	fi
-	exit ;;
+	exit 0 ;;
     PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
                       # says <Richard.M.Bartel@ccMail.Census.GOV>
         echo i586-unisys-sysv4
-        exit ;;
+        exit 0 ;;
     *:UNIX_System_V:4*:FTX*)
 	# From Gerald Hewes <hewes@openmarket.com>.
 	# How about differentiating between stratus architectures? -djm
 	echo hppa1.1-stratus-sysv4
-	exit ;;
+	exit 0 ;;
     *:*:*:FTX*)
 	# From seanf@swdc.stratus.com.
 	echo i860-stratus-sysv4
-	exit ;;
-    i*86:VOS:*:*)
-	# From Paul.Green@stratus.com.
-	echo ${UNAME_MACHINE}-stratus-vos
-	exit ;;
+	exit 0 ;;
     *:VOS:*:*)
 	# From Paul.Green@stratus.com.
 	echo hppa1.1-stratus-vos
-	exit ;;
+	exit 0 ;;
     mc68*:A/UX:*:*)
 	echo m68k-apple-aux${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     news*:NEWS-OS:6*:*)
 	echo mips-sony-newsos6
-	exit ;;
+	exit 0 ;;
     R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
 	if [ -d /usr/nec ]; then
 	        echo mips-nec-sysv${UNAME_RELEASE}
 	else
 	        echo mips-unknown-sysv${UNAME_RELEASE}
 	fi
-        exit ;;
+        exit 0 ;;
     BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
 	echo powerpc-be-beos
-	exit ;;
+	exit 0 ;;
     BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
 	echo powerpc-apple-beos
-	exit ;;
+	exit 0 ;;
     BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
 	echo i586-pc-beos
-	exit ;;
-    BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
-	echo i586-pc-haiku
-	exit ;;
+	exit 0 ;;
     SX-4:SUPER-UX:*:*)
 	echo sx4-nec-superux${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     SX-5:SUPER-UX:*:*)
 	echo sx5-nec-superux${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     SX-6:SUPER-UX:*:*)
 	echo sx6-nec-superux${UNAME_RELEASE}
-	exit ;;
-    SX-7:SUPER-UX:*:*)
-	echo sx7-nec-superux${UNAME_RELEASE}
-	exit ;;
-    SX-8:SUPER-UX:*:*)
-	echo sx8-nec-superux${UNAME_RELEASE}
-	exit ;;
-    SX-8R:SUPER-UX:*:*)
-	echo sx8r-nec-superux${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     Power*:Rhapsody:*:*)
 	echo powerpc-apple-rhapsody${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     *:Rhapsody:*:*)
 	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     *:Darwin:*:*)
-	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
-	case $UNAME_PROCESSOR in
-	    i386)
-		eval $set_cc_for_build
-		if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
-		  if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
-		      (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
-		      grep IS_64BIT_ARCH >/dev/null
-		  then
-		      UNAME_PROCESSOR="x86_64"
-		  fi
-		fi ;;
-	    unknown) UNAME_PROCESSOR=powerpc ;;
+	case `uname -p` in
+	    *86) UNAME_PROCESSOR=i686 ;;
+	    powerpc) UNAME_PROCESSOR=powerpc ;;
 	esac
 	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
 	UNAME_PROCESSOR=`uname -p`
 	if test "$UNAME_PROCESSOR" = "x86"; then
@@ -1227,25 +1160,22 @@
 		UNAME_MACHINE=pc
 	fi
 	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     *:QNX:*:4*)
 	echo i386-pc-qnx
-	exit ;;
-    NSE-?:NONSTOP_KERNEL:*:*)
-	echo nse-tandem-nsk${UNAME_RELEASE}
-	exit ;;
-    NSR-?:NONSTOP_KERNEL:*:*)
+	exit 0 ;;
+    NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*)
 	echo nsr-tandem-nsk${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     *:NonStop-UX:*:*)
 	echo mips-compaq-nonstopux
-	exit ;;
+	exit 0 ;;
     BS2000:POSIX*:*:*)
 	echo bs2000-siemens-sysv
-	exit ;;
+	exit 0 ;;
     DS/*:UNIX_System_V:*:*)
 	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
-	exit ;;
+	exit 0 ;;
     *:Plan9:*:*)
 	# "uname -m" is not consistent, so use $cputype instead. 386
 	# is converted to i386 for consistency with other x86
@@ -1256,50 +1186,28 @@
 	    UNAME_MACHINE="$cputype"
 	fi
 	echo ${UNAME_MACHINE}-unknown-plan9
-	exit ;;
+	exit 0 ;;
     *:TOPS-10:*:*)
 	echo pdp10-unknown-tops10
-	exit ;;
+	exit 0 ;;
     *:TENEX:*:*)
 	echo pdp10-unknown-tenex
-	exit ;;
+	exit 0 ;;
     KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
 	echo pdp10-dec-tops20
-	exit ;;
+	exit 0 ;;
     XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
 	echo pdp10-xkl-tops20
-	exit ;;
+	exit 0 ;;
     *:TOPS-20:*:*)
 	echo pdp10-unknown-tops20
-	exit ;;
+	exit 0 ;;
     *:ITS:*:*)
 	echo pdp10-unknown-its
-	exit ;;
+	exit 0 ;;
     SEI:*:*:SEIUX)
         echo mips-sei-seiux${UNAME_RELEASE}
-	exit ;;
-    *:DragonFly:*:*)
-	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
-	exit ;;
-    *:*VMS:*:*)
-    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
-	case "${UNAME_MACHINE}" in
-	    A*) echo alpha-dec-vms ; exit ;;
-	    I*) echo ia64-dec-vms ; exit ;;
-	    V*) echo vax-dec-vms ; exit ;;
-	esac ;;
-    *:XENIX:*:SysV)
-	echo i386-pc-xenix
-	exit ;;
-    i*86:skyos:*:*)
-	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
-	exit ;;
-    i*86:rdos:*:*)
-	echo ${UNAME_MACHINE}-pc-rdos
-	exit ;;
-    i*86:AROS:*:*)
-	echo ${UNAME_MACHINE}-pc-aros
-	exit ;;
+	exit 0 ;;
 esac
 
 #echo '(No uname command or uname output not recognized.)' 1>&2
@@ -1331,7 +1239,7 @@
 #endif
 
 #if defined (__arm) && defined (__acorn) && defined (__unix)
-  printf ("arm-acorn-riscix\n"); exit (0);
+  printf ("arm-acorn-riscix"); exit (0);
 #endif
 
 #if defined (hp300) && !defined (hpux)
@@ -1420,12 +1328,11 @@
 }
 EOF
 
-$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
-	{ echo "$SYSTEM_NAME"; exit; }
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
 
 # Apollos put the system type in the environment.
 
-test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
 
 # Convex versions that predate uname can use getsysinfo(1)
 
@@ -1434,22 +1341,22 @@
     case `getsysinfo -f cpu_type` in
     c1*)
 	echo c1-convex-bsd
-	exit ;;
+	exit 0 ;;
     c2*)
 	if getsysinfo -f scalar_acc
 	then echo c32-convex-bsd
 	else echo c2-convex-bsd
 	fi
-	exit ;;
+	exit 0 ;;
     c34*)
 	echo c34-convex-bsd
-	exit ;;
+	exit 0 ;;
     c38*)
 	echo c38-convex-bsd
-	exit ;;
+	exit 0 ;;
     c4*)
 	echo c4-convex-bsd
-	exit ;;
+	exit 0 ;;
     esac
 fi
 
@@ -1460,9 +1367,7 @@
 the operating system you are using. It is advised that you
 download the most up to date version of the config scripts from
 
-  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
-and
-  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+    ftp://ftp.gnu.org/pub/gnu/config/
 
 If the version you run ($0) is already up to date, please
 send the following data and any information you think might be
diff --git a/tclconfig/config.sub b/tclconfig/config.sub
index c2d1257..9d7f733 100755
--- a/tclconfig/config.sub
+++ b/tclconfig/config.sub
@@ -1,10 +1,9 @@
 #! /bin/sh
 # Configuration validation subroutine script.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-#   Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
-timestamp='2010-01-22'
+timestamp='2003-07-04'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -22,26 +21,22 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
-# 02110-1301, USA.
-#
+# Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
-
 # Please send patches to <config-patches@gnu.org>.  Submit a context
-# diff and a properly formatted GNU ChangeLog entry.
+# diff and a properly formatted ChangeLog entry.
 #
 # Configuration subroutine to validate and canonicalize a configuration type.
 # Supply the specified configuration type as an argument.
 # If it is invalid, we print an error message on stderr and exit with code 1.
 # Otherwise, we print the canonical config type on stdout and succeed.
 
-# You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
-
 # This file is supposed to be the same for all GNU packages
 # and recognize all the CPU types, system types and aliases
 # that are meaningful with *any* GNU software.
@@ -75,9 +70,8 @@
 version="\
 GNU config.sub ($timestamp)
 
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
-Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -89,11 +83,11 @@
 while test $# -gt 0 ; do
   case $1 in
     --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit ;;
+       echo "$timestamp" ; exit 0 ;;
     --version | -v )
-       echo "$version" ; exit ;;
+       echo "$version" ; exit 0 ;;
     --help | --h* | -h )
-       echo "$usage"; exit ;;
+       echo "$usage"; exit 0 ;;
     -- )     # Stop option processing
        shift; break ;;
     - )	# Use stdin as input.
@@ -105,7 +99,7 @@
     *local*)
        # First pass through any local machine types.
        echo $1
-       exit ;;
+       exit 0;;
 
     * )
        break ;;
@@ -124,10 +118,7 @@
 # Here we must recognize all the valid KERNEL-OS combinations.
 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 case $maybe_os in
-  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
-  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
-  kopensolaris*-gnu* | \
-  storm-chaos* | os2-emx* | rtmk-nova*)
+  nto-qnx* | linux-gnu* | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     ;;
@@ -153,13 +144,10 @@
 	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
 	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
 	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-	-apple | -axis | -knuth | -cray | -microblaze)
+	-apple | -axis)
 		os=
 		basic_machine=$1
 		;;
-        -bluegene*)
-	        os=-cnk
-		;;
 	-sim | -cisco | -oki | -wec | -winbond)
 		os=
 		basic_machine=$1
@@ -181,10 +169,6 @@
 	-hiux*)
 		os=-hiuxwe2
 		;;
-	-sco6)
-		os=-sco5v6
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-		;;
 	-sco5)
 		os=-sco3.2v5
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
@@ -201,10 +185,6 @@
 		# Don't forget version if it is 3.2v4 or newer.
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
 		;;
-	-sco5v6*)
-		# Don't forget version if it is 3.2v4 or newer.
-		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-		;;
 	-sco*)
 		os=-sco3.2v2
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
@@ -248,71 +228,53 @@
 	| a29k \
 	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
 	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
-	| am33_2.0 \
-	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
-	| bfin \
+	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
 	| c4x | clipper \
 	| d10v | d30v | dlx | dsp16xx \
-	| fido | fr30 | frv \
+	| fr30 | frv \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| i370 | i860 | i960 | ia64 \
-	| ip2k | iq2000 \
-	| lm32 \
-	| m32c | m32r | m32rle | m68000 | m68k | m88k \
-	| maxq | mb | microblaze | mcore | mep | metag \
+	| ip2k \
+	| m32r | m68000 | m68k | m88k | mcore \
 	| mips | mipsbe | mipseb | mipsel | mipsle \
 	| mips16 \
 	| mips64 | mips64el \
-	| mips64octeon | mips64octeonel \
-	| mips64orion | mips64orionel \
-	| mips64r5900 | mips64r5900el \
 	| mips64vr | mips64vrel \
+	| mips64orion | mips64orionel \
 	| mips64vr4100 | mips64vr4100el \
 	| mips64vr4300 | mips64vr4300el \
 	| mips64vr5000 | mips64vr5000el \
-	| mips64vr5900 | mips64vr5900el \
 	| mipsisa32 | mipsisa32el \
 	| mipsisa32r2 | mipsisa32r2el \
 	| mipsisa64 | mipsisa64el \
-	| mipsisa64r2 | mipsisa64r2el \
 	| mipsisa64sb1 | mipsisa64sb1el \
 	| mipsisa64sr71k | mipsisa64sr71kel \
 	| mipstx39 | mipstx39el \
 	| mn10200 | mn10300 \
-	| moxie \
-	| mt \
 	| msp430 \
-	| nios | nios2 \
 	| ns16k | ns32k \
-	| or32 \
+	| openrisc | or32 \
 	| pdp10 | pdp11 | pj | pjl \
 	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
 	| pyramid \
-	| rx \
-	| score \
-	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
 	| sh64 | sh64le \
-	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
-	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
-	| spu | strongarm \
+	| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
+	| strongarm \
 	| tahoe | thumb | tic4x | tic80 | tron \
-	| ubicom32 \
 	| v850 | v850e \
 	| we32k \
-	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
-	| z8k | z80)
+	| x86 | xscale | xstormy16 | xtensa \
+	| z8k)
 		basic_machine=$basic_machine-unknown
 		;;
-	m6811 | m68hc11 | m6812 | m68hc12 | picochip)
+	m6811 | m68hc11 | m6812 | m68hc12)
 		# Motorola 68HC11/12.
 		basic_machine=$basic_machine-unknown
 		os=-none
 		;;
 	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
 		;;
-	ms1)
-		basic_machine=mt-unknown
-		;;
 
 	# We use `pc' rather than `unknown'
 	# because (1) that's what they normally are, and
@@ -330,71 +292,56 @@
 	| a29k-* \
 	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
 	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
-	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | amd64-* | arc-* \
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
-	| avr-* | avr32-* \
-	| bfin-* | bs2000-* \
+	| avr-* \
+	| bs2000-* \
 	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
-	| clipper-* | craynv-* | cydra-* \
+	| clipper-* | cydra-* \
 	| d10v-* | d30v-* | dlx-* \
 	| elxsi-* \
-	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+	| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
 	| h8300-* | h8500-* \
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| i*86-* | i860-* | i960-* | ia64-* \
-	| ip2k-* | iq2000-* \
-	| lm32-* \
-	| m32c-* | m32r-* | m32rle-* \
+	| ip2k-* \
+	| m32r-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
-	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
+	| m88110-* | m88k-* | mcore-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
 	| mips16-* \
 	| mips64-* | mips64el-* \
-	| mips64octeon-* | mips64octeonel-* \
-	| mips64orion-* | mips64orionel-* \
-	| mips64r5900-* | mips64r5900el-* \
 	| mips64vr-* | mips64vrel-* \
+	| mips64orion-* | mips64orionel-* \
 	| mips64vr4100-* | mips64vr4100el-* \
 	| mips64vr4300-* | mips64vr4300el-* \
 	| mips64vr5000-* | mips64vr5000el-* \
-	| mips64vr5900-* | mips64vr5900el-* \
 	| mipsisa32-* | mipsisa32el-* \
 	| mipsisa32r2-* | mipsisa32r2el-* \
 	| mipsisa64-* | mipsisa64el-* \
-	| mipsisa64r2-* | mipsisa64r2el-* \
 	| mipsisa64sb1-* | mipsisa64sb1el-* \
 	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
 	| mipstx39-* | mipstx39el-* \
-	| mmix-* \
-	| mt-* \
 	| msp430-* \
-	| nios-* | nios2-* \
-	| none-* | np1-* | ns16k-* | ns32k-* \
+	| none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
 	| pyramid-* \
-	| romp-* | rs6000-* | rx-* \
-	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+	| romp-* | rs6000-* \
+	| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
-	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
-	| sparclite-* \
-	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
+	| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
+	| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
 	| tahoe-* | thumb-* \
 	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
-	| tile-* | tilegx-* \
 	| tron-* \
-	| ubicom32-* \
 	| v850-* | v850e-* | vax-* \
 	| we32k-* \
-	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
-	| xstormy16-* | xtensa*-* \
+	| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
+	| xtensa-* \
 	| ymp-* \
-	| z8k-* | z80-*)
-		;;
-	# Recognize the basic CPU types without company name, with glob match.
-	xtensa*)
-		basic_machine=$basic_machine-unknown
+	| z8k-*)
 		;;
 	# Recognize the various machine names and aliases which stand
 	# for a CPU type and a company and sometimes even an OS.
@@ -412,9 +359,6 @@
 		basic_machine=a29k-amd
 		os=-udi
 		;;
-    	abacus)
-		basic_machine=abacus-unknown
-		;;
 	adobe68k)
 		basic_machine=m68010-adobe
 		os=-scout
@@ -432,9 +376,6 @@
 	amd64)
 		basic_machine=x86_64-pc
 		;;
-	amd64-*)
-		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
-		;;
 	amdahl)
 		basic_machine=580-amdahl
 		os=-sysv
@@ -458,10 +399,6 @@
 		basic_machine=m68k-apollo
 		os=-bsd
 		;;
-	aros)
-		basic_machine=i386-pc
-		os=-aros
-		;;
 	aux)
 		basic_machine=m68k-apple
 		os=-aux
@@ -470,26 +407,10 @@
 		basic_machine=ns32k-sequent
 		os=-dynix
 		;;
-	blackfin)
-		basic_machine=bfin-unknown
-		os=-linux
-		;;
-	blackfin-*)
-		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
-		os=-linux
-		;;
-	bluegene*)
-		basic_machine=powerpc-ibm
-		os=-cnk
-		;;
 	c90)
 		basic_machine=c90-cray
 		os=-unicos
 		;;
-        cegcc)
-		basic_machine=arm-unknown
-		os=-cegcc
-		;;
 	convex-c1)
 		basic_machine=c1-convex
 		os=-bsd
@@ -514,27 +435,12 @@
 		basic_machine=j90-cray
 		os=-unicos
 		;;
-	craynv)
-		basic_machine=craynv-cray
-		os=-unicosmp
-		;;
-	cr16)
-		basic_machine=cr16-unknown
-		os=-elf
-		;;
 	crds | unos)
 		basic_machine=m68k-crds
 		;;
-	crisv32 | crisv32-* | etraxfs*)
-		basic_machine=crisv32-axis
-		;;
 	cris | cris-* | etrax*)
 		basic_machine=cris-axis
 		;;
-	crx)
-		basic_machine=crx-unknown
-		os=-elf
-		;;
 	da30 | da30-*)
 		basic_machine=m68k-da30
 		;;
@@ -557,14 +463,6 @@
 		basic_machine=m88k-motorola
 		os=-sysv3
 		;;
-	dicos)
-		basic_machine=i686-pc
-		os=-dicos
-		;;
-	djgpp)
-		basic_machine=i586-pc
-		os=-msdosdjgpp
-		;;
 	dpx20 | dpx20-*)
 		basic_machine=rs6000-bull
 		os=-bosx
@@ -715,14 +613,6 @@
 		basic_machine=m68k-isi
 		os=-sysv
 		;;
-	m68knommu)
-		basic_machine=m68k-unknown
-		os=-linux
-		;;
-	m68knommu-*)
-		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
-		os=-linux
-		;;
 	m88k-omron*)
 		basic_machine=m88k-omron
 		;;
@@ -734,17 +624,10 @@
 		basic_machine=ns32k-utek
 		os=-sysv
 		;;
-        microblaze)
-		basic_machine=microblaze-xilinx
-		;;
 	mingw32)
 		basic_machine=i386-pc
 		os=-mingw32
 		;;
-	mingw32ce)
-		basic_machine=arm-unknown
-		os=-mingw32ce
-		;;
 	miniframe)
 		basic_machine=m68000-convergent
 		;;
@@ -758,6 +641,10 @@
 	mips3*)
 		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
 		;;
+	mmix*)
+		basic_machine=mmix-knuth
+		os=-mmixware
+		;;
 	monitor)
 		basic_machine=m68k-rom68k
 		os=-coff
@@ -770,9 +657,6 @@
 		basic_machine=i386-pc
 		os=-msdos
 		;;
-	ms1-*)
-		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
-		;;
 	mvs)
 		basic_machine=i370-ibm
 		os=-mvs
@@ -841,6 +725,10 @@
 	np1)
 		basic_machine=np1-gould
 		;;
+	nv1)
+		basic_machine=nv1-cray
+		os=-unicosmp
+		;;
 	nsr-tandem)
 		basic_machine=nsr-tandem
 		;;
@@ -848,12 +736,9 @@
 		basic_machine=hppa1.1-oki
 		os=-proelf
 		;;
-	openrisc | openrisc-*)
+	or32 | or32-*)
 		basic_machine=or32-unknown
-		;;
-	os400)
-		basic_machine=powerpc-ibm
-		os=-os400
+		os=-coff
 		;;
 	OSE68000 | ose68000)
 		basic_machine=m68000-ericsson
@@ -871,14 +756,6 @@
 		basic_machine=i860-intel
 		os=-osf
 		;;
-	parisc)
-		basic_machine=hppa-unknown
-		os=-linux
-		;;
-	parisc-*)
-		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
-		os=-linux
-		;;
 	pbd)
 		basic_machine=sparc-tti
 		;;
@@ -888,12 +765,6 @@
 	pc532 | pc532-*)
 		basic_machine=ns32k-pc532
 		;;
-	pc98)
-		basic_machine=i386-pc
-		;;
-	pc98-*)
-		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
-		;;
 	pentium | p5 | k5 | k6 | nexgen | viac3)
 		basic_machine=i586-pc
 		;;
@@ -950,10 +821,6 @@
 		basic_machine=i586-unknown
 		os=-pw32
 		;;
-	rdos)
-		basic_machine=i386-pc
-		os=-rdos
-		;;
 	rom68k)
 		basic_machine=m68k-rom68k
 		os=-coff
@@ -980,10 +847,6 @@
 	sb1el)
 		basic_machine=mipsisa64sb1el-unknown
 		;;
-	sde)
-		basic_machine=mipsisa32-sde
-		os=-elf
-		;;
 	sei)
 		basic_machine=mips-sei
 		os=-seiux
@@ -995,9 +858,6 @@
 		basic_machine=sh-hitachi
 		os=-hms
 		;;
-	sh5el)
-		basic_machine=sh5le-unknown
-		;;
 	sh64)
 		basic_machine=sh64-unknown
 		;;
@@ -1087,15 +947,6 @@
 		basic_machine=tic6x-unknown
 		os=-coff
 		;;
-        # This must be matched before tile*.
-        tilegx*)
-		basic_machine=tilegx-unknown
-		os=-linux-gnu
-		;;
-	tile*)
-		basic_machine=tile-unknown
-		os=-linux-gnu
-		;;
 	tx39)
 		basic_machine=mipstx39-unknown
 		;;
@@ -1109,10 +960,6 @@
 	tower | tower-32)
 		basic_machine=m68k-ncr
 		;;
-	tpf)
-		basic_machine=s390x-ibm
-		os=-tpf
-		;;
 	udi29k)
 		basic_machine=a29k-amd
 		os=-udi
@@ -1156,10 +1003,6 @@
 		basic_machine=hppa1.1-winbond
 		os=-proelf
 		;;
-	xbox)
-		basic_machine=i686-pc
-		os=-mingw32
-		;;
 	xps | xps100)
 		basic_machine=xps100-honeywell
 		;;
@@ -1171,10 +1014,6 @@
 		basic_machine=z8k-unknown
 		os=-sim
 		;;
-	z80-*-coff)
-		basic_machine=z80-unknown
-		os=-sim
-		;;
 	none)
 		basic_machine=none-none
 		os=-none
@@ -1194,9 +1033,6 @@
 	romp)
 		basic_machine=romp-ibm
 		;;
-	mmix)
-		basic_machine=mmix-knuth
-		;;
 	rs6000)
 		basic_machine=rs6000-ibm
 		;;
@@ -1213,10 +1049,13 @@
 	we32k)
 		basic_machine=we32k-att
 		;;
-	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+	sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
 		basic_machine=sh-unknown
 		;;
-	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparc | sparcv9 | sparcv9b)
 		basic_machine=sparc-sun
 		;;
 	cydra)
@@ -1263,9 +1102,6 @@
         # First match some system type aliases
         # that might get confused with valid system types.
 	# -solaris* is a basic system type, with this one exception.
-        -auroraux)
-	        os=-auroraux
-		;;
 	-solaris1 | -solaris1.*)
 		os=`echo $os | sed -e 's|solaris1|sunos4|'`
 		;;
@@ -1286,30 +1122,25 @@
 	# Each alternative MUST END IN A *, to match a version number.
 	# -sysv* is not here because it comes later, after sysvr4.
 	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
-	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
-	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
-	      | -sym* | -kopensolaris* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
-	      | -aos* | -aros* \
+	      | -aos* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
-	      | -openbsd* | -solidbsd* \
-	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
-	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
+	      | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
-	      | -chorusos* | -chorusrdb* | -cegcc* \
+	      | -chorusos* | -chorusrdb* \
 	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
-	      | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
 	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
 	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
-	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
-	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei*)
 	# Remember, each alternative MUST END IN *, to match a version number.
 		;;
 	-qnx*)
@@ -1327,15 +1158,12 @@
 		os=`echo $os | sed -e 's|nto|nto-qnx|'`
 		;;
 	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
-	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
 	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
 		;;
 	-mac*)
 		os=`echo $os | sed -e 's|mac|macos|'`
 		;;
-	-linux-dietlibc)
-		os=-linux-dietlibc
-		;;
 	-linux*)
 		os=`echo $os | sed -e 's|linux|linux-gnu|'`
 		;;
@@ -1348,9 +1176,6 @@
 	-opened*)
 		os=-openedition
 		;;
-        -os400*)
-		os=-os400
-		;;
 	-wince*)
 		os=-wince
 		;;
@@ -1372,9 +1197,6 @@
 	-atheos*)
 		os=-atheos
 		;;
-	-syllable*)
-		os=-syllable
-		;;
 	-386bsd)
 		os=-bsd
 		;;
@@ -1397,9 +1219,6 @@
 	-sinix*)
 		os=-sysv4
 		;;
-        -tpf*)
-		os=-tpf
-		;;
 	-triton*)
 		os=-sysv3
 		;;
@@ -1436,14 +1255,6 @@
 	-kaos*)
 		os=-kaos
 		;;
-	-zvmoe)
-		os=-zvmoe
-		;;
-	-dicos*)
-		os=-dicos
-		;;
-        -nacl*)
-	        ;;
 	-none)
 		;;
 	*)
@@ -1466,12 +1277,6 @@
 # system, and we'll never get to this point.
 
 case $basic_machine in
-        score-*)
-		os=-elf
-		;;
-        spu-*)
-		os=-elf
-		;;
 	*-acorn)
 		os=-riscix1.2
 		;;
@@ -1481,9 +1286,9 @@
 	arm*-semi)
 		os=-aout
 		;;
-        c4x-* | tic4x-*)
-        	os=-coff
-		;;
+    c4x-* | tic4x-*)
+        os=-coff
+        ;;
 	# This must come before the *-dec entry.
 	pdp10-*)
 		os=-tops20
@@ -1509,9 +1314,6 @@
 	m68*-cisco)
 		os=-aout
 		;;
-        mep-*)
-		os=-elf
-		;;
 	mips*-cisco)
 		os=-elf
 		;;
@@ -1530,15 +1332,9 @@
 	*-be)
 		os=-beos
 		;;
-	*-haiku)
-		os=-haiku
-		;;
 	*-ibm)
 		os=-aix
 		;;
-    	*-knuth)
-		os=-mmixware
-		;;
 	*-wec)
 		os=-proelf
 		;;
@@ -1641,7 +1437,7 @@
 			-sunos*)
 				vendor=sun
 				;;
-			-cnk*|-aix*)
+			-aix*)
 				vendor=ibm
 				;;
 			-beos*)
@@ -1671,15 +1467,9 @@
 			-mvs* | -opened*)
 				vendor=ibm
 				;;
-			-os400*)
-				vendor=ibm
-				;;
 			-ptx*)
 				vendor=sequent
 				;;
-			-tpf*)
-				vendor=ibm
-				;;
 			-vxsim* | -vxworks* | -windiss*)
 				vendor=wrs
 				;;
@@ -1704,7 +1494,7 @@
 esac
 
 echo $basic_machine$os
-exit
+exit 0
 
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)
diff --git a/tclconfig/depcomp b/tclconfig/depcomp
index 6589965..df8eea7 100755
--- a/tclconfig/depcomp
+++ b/tclconfig/depcomp
@@ -1,7 +1,10 @@
 #! /bin/sh
-
 # depcomp - compile a program generating dependencies as side-effects
-# Copyright 1999, 2000 Free Software Foundation, Inc.
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
+# Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -14,9 +17,7 @@
 # GNU General Public License for more details.
 
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -25,13 +26,45 @@
 
 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
 
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by `PROGRAMS ARGS'.
+  object      Object file output by `PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputing dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
   echo "depcomp: Variables source, object and depmode must be set" 1>&2
   exit 1
 fi
-# `libtool' can also be set to `yes' or `no'.
 
-depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
 
 rm -f "$tmpdepfile"
@@ -52,12 +85,34 @@
    depmode=dashmstdout
 fi
 
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+   # This is just like msvisualcpp but w/o cygpath translation.
+   # Just convert the backslash-escaped backslashes to single forward
+   # slashes to satisfy depend.m4
+   cygpath_u="sed s,\\\\\\\\,/,g"
+   depmode=msvisualcpp
+fi
+
 case "$depmode" in
 gcc3)
 ## gcc 3 implements dependency tracking that does exactly what
 ## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
 ## it if -MD -MP comes after the -MF stuff.  Hmm.
-  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
   stat=$?
   if test $stat -eq 0; then :
   else
@@ -144,14 +199,14 @@
 ' < "$tmpdepfile" \
     | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
     tr '
-' ' ' >> $depfile
-    echo >> $depfile
+' ' ' >> "$depfile"
+    echo >> "$depfile"
 
     # The second pass generates a dummy entry for each header file.
     tr ' ' '
 ' < "$tmpdepfile" \
    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
-   >> $depfile
+   >> "$depfile"
   else
     # The sourcefile does not contain any dependencies, so just
     # store a dummy comment line, to avoid errors with the Makefile
@@ -163,31 +218,43 @@
 
 aix)
   # The C for AIX Compiler uses -M and outputs the dependencies
-  # in a .u file.  This file always lives in the current directory.
-  # Also, the AIX compiler puts `$object:' at the start of each line;
-  # $object doesn't have directory information.
-  stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
-  tmpdepfile="$stripped.u"
-  outname="$stripped.o"
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts `$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
   if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
     "$@" -Wc,-M
   else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
     "$@" -M
   fi
-
   stat=$?
+
   if test $stat -eq 0; then :
   else
-    rm -f "$tmpdepfile"
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
     exit $stat
   fi
 
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
   if test -f "$tmpdepfile"; then
     # Each line is of the form `foo.o: dependent.h'.
     # Do two passes, one to just change these to
     # `$object: dependent.h' and one to simply `dependent.h:'.
-    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
-    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
+    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+    # That's a tab and a space in the [].
+    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
   else
     # The sourcefile does not contain any dependencies, so just
     # store a dummy comment line, to avoid errors with the Makefile
@@ -197,37 +264,141 @@
   rm -f "$tmpdepfile"
   ;;
 
+icc)
+  # Intel's C compiler understands `-MD -MF file'.  However on
+  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
+  # ICC 7.0 will fill foo.d with something like
+  #    foo.o: sub/foo.c
+  #    foo.o: sub/foo.h
+  # which is wrong.  We want:
+  #    sub/foo.o: sub/foo.c
+  #    sub/foo.o: sub/foo.h
+  #    sub/foo.c:
+  #    sub/foo.h:
+  # ICC 7.1 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using \ :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
+    sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add `dependent.h:' lines.
+    sed -ne '2,${
+	       s/^ *//
+	       s/ \\*$//
+	       s/$/:/
+	       p
+	     }' "$tmpdepfile" >> "$depfile"
+  else
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
 tru64)
-   # The Tru64 AIX compiler uses -MD to generate dependencies as a side
+   # The Tru64 compiler uses -MD to generate dependencies as a side
    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
-   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 
+   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
    # dependencies in `foo.d' instead, so we check for that too.
    # Subdirectories are respected.
+   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+   test "x$dir" = "x$object" && dir=
+   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
 
-   tmpdepfile1="$object.d"
-   tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'` 
    if test "$libtool" = yes; then
+      # With Tru64 cc, shared objects can also be used to make a
+      # static library.  This mechanism is used in libtool 1.4 series to
+      # handle both shared and static libraries in a single compilation.
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
+      #
+      # With libtool 1.5 this exception was removed, and libtool now
+      # generates 2 separate objects for the 2 libraries.  These two
+      # compilations output dependencies in $dir.libs/$base.o.d and
+      # in $dir$base.o.d.  We have to check for both files, because
+      # one of the two compilations can be disabled.  We should prefer
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+      # automatically cleaned when .libs/ is deleted, while ignoring
+      # the former would cause a distcleancheck panic.
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
       "$@" -Wc,-MD
    else
+      tmpdepfile1=$dir$base.o.d
+      tmpdepfile2=$dir$base.d
+      tmpdepfile3=$dir$base.d
+      tmpdepfile4=$dir$base.d
       "$@" -MD
    fi
 
    stat=$?
    if test $stat -eq 0; then :
    else
-      rm -f "$tmpdepfile1" "$tmpdepfile2"
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
       exit $stat
    fi
 
-   if test -f "$tmpdepfile1"; then
-      tmpdepfile="$tmpdepfile1"
-   else
-      tmpdepfile="$tmpdepfile2"
-   fi
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+   do
+     test -f "$tmpdepfile" && break
+   done
    if test -f "$tmpdepfile"; then
       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
-      # That's a space and a tab in the [].
-      sed -e 's,^.*\.[a-z]*:[ 	]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+      # That's a tab and a space in the [].
+      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
    else
       echo "#dummy" > "$depfile"
    fi
@@ -240,34 +411,42 @@
 
 dashmstdout)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the proprocessed file to stdout, regardless of -o,
-  # because we must use -o when running libtool.
-  test -z "$dashmflag" && dashmflag=-M
-  ( IFS=" "
-    case " $* " in
-    *" --mode=compile "*) # this is libtool, let us make it quiet
-      for arg
-      do # cycle over the arguments
-        case "$arg" in
-	"--mode=compile")
-	  # insert --quiet before "--mode=compile"
-	  set fnord "$@" --quiet
-	  shift # fnord
-	  ;;
-	esac
-	set fnord "$@" "$arg"
-	shift # fnord
-	shift # "$arg"
-      done
+  # always write the preprocessed file to stdout, regardless of -o.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
       ;;
     esac
-    "$@" $dashmflag | sed 's:^[^:]*\:[ 	]*:'"$object"'\: :' > "$tmpdepfile"
-  ) &
-  proc=$!
-  "$@"
-  stat=$?
-  wait "$proc"
-  if test "$stat" != 0; then exit $stat; fi
+  done
+
+  test -z "$dashmflag" && dashmflag=-M
+  # Require at least two characters before searching for `:'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+  "$@" $dashmflag |
+    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
   rm -f "$depfile"
   cat < "$tmpdepfile" > "$depfile"
   tr ' ' '
@@ -285,36 +464,47 @@
   ;;
 
 makedepend)
-  # X makedepend
-  (
-    shift
-    cleared=no
-    for arg in "$@"; do
-      case $cleared in no)
-        set ""; shift
-	cleared=yes
-      esac
-      case "$arg" in
-        -D*|-I*)
-	  set fnord "$@" "$arg"; shift;;
-	-*)
-	  ;;
-	*)
-	  set fnord "$@" "$arg"; shift;;
-      esac
+  "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
     done
-    obj_suffix="`echo $object | sed 's/^.*\././'`"
-    touch "$tmpdepfile"
-    ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
-  ) &
-  proc=$!
-  "$@"
-  stat=$?
-  wait "$proc"
-  if test "$stat" != 0; then exit $stat; fi
+    shift
+  fi
+  # X makedepend
+  shift
+  cleared=no eat=no
+  for arg
+  do
+    case $cleared in
+    no)
+      set ""; shift
+      cleared=yes ;;
+    esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
+    case "$arg" in
+    -D*|-I*)
+      set fnord "$@" "$arg"; shift ;;
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
+    -*|$object)
+      ;;
+    *)
+      set fnord "$@" "$arg"; shift ;;
+    esac
+  done
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
+  touch "$tmpdepfile"
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
   rm -f "$depfile"
   cat < "$tmpdepfile" > "$depfile"
-  tail +3 "$tmpdepfile" | tr ' ' '
+  sed '1,2d' "$tmpdepfile" | tr ' ' '
 ' | \
 ## Some versions of the HPUX 10.20 sed can't process this invocation
 ## correctly.  Breaking it into two sed invocations is a workaround.
@@ -324,35 +514,40 @@
 
 cpp)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the proprocessed file to stdout, regardless of -o,
-  # because we must use -o when running libtool.
-  ( IFS=" "
-    case " $* " in
-    *" --mode=compile "*)
-      for arg
-      do # cycle over the arguments
-        case $arg in
-	"--mode=compile")
-	  # insert --quiet before "--mode=compile"
-	  set fnord "$@" --quiet
-	  shift # fnord
-	  ;;
-	esac
-	set fnord "$@" "$arg"
-	shift # fnord
-	shift # "$arg"
-      done
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
       ;;
     esac
-    "$@" -E |
-    sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
+  done
+
+  "$@" -E |
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
     sed '$ s: \\$::' > "$tmpdepfile"
-  ) &
-  proc=$!
-  "$@"
-  stat=$?
-  wait "$proc"
-  if test "$stat" != 0; then exit $stat; fi
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
   cat < "$tmpdepfile" >> "$depfile"
@@ -362,42 +557,56 @@
 
 msvisualcpp)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the proprocessed file to stdout, regardless of -o,
-  # because we must use -o when running libtool.
-  ( IFS=" "
-    case " $* " in
-    *" --mode=compile "*)
-      for arg
-      do # cycle over the arguments
-        case $arg in
-	"--mode=compile")
-	  # insert --quiet before "--mode=compile"
-	  set fnord "$@" --quiet
-	  shift # fnord
-	  ;;
-	esac
-	set fnord "$@" "$arg"
-	shift # fnord
-	shift # "$arg"
-      done
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  IFS=" "
+  for arg
+  do
+    case "$arg" in
+    -o)
+      shift
       ;;
+    $object)
+      shift
+      ;;
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
+	set fnord "$@"
+	shift
+	shift
+	;;
+    *)
+	set fnord "$@" "$arg"
+	shift
+	shift
+	;;
     esac
-    "$@" -E |
-    sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
-  ) &
-  proc=$!
-  "$@"
-  stat=$?
-  wait "$proc"
-  if test "$stat" != 0; then exit $stat; fi
+  done
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
-  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
   echo "	" >> "$depfile"
-  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
   rm -f "$tmpdepfile"
   ;;
 
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
 none)
   exec "$@"
   ;;
@@ -409,3 +618,13 @@
 esac
 
 exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/tclconfig/ltmain.sh b/tclconfig/ltmain.sh
index c7d06c3..16ddbf8 100644
--- a/tclconfig/ltmain.sh
+++ b/tclconfig/ltmain.sh
@@ -70,7 +70,7 @@
 #         compiler:		$LTCC
 #         compiler flags:		$LTCFLAGS
 #         linker:		$LD (gnu? $with_gnu_ld)
-#         $progname:	(GNU libtool) 2.4.2 Debian-2.4.2-1
+#         $progname:	(GNU libtool) 2.4.2
 #         automake:	$automake_version
 #         autoconf:	$autoconf_version
 #
@@ -80,7 +80,7 @@
 
 PROGRAM=libtool
 PACKAGE=libtool
-VERSION="2.4.2 Debian-2.4.2-1"
+VERSION=2.4.2
 TIMESTAMP=""
 package_revision=1.3337
 
@@ -1375,6 +1375,21 @@
 func_infer_tag ()
 {
     $opt_debug
+
+    # FreeBSD-specific: where we install compilers with non-standard names
+    tag_compilers_CC="*cc cc* *gcc gcc* clang"
+    tag_compilers_CXX="*c++ c++* *g++ g++* clang++"
+    base_compiler=`set -- "$@"; echo $1`
+
+    # If $tagname isn't set, then try to infer if the default "CC" tag applies
+    if test -z "$tagname"; then
+      for zp in $tag_compilers_CC; do
+        case $base_compiler in
+	 $zp) tagname="CC"; break;;
+	esac
+      done
+    fi
+
     if test -n "$available_tags" && test -z "$tagname"; then
       CC_quoted=
       for arg in $CC; do
@@ -1411,7 +1426,22 @@
 	      break
 	      ;;
 	    esac
-	  fi
+
+	    # FreeBSD-specific: try compilers based on inferred tag
+	    if test -z "$tagname"; then
+	      eval "tag_compilers=\$tag_compilers_${z}"
+	      if test -n "$tag_compilers"; then
+		for zp in $tag_compilers; do
+		  case $base_compiler in   
+		    $zp) tagname=$z; break;;
+		  esac
+		done
+		if test -n "$tagname"; then
+		  break
+		fi
+	      fi
+            fi
+          fi
 	done
 	# If $tagname still isn't set, then no tagged configuration
 	# was found and let the user know that the "--tag" command
@@ -3517,6 +3547,9 @@
 	  ;;
 	esac
 	;;
+      *-*-freebsd*)
+	# FreeBSD doesn't need this...
+	;;
       *)
 	func_fatal_error "unknown suffix for \`$my_dlsyms'"
 	;;
@@ -5595,6 +5628,7 @@
 	  esac
 	  ;;
 	esac
+	deplibs="$deplibs $arg"
 	continue
 	;;
 
@@ -6124,10 +6158,7 @@
 	case $pass in
 	dlopen) libs="$dlfiles" ;;
 	dlpreopen) libs="$dlprefiles" ;;
-	link)
-	  libs="$deplibs %DEPLIBS%"
-	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
-	  ;;
+	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
 	esac
       fi
       if test "$linkmode,$pass" = "lib,dlpreopen"; then
@@ -6170,13 +6201,30 @@
 	    finalize_deplibs="$deplib $finalize_deplibs"
 	  else
 	    func_append compiler_flags " $deplib"
-	    if test "$linkmode" = lib ; then
-		case "$new_inherited_linker_flags " in
-		    *" $deplib "*) ;;
-		    * ) func_append new_inherited_linker_flags " $deplib" ;;
-		esac
-	    fi
 	  fi
+
+	  case $linkmode in
+	  lib)
+	    deplibs="$deplib $deplibs"
+	    test "$pass" = conv && continue
+	    newdependency_libs="$deplib $newdependency_libs"
+	    ;;
+	  prog)
+	    if test "$pass" = conv; then
+	      deplibs="$deplib $deplibs"
+	      continue
+	    fi
+	    if test "$pass" = scan; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    ;;
+	  *)
+	    ;;
+	  esac # linkmode
+
 	  continue
 	  ;;
 	-l*)
@@ -6447,19 +6495,19 @@
 	    # It is a libtool convenience library, so add in its objects.
 	    func_append convenience " $ladir/$objdir/$old_library"
 	    func_append old_convenience " $ladir/$objdir/$old_library"
-	    tmp_libs=
-	    for deplib in $dependency_libs; do
-	      deplibs="$deplib $deplibs"
-	      if $opt_preserve_dup_deps ; then
-		case "$tmp_libs " in
-		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
-		esac
-	      fi
-	      func_append tmp_libs " $deplib"
-	    done
 	  elif test "$linkmode" != prog && test "$linkmode" != lib; then
 	    func_fatal_error "\`$lib' is not a convenience library"
 	  fi
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    deplibs="$deplib $deplibs"
+	    if $opt_preserve_dup_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
+	      esac
+	    fi
+	    func_append tmp_libs " $deplib"
+	  done
 	  continue
 	fi # $pass = conv
 
@@ -7352,9 +7400,6 @@
 	    revision="$number_minor"
 	    lt_irix_increment=no
 	    ;;
-	  *)
-	    func_fatal_configuration "$modename: unknown library version type \`$version_type'"
-	    ;;
 	  esac
 	  ;;
 	no)
diff --git a/tclconfig/missing b/tclconfig/missing
index e7ef83a..28055d2 100755
--- a/tclconfig/missing
+++ b/tclconfig/missing
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Common stub for a few missing GNU programs while installing.
 
-scriptversion=2003-09-02.23
+scriptversion=2009-04-28.21; # UTC
 
-# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 
-#   Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
+# 2008, 2009 Free Software Foundation, Inc.
 # Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 
 # This program is free software; you can redistribute it and/or modify
@@ -18,9 +18,7 @@
 # GNU General Public License for more details.
 
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -33,6 +31,8 @@
 fi
 
 run=:
+sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
+sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
 
 # In the cases where this matters, `missing' is being run in the
 # srcdir already.
@@ -44,7 +44,7 @@
 
 msg="missing on your system"
 
-case "$1" in
+case $1 in
 --run)
   # Try to run requested program, and just exit if it succeeds.
   run=
@@ -60,11 +60,6 @@
     msg="probably too old"
   fi
   ;;
-esac
-
-# If it does not exist, or fails to run (possibly an outdated version),
-# try to emulate it.
-case "$1" in
 
   -h|--h|--he|--hel|--help)
     echo "\
@@ -82,6 +77,7 @@
   aclocal      touch file \`aclocal.m4'
   autoconf     touch file \`configure'
   autoheader   touch file \`config.h.in'
+  autom4te     touch the output file, or create a stub one
   automake     touch all \`Makefile.in' files
   bison        create \`y.tab.[ch]', if possible, from existing .[ch]
   flex         create \`lex.yy.c', if possible, from existing .c
@@ -91,11 +87,16 @@
   tar          try tar, gnutar, gtar, then tar without non-portable flags
   yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
 
+Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
+\`g' are ignored when checking the name.
+
 Send bug reports to <bug-automake@gnu.org>."
+    exit $?
     ;;
 
   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
     echo "missing $scriptversion (GNU Automake)"
+    exit $?
     ;;
 
   -*)
@@ -104,12 +105,49 @@
     exit 1
     ;;
 
-  aclocal*)
+esac
+
+# normalize program name to check for.
+program=`echo "$1" | sed '
+  s/^gnu-//; t
+  s/^gnu//; t
+  s/^g//; t'`
+
+# Now exit if we have it, but it failed.  Also exit now if we
+# don't have it and --version was passed (most likely to detect
+# the program).  This is about non-GNU programs, so use $1 not
+# $program.
+case $1 in
+  lex*|yacc*)
+    # Not GNU programs, they don't have --version.
+    ;;
+
+  tar*)
+    if test -n "$run"; then
+       echo 1>&2 "ERROR: \`tar' requires --run"
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       exit 1
+    fi
+    ;;
+
+  *)
     if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
        # We have it, but it failed.
        exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       # Could not run --version or --help.  This is probably someone
+       # running `$TOOL --version' or `$TOOL --help' to check whether
+       # $TOOL exists and not knowing $TOOL uses missing.
+       exit 1
     fi
+    ;;
+esac
 
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case $program in
+  aclocal*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
@@ -118,12 +156,7 @@
     touch aclocal.m4
     ;;
 
-  autoconf)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
+  autoconf*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`${configure_ac}'.  You might want to install the
@@ -132,12 +165,7 @@
     touch configure
     ;;
 
-  autoheader)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
+  autoheader*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`acconfig.h' or \`${configure_ac}'.  You might want
@@ -147,7 +175,7 @@
     test -z "$files" && files="config.h"
     touch_files=
     for f in $files; do
-      case "$f" in
+      case $f in
       *:*) touch_files="$touch_files "`echo "$f" |
 				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
       *) touch_files="$touch_files $f.in";;
@@ -157,11 +185,6 @@
     ;;
 
   automake*)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
@@ -172,12 +195,7 @@
 	   while read f; do touch "$f"; done
     ;;
 
-  autom4te)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
+  autom4te*)
     echo 1>&2 "\
 WARNING: \`$1' is needed, but is $msg.
          You might have modified some files without having the
@@ -185,8 +203,8 @@
          You can get \`$1' as part of \`Autoconf' from any GNU
          archive site."
 
-    file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
-    test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
     if test -f "$file"; then
 	touch $file
     else
@@ -200,90 +218,78 @@
     fi
     ;;
 
-  bison|yacc)
+  bison*|yacc*)
     echo 1>&2 "\
 WARNING: \`$1' $msg.  You should only need it if
          you modified a \`.y' file.  You may need the \`Bison' package
          in order for those modifications to take effect.  You can get
          \`Bison' from any GNU archive site."
     rm -f y.tab.c y.tab.h
-    if [ $# -ne 1 ]; then
+    if test $# -ne 1; then
         eval LASTARG="\${$#}"
-	case "$LASTARG" in
+	case $LASTARG in
 	*.y)
 	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
-	    if [ -f "$SRCFILE" ]; then
+	    if test -f "$SRCFILE"; then
 	         cp "$SRCFILE" y.tab.c
 	    fi
 	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
-	    if [ -f "$SRCFILE" ]; then
+	    if test -f "$SRCFILE"; then
 	         cp "$SRCFILE" y.tab.h
 	    fi
 	  ;;
 	esac
     fi
-    if [ ! -f y.tab.h ]; then
+    if test ! -f y.tab.h; then
 	echo >y.tab.h
     fi
-    if [ ! -f y.tab.c ]; then
+    if test ! -f y.tab.c; then
 	echo 'main() { return 0; }' >y.tab.c
     fi
     ;;
 
-  lex|flex)
+  lex*|flex*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified a \`.l' file.  You may need the \`Flex' package
          in order for those modifications to take effect.  You can get
          \`Flex' from any GNU archive site."
     rm -f lex.yy.c
-    if [ $# -ne 1 ]; then
+    if test $# -ne 1; then
         eval LASTARG="\${$#}"
-	case "$LASTARG" in
+	case $LASTARG in
 	*.l)
 	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
-	    if [ -f "$SRCFILE" ]; then
+	    if test -f "$SRCFILE"; then
 	         cp "$SRCFILE" lex.yy.c
 	    fi
 	  ;;
 	esac
     fi
-    if [ ! -f lex.yy.c ]; then
+    if test ! -f lex.yy.c; then
 	echo 'main() { return 0; }' >lex.yy.c
     fi
     ;;
 
-  help2man)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
+  help2man*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
 	 you modified a dependency of a manual page.  You may need the
 	 \`Help2man' package in order for those modifications to take
 	 effect.  You can get \`Help2man' from any GNU archive site."
 
-    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
-    if test -z "$file"; then
-	file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
-    fi
-    if [ -f "$file" ]; then
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
 	touch $file
     else
 	test -z "$file" || exec >$file
 	echo ".ab help2man is required to generate this page"
-	exit 1
+	exit $?
     fi
     ;;
 
-  makeinfo)
-    if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
-       # We have makeinfo, but it failed.
-       exit 1
-    fi
-
+  makeinfo*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified a \`.texi' or \`.texinfo' file, or any other file
@@ -291,20 +297,29 @@
          call might also be the consequence of using a buggy \`make' (AIX,
          DU, IRIX).  You might want to install the \`Texinfo' package or
          the \`GNU make' package.  Grab either from any GNU archive site."
-    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
+    # The file to touch is that specified with -o ...
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
     if test -z "$file"; then
-      file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
-      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
+      # ... or it is the one specified with @setfilename ...
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '
+	/^@setfilename/{
+	  s/.* \([^ ]*\) *$/\1/
+	  p
+	  q
+	}' $infile`
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
     fi
+    # If the file does not exist, the user really needs makeinfo;
+    # let's fail without touching anything.
+    test -f $file || exit 1
     touch $file
     ;;
 
-  tar)
+  tar*)
     shift
-    if test -n "$run"; then
-      echo 1>&2 "ERROR: \`tar' requires --run"
-      exit 1
-    fi
 
     # We have already tried tar in the generic part.
     # Look for gnutar/gtar before invocation to avoid ugly error
@@ -317,13 +332,13 @@
     fi
     firstarg="$1"
     if shift; then
-	case "$firstarg" in
+	case $firstarg in
 	*o*)
 	    firstarg=`echo "$firstarg" | sed s/o//`
 	    tar "$firstarg" "$@" && exit 0
 	    ;;
 	esac
-	case "$firstarg" in
+	case $firstarg in
 	*h*)
 	    firstarg=`echo "$firstarg" | sed s/h//`
 	    tar "$firstarg" "$@" && exit 0
@@ -356,5 +371,6 @@
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:
diff --git a/tests/apachetest/apachetest.tcl b/tests/apachetest/apachetest.tcl
index 3a051d7..53ab67a 100644
--- a/tests/apachetest/apachetest.tcl
+++ b/tests/apachetest/apachetest.tcl
@@ -30,7 +30,7 @@
 
 namespace eval apachetest {
 
-    set debug 0
+    set debug 1
 
     # name of the apache binary, such as /usr/sbin/httpd
     variable binname ""
@@ -80,13 +80,13 @@
     set diff 0
     # We try for 10 seconds.
     while { $diff < 10 } {
-	if { ! [catch {
-	    set sk [socket localhost 8081]
-	} err]} {
-	    close $sk
-	    return
-	}
-	set diff [expr {[clock seconds] - $starttime}]
+        if { ! [catch {
+            set sk [socket localhost 8081]
+        } err]} {
+            close $sk
+            return
+        }
+        set diff [expr {[clock seconds] - $starttime}]
     }
 }
 
@@ -133,10 +133,9 @@
     if { $debug > 0 } {
 	    puts "Apache started as PID $serverpid"
     }
-    if { [catch {
-	uplevel $code
-    } err] } {
-    }
+
+    if { [catch { uplevel $code } err] } { }
+
     # Kill and wait are the only reasons we need TclX.
     # apache2 binary started with -X reacts to SIGQUIT and ignores TERM
     kill QUIT $serverpid 
@@ -153,14 +152,14 @@
 proc apachetest::startserver { args } {
     variable binname
     variable debug
+
     if { [catch {
-	if { $debug } {
-	    puts "$binname -X -f [file join [pwd] server.conf] [concat $args]"
-	}
-	set serverpid [eval exec $binname -X -f \
-			   "[file join [pwd] server.conf]" [concat $args]]
+        if { $debug } {
+            puts "$binname -X -f [file join [pwd] server.conf] [concat $args]"
+        }
+        set serverpid [eval exec $binname -X -f "[file join [pwd] server.conf]" [concat $args]]
     } err] } {
-	puts "$err"
+        puts "$err"
     }
 }
 
@@ -169,9 +168,10 @@
 
 proc apachetest::getbinname { argv } {
     variable binname
+
     set binname [lindex $argv 0]
     if { $binname == "" || ! [file executable $binname] } {
-	error "Please supply the full name and path of the Apache executable on the command line."
+	    error "Please supply the full name and path of the Apache executable on the command line."
     }
     return $binname
 }
@@ -182,6 +182,7 @@
 
 proc apachetest::getcompiledin { binname } {
     variable module_assoc
+
     set bin [open [list | "$binname" -l] r]
     set compiledin [read $bin]
     close $bin
@@ -189,17 +190,17 @@
     set compiledin [list]
     set mod_so_present 0
     foreach entry $modlist {
-	if { [regexp {(.*)\.c$} $entry match modname] } {
-	    if { $modname == "mod_so" } {
-		set mod_so_present 1
-	    }
-	    if { [info exists module_assoc($modname)] } {
-		lappend compiledin $module_assoc($modname)
-	    }
-	}
+        if { [regexp {(.*)\.c$} $entry match modname] } {
+            if { $modname == "mod_so" } {
+                set mod_so_present 1
+            }
+            if { [info exists module_assoc($modname)] } {
+                lappend compiledin $module_assoc($modname)
+            }
+        }
     }
     if { $mod_so_present == 0 } {
-	error "We need mod_so in Apache to run these tests"
+        error "We need mod_so in Apache to run these tests"
     }
     return $compiledin
 }
@@ -211,15 +212,19 @@
     set options [read $bin]
     close $bin
     regexp {SERVER_CONFIG_FILE="(.*?)"} "$options" match filename
+
     if { ! [file exists $filename] } {
-	# see if we can find something by combining HTTP_ROOT + SERVER_CONFIG_FILE
-	regexp {HTTPD_ROOT="(.*?)"} "$options" match httpdroot
-	set completename [file join $httpdroot $filename]
-	if { ! [file exists $completename] } {
-	    error "neither '$filename' or '$completename' exists"
-	}
-	return $completename
+
+# see if we can find something by combining HTTP_ROOT + SERVER_CONFIG_FILE
+
+        regexp {HTTPD_ROOT="(.*?)"} "$options" match httpdroot
+        set completename [file join $httpdroot $filename]
+        if { ! [file exists $completename] } {
+            error "neither '$filename' or '$completename' exists"
+        }
+        return $completename
     }
+
     return $filename
 }
 
@@ -238,7 +243,7 @@
 #	Text of configuration files.
 
 proc apachetest::getallincludes { conffile } {
-    if [file  exists $conffile] {
+    if [file exists $conffile] {
 	    set fl [open $conffile r]
 	    set data [read $fl]
 	    close $fl
@@ -246,41 +251,41 @@
 	    set newdata {}
 	    foreach line [split $data \n] {
 		# Look for Include lines.
-		if { [regexp -line {^[^\#]*Include +(.*)} $line match file] } {
-		    puts "including files from $file"
-		    set file [string trim $file]
+            if { [regexp -line {^[^\#]*Include +(.*)} $line match file] } {
+                puts "including files from $file"
+                set file [string trim $file]
 
-		    # Include directives accept as argument a file, a directory
-		    # or a glob-style file matching pattern. Patterns usually match
-		    # many files, but are not directories, so we have to handle 
-		    # all these 3 cases
+                # Include directives accept as argument a file, a directory
+                # or a glob-style file matching pattern. Patterns usually match
+                # many files, but are not directories, so we have to handle 
+                # all these 3 cases
 
-		    # we use the glob command to tell whether we are dealing with
-		    # a pure file expression or a matching pattern
+                # we use the glob command to tell whether we are dealing with
+                # a pure file expression or a matching pattern
 
-		    set matched_files [glob -nocomplain $file]
-		    set matched_files_n [llength $matched_files]
-		    if {$matched_files_n > 1} {
-			foreach fl $matched_files {
-			    puts "including $fl"
-			    if [file  exists $fl] {
-				    append newdata [getallincludes $fl]
-			    }
-			}
-		    } elseif {$matched_files_n == 1} {
-			set file $matched_files
-			if { [file isdirectory $file] } {
-			    foreach fl [glob -nocomplain [file join $file *]] {
-				puts "including $fl"
-				if [file  exists $fl] {
-					append newdata [getallincludes $fl]
-				}
-			    }
-			} else {
-			    append newdata [getallincludes $file]
-			}
-		    }
-		}
+                set matched_files [glob -nocomplain $file]
+                set matched_files_n [llength $matched_files]
+                if {$matched_files_n > 1} {
+                    foreach fl $matched_files {
+                        puts "including $fl"
+                        if [file  exists $fl] {
+                            append newdata [getallincludes $fl]
+                        }
+                    }
+                } elseif {$matched_files_n == 1} {
+                    set file $matched_files
+                    if { [file isdirectory $file] } {
+                        foreach fl [glob -nocomplain [file join $file *]] {
+                            puts "including $fl"
+                            if [file  exists $fl] {
+                                append newdata [getallincludes $fl]
+                            }
+                        }
+                    } else {
+                        append newdata [getallincludes $file]
+                    }
+                }
+            }
 	    }
 	    append data $newdata
 	    return $data
@@ -311,18 +316,19 @@
     regexp -line {^[^#]*(ServerRoot[\s]?[\"]?)([^\"]+)()([\"]?)} $confdata \
     match sub1 server_root_path sub2 
     foreach mod $needtoget {
+
     	# Look for LoadModule lines.
-	puts -nonewline "check conf line for $mod module..."
-	flush stdout
+        puts -nonewline "check conf line for $mod module..."
+        flush stdout
         if { ! [regexp -line "^\[^\#\]*(LoadModule\\s+$mod\\s+.+)\$"\
-                $confdata match line] } {
+                        $confdata match line] } {
             error "No LoadModule line for $mod\!"
         } else {
-	    puts ok
+            puts ok
 
-	    set raw_path [join [lrange [split $line { }] 2 end]]
-	    #trimming leading whitespaces
-	    set path [string trimleft $raw_path]
+            set raw_path [join [lrange [split $line { }] 2 end]]
+            #trimming leading whitespaces
+            set path [string trimleft $raw_path]
             if ![string equal [file pathtype $line] "absolute"] {
                 set absolute_path [file join $server_root_path $path]
                 lappend loadline "[join [lrange [split $line " "]  0 1]] $absolute_path"
@@ -342,20 +348,20 @@
     set conffile [gethttpdconf $binname]
 
     foreach {n k} [array get module_assoc] {
-	lappend needed $k
+        lappend needed $k
     }
     set needed [lsort $needed]
 
     set needtoget [list]
     foreach mod $needed {
-	if { [lsearch $compiledin $mod] == -1 } {
-	    lappend needtoget $mod
-	}
+        if { [lsearch $compiledin $mod] == -1 } {
+            lappend needtoget $mod
+        }
     }
     if { $needtoget == "" } {
-	return ""
+        return ""
     } else {
-	return [getloadmodules $conffile $needtoget]
+        return [getloadmodules $conffile $needtoget]
     }
 }
 
diff --git a/tests/binary.rvt b/tests/binary.rvt
index f78820d..83bddc0 100644
--- a/tests/binary.rvt
+++ b/tests/binary.rvt
@@ -1,6 +1,6 @@
 <?
-headers type "image/jpeg"
-if { [var exists test1] } {
+::rivet::headers type "image/jpeg"
+if { [::rivet::var exists test1] } {
     set fl [ open AngeloFish.jpg r ]
     fconfigure $fl -encoding binary
     fconfigure $fl -translation binary
@@ -11,6 +11,6 @@
     puts -nonewline [read $fl]
     close $fl
 } else {
-    include AngeloFish.jpg
+    ::rivet::include AngeloFish.jpg
 }
-?>
\ No newline at end of file
+?>
diff --git a/tests/binary.test b/tests/binary.test
index 7159114..307afa8 100644
--- a/tests/binary.test
+++ b/tests/binary.test
@@ -8,7 +8,7 @@
     set fl [open $binaryfile r]
     fconfigure $fl -translation binary
     fconfigure $fl -encoding binary
-    set ret [string equal -length 42746 [::http::data $page] [read $fl]]
+    set ret [string equal -length 42747 [::http::data $page] [read $fl]]
     close $fl
     set ret
 } 1
@@ -18,7 +18,7 @@
     set fl [open $binaryfile r]
     fconfigure $fl -translation binary
     fconfigure $fl -encoding binary
-    set ret [string equal -length 42746 [::http::data $page] [read $fl]]
+    set ret [string equal -length 42747 [::http::data $page] [read $fl]]
     close $fl
     set ret
 } 1
diff --git a/tests/broken.rvt b/tests/broken.rvt
index 0d5ada5..518af48 100644
--- a/tests/broken.rvt
+++ b/tests/broken.rvt
@@ -1,4 +1,4 @@
 <?
-# non-existant command
+# non-existent command
 broken
 ?>
diff --git a/tests/broken.test b/tests/broken.test
index c0c9f70..d2491ff 100644
--- a/tests/broken.test
+++ b/tests/broken.test
@@ -4,10 +4,10 @@
 
 ::tcltest::test broken-1.1 {error page test} {
     apachetest::start {} {} {
-	catch {
-	    set page [::http::geturl "${urlbase}$testfilename1"]
-	    set match [string trim [::http::data $page]]
-	}
+        catch {
+            set page [::http::geturl "${urlbase}$testfilename1"]
+            set match [string trim [::http::data $page]]
+        }
     }
     set match
 } {<PRE>
@@ -19,7 +19,7 @@
 "namespace eval request {
 puts -nonewline ""
 
-# non-existant command
+# non-existent command
 broken
 
 puts -nonewline "
@@ -30,7 +30,7 @@
 namespace eval request {
 puts -nonewline ""
 
-# non-existant command
+# non-existent command
 broken
 
 puts -nonewline "
diff --git a/tests/channel.rvt b/tests/channel.rvt
index 51e99a1..434652c 100644
--- a/tests/channel.rvt
+++ b/tests/channel.rvt
@@ -1,6 +1,6 @@
 HTML
 <?
-no_body
+::rivet::no_body
 puts "foo"
 ?>
 MORE HTML
@@ -15,4 +15,4 @@
 after 2000
 puts stdout baz
 ?>
-LAST HTML
\ No newline at end of file
+LAST HTML
diff --git a/tests/config.rvt b/tests/config.rvt
index 385b2f7..e3bde5a 100644
--- a/tests/config.rvt
+++ b/tests/config.rvt
@@ -1,8 +1,8 @@
 <?
-if { [var exists brokenpage] } {
+if { [::rivet::var exists brokenpage] } {
     # config-1.1
     broken
-} elseif { [var exists goodpage] } {
+} elseif { [::rivet::var exists goodpage] } {
     puts "Page Body"
 }
 ?>
\ No newline at end of file
diff --git a/tests/config.test b/tests/config.test
index 67bfee6..9e87b9b 100644
--- a/tests/config.test
+++ b/tests/config.test
@@ -4,13 +4,13 @@
 
 ::tcltest::test config-1.1 {ErrorScript config test} {
     apachetest::start {
-	-c "RivetUserConf ErrorScript 'puts \"Page broken\"'"
+	    -c "RivetUserConf ErrorScript 'puts \"Page broken\"'"
     } {} {
-	catch {
-	    set page [::http::geturl "${urlbase}$testfilename1?brokenpage"]
-	    set match [string trim [::http::data $page]]
-	    ::http::cleanup $page
-	}
+        catch {
+            set page [::http::geturl "${urlbase}$testfilename1?brokenpage"]
+            set match [string trim [::http::data $page]]
+            ::http::cleanup $page
+        }
     }
     set match
 } {Page broken}
@@ -19,11 +19,11 @@
     apachetest::start {
 	-c "RivetUserConf ErrorScript 'puts \"Page broken\"'" -c "AccessFileName test-htaccess"
     } {} {
-	catch {
-	    set page [::http::geturl "${urlbase}$testfilename1?brokenpage"]
-	    set match [string trim [::http::data $page]]
-	    ::http::cleanup $page
-	}
+        catch {
+            set page [::http::geturl "${urlbase}$testfilename1?brokenpage"]
+            set match [string trim [::http::data $page]]
+            ::http::cleanup $page
+        }
     }
     set match
 } {Local Page Header
@@ -34,19 +34,19 @@
     puts $fl {RivetUserConf BeforeScript 'puts "Local Page Header"'}
     close $fl
     apachetest::start { -c "AccessFileName htaccess2" } {} {
-	catch {
-	    set page [::http::geturl "${urlbase}$testfilename1?goodpage"]
-	    set match [string trim [::http::data $page]]
-	    ::http::cleanup $page
-	    # Now change what's in the ".htaccess" file, and see if it
-	    # picks it up.
-	    set fl [open htaccess2 w]
-	    puts $fl {RivetUserConf BeforeScript 'puts "New Local Page Header"'}
-	    close $fl
-	    set page [::http::geturl "${urlbase}$testfilename1?goodpage"]
-	    append match [string trim [::http::data $page]]
-	    ::http::cleanup $page
-	}
+        catch {
+            set page [::http::geturl "${urlbase}$testfilename1?goodpage"]
+            set match [string trim [::http::data $page]]
+            ::http::cleanup $page
+            # Now change what's in the ".htaccess" file, and see if it
+            # picks it up.
+            set fl [open htaccess2 w]
+            puts $fl {RivetUserConf BeforeScript 'puts "New Local Page Header"'}
+            close $fl
+            set page [::http::geturl "${urlbase}$testfilename1?goodpage"]
+            append match [string trim [::http::data $page]]
+            ::http::cleanup $page
+        }
     }
     set match
 } {Local Page Header
@@ -115,12 +115,12 @@
 foreach Config $ConfigList {
     incr i
     ::tcltest::test config-auto-${i}.1 {config test} {
-	apachetest::start $Config {} {
-	    catch {
-		set page [::http::geturl "${urlbase}$testfilename1?goodpage"]
-		set match [string trim [::http::data $page]]
-	    }
-	}
-	set match
+        apachetest::start $Config {} {
+            catch {
+                set page [::http::geturl "${urlbase}$testfilename1?goodpage"]
+                set match [string trim [::http::data $page]]
+            }
+        }
+        set match
     } [lindex $ResultList [expr $i - 1]]
 }
diff --git a/tests/cookies.rvt b/tests/cookies.rvt
index 81d6c1a..1939850 100644
--- a/tests/cookies.rvt
+++ b/tests/cookies.rvt
@@ -1,8 +1,8 @@
 <?
 
-load_cookies
+::rivet::load_cookies
 
-cookie set mod rivet -expires 01-01-2003
+::rivet::cookie set mod rivet -expires 01-01-2003
 
 if { [ array exists cookies ] } {
     foreach { ck } [ array names cookies ]  {
@@ -10,4 +10,4 @@
     }
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/tests/docroot1/afterscript.tcl b/tests/docroot1/afterscript.tcl
index 0c857b9..383fb69 100644
--- a/tests/docroot1/afterscript.tcl
+++ b/tests/docroot1/afterscript.tcl
@@ -2,4 +2,4 @@
 
 # $Id$
 
-puts "afterscript1<br>"
+puts -nonewline "afterscript1"
diff --git a/tests/docroot1/basic1.rvt b/tests/docroot1/basic1.rvt
new file mode 100644
index 0000000..8a42764
--- /dev/null
+++ b/tests/docroot1/basic1.rvt
@@ -0,0 +1 @@
+Virtual Host1 Test
diff --git a/tests/docroot1/beforescript.tcl b/tests/docroot1/beforescript.tcl
index b0dbab9..d462ecd 100644
--- a/tests/docroot1/beforescript.tcl
+++ b/tests/docroot1/beforescript.tcl
@@ -2,4 +2,5 @@
 
 # $Id$
 
-puts "beforescript1"
\ No newline at end of file
+set  ::beforescript1 1
+puts "beforescript1"
diff --git a/tests/docroot1/childinit.tcl b/tests/docroot1/childinit.tcl
index 8fa1995..108effb 100644
--- a/tests/docroot1/childinit.tcl
+++ b/tests/docroot1/childinit.tcl
@@ -2,4 +2,4 @@
 
 # $Id$
 
-set ::childinit1 1
\ No newline at end of file
+set ::childinit1 1
diff --git a/tests/docroot1/vhost1.rvt b/tests/docroot1/vhost1.rvt
index 3f9634d..1a85f2c 100644
--- a/tests/docroot1/vhost1.rvt
+++ b/tests/docroot1/vhost1.rvt
@@ -1,15 +1,13 @@
-Virtual Host1 Test
-
 <?
-set ::vhost1 1
-puts "vhost1 hello world<br>"
+if {[info exists ::childinit1]} {
+    puts "vhost1 hello world<br>"
+	puts "::childinit1 exists<br>"
 
-foreach var {
-    childinit1 childinit2 vhost1 vhost2
-} {
-    if { [info exists ::$var] } {
-	puts "$var exists<br>"
-    }
+} elseif {[info exists ::beforescript1]} {
+    ?>Virtual Host1 Test<?
+} 
+if {[info exists ::childinit2]} {
+	puts "::childinit2 exists<br>"
+
 }
-
 ?>
diff --git a/tests/docroot2/afterscript.tcl b/tests/docroot2/afterscript.tcl
index 2be6742..84ff27a 100644
--- a/tests/docroot2/afterscript.tcl
+++ b/tests/docroot2/afterscript.tcl
@@ -2,4 +2,4 @@
 
 # $Id$
 
-puts "afterscript2<br>"
+puts -nonewline "afterscript2"
diff --git a/tests/docroot2/basic2.rvt b/tests/docroot2/basic2.rvt
new file mode 100644
index 0000000..1b06708
--- /dev/null
+++ b/tests/docroot2/basic2.rvt
@@ -0,0 +1,2 @@
+Virtual Host2 Test
+
diff --git a/tests/docroot2/beforescript.tcl b/tests/docroot2/beforescript.tcl
index 7e99dd1..a1d563a 100644
--- a/tests/docroot2/beforescript.tcl
+++ b/tests/docroot2/beforescript.tcl
@@ -2,4 +2,5 @@
 
 # $Id$
 
+set  ::beforescript2 1
 puts "beforescript2"
diff --git a/tests/docroot2/vhost2.rvt b/tests/docroot2/vhost2.rvt
index a3b97ca..72bbdd6 100644
--- a/tests/docroot2/vhost2.rvt
+++ b/tests/docroot2/vhost2.rvt
@@ -1,15 +1,13 @@
-Virtual Host2 Test
-
 <?
-set ::vhost2 2
-puts "vhost2 hello world"
+if {[info exists ::childinit2]} {
+    puts "vhost2 hello world<br>"
+	puts "::childinit2 exists<br>"
 
-foreach var {
-    childinit1 childinit2 vhost1 vhost2
-} {
-    if { [info exists ::$var] } {
-	puts "$var exists<br>"
-    }
+} elseif {[info exists ::beforescript2]} {
+    ?>Virtual Host2 Test<?
 }
+if {[info exists ::childinit1]} {
+	puts "::childinit1 exists<br>"
 
+}
 ?>
diff --git a/tests/env.rvt b/tests/env.rvt
index 7887482..d039ce0 100644
--- a/tests/env.rvt
+++ b/tests/env.rvt
@@ -1,7 +1,7 @@
 <?
 
-load_env
+::rivet::load_env
 
 puts "env(DOCUMENT_NAME) = $env(DOCUMENT_NAME)\n"
 
-?>
\ No newline at end of file
+?>
diff --git a/tests/get.rvt b/tests/get.rvt
index df0ef5c..f235ad2 100644
--- a/tests/get.rvt
+++ b/tests/get.rvt
@@ -1,26 +1,26 @@
 <?
 
-if { [var number] > 0 } {
-    if { [var exists foobar] } {
-	puts "\[var get foobar\] = [var get foobar]\n"
-	puts "\[var_qs get foobar\] = [var_qs get foobar]\n"
+if { [::rivet::var number] > 0 } {
+    if { [::rivet::var exists foobar] } {
+        puts "\[::rivet::var get foobar\] = [::rivet::var get foobar]\n"
+        puts "\[::rivet::var_qs get foobar\] = [::rivet::var_qs get foobar]\n"
     }
-    if { [var exists xst] } {
-	puts "\[var exists xst\]\[var exists noxst\] = [var exists xst] [var exists noxst]\n"
-	puts "\[var_qs exists xst\]\[var_qs exists noxst\] = [var_qs exists xst] [var_qs exists noxst]\n"
+    if { [::rivet::var exists xst] } {
+        puts "\[::rivet::var exists xst\]\[::rivet::var exists noxst\] = [::rivet::var exists xst] [::rivet::var exists noxst]\n"
+        puts "\[::rivet::var_qs exists xst\]\[::rivet::var_qs exists noxst\] = [::rivet::var_qs exists xst] [::rivet::var_qs exists noxst]\n"
     }
-    if { [var exists Más] } {
-	puts "\[var get Más\] = [var get Más]\n"
+    if { [::rivet::var exists Más] } {
+        puts "\[::rivet::var get Más\] = [::rivet::var get Más]\n"
     }
-    if { [var exists lstvar1] } {
-	puts "\[var get lstvar1\] = [var get lstvar1]\n"
+    if { [::rivet::var exists lstvar1] } {
+        puts "\[::rivet::var get lstvar1\] = [::rivet::var get lstvar1]\n"
     }
-    if { [var exists lstvar2] } {
-	puts "\[var list lstvar2\] = [var list lstvar2]\n"
+    if { [::rivet::var exists lstvar2] } {
+        puts "\[::rivet::var list lstvar2\] = [::rivet::var list lstvar2]\n"
     }
-    puts "\[var get xst foo\] = [var get xst foo]"
+    puts "\[::rivet::var get xst foo\] = [::rivet::var get xst foo]"
 } else {
-    puts "\[var get xst\] = [var get xst]"
+    puts "\[::rivet::var get xst\] = [::rivet::var get xst]"
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/tests/get.test b/tests/get.test
index e365129..96e2430 100644
--- a/tests/get.test
+++ b/tests/get.test
@@ -2,60 +2,60 @@
 
 ::tcltest::test getvariables-1.1 {GET variables} {
     set page [ ::http::geturl "${urlbase}get.rvt?foobar=goober" ]
-    regexp -line {\[var get foobar\] = goober$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var get foobar\] = goober$} [ ::http::data $page ] match
     set match
-} {[var get foobar] = goober}
+} {[::rivet::var get foobar] = goober}
 
 ::tcltest::test getvariables-1.2 {GET variables - exists} {
     set page [ ::http::geturl "${urlbase}get.rvt?xst=1" ]
-    regexp -line {\[var exists xst\]\[var exists noxst\] = 1 0$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var exists xst\]\[::rivet::var exists noxst\] = 1 0$} [ ::http::data $page ] match
     set match
-} {[var exists xst][var exists noxst] = 1 0}
+} {[::rivet::var exists xst][::rivet::var exists noxst] = 1 0}
 
 ::tcltest::test getvariables-1.3 {GET variables - doesn't exist} {
     set page [ ::http::geturl "${urlbase}get.rvt" ]
-    regexp -line {\[var get xst\] = } [ ::http::data $page ] match
+    regexp -line {\[::rivet::var get xst\] = } [ ::http::data $page ] match
     set match
-} {[var get xst] = }
+} {[::rivet::var get xst] = }
 
 ::tcltest::test getvariables-1.4 {GET variables - default value} {
     set page [ ::http::geturl "${urlbase}get.rvt?defaulttest=1" ]
-    regexp {^\[var get xst foo\] = foo} [ ::http::data $page ] match
+    regexp {^\[::rivet::var get xst foo\] = foo} [ ::http::data $page ] match
     set match
-} {[var get xst foo] = foo}
+} {[::rivet::var get xst foo] = foo}
 
 ::tcltest::test getvariables-1.5 {GET variables - var_qs exists} {
     set page [ ::http::geturl "${urlbase}get.rvt?xst=1" ]
-    regexp -line {\[var_qs exists xst\]\[var_qs exists noxst\] = 1 0$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var_qs exists xst\]\[::rivet::var_qs exists noxst\] = 1 0$} [ ::http::data $page ] match
     set match
-} {[var_qs exists xst][var_qs exists noxst] = 1 0}
+} {[::rivet::var_qs exists xst][::rivet::var_qs exists noxst] = 1 0}
 
 ::tcltest::test getvariables-2.1 {GET variables + I18N} {
     set page [ ::http::geturl "${urlbase}get.rvt?Más=Tú" ]
-    regexp -line {^\[var get Más\] = Tú$} [ ::http::data $page ] match
+    regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
-} {[var get Más] = Tú}
+} {[::rivet::var get Más] = Tú}
 
 ::tcltest::test getvariables-2.2 {GET variables + I18N + encoding} {
     set page [ ::http::geturl [ format "${urlbase}get.rvt?%s" [ ::http::formatQuery Más Tú ] ] ]
-    regexp -line {^\[var get Más\] = Tú$} [ ::http::data $page ] match
+    regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
-} {[var get Más] = Tú}
+} {[::rivet::var get Más] = Tú}
 
 ::tcltest::test getvariables-3.1 {GET multi-value variable} {
     set page [ ::http::geturl "${urlbase}get.rvt?lstvar1=a&lstvar1=b&lstvar1=c+d" ]
-    regexp -line {\[var get lstvar1\] = a b c d$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var get lstvar1\] = a b c d$} [ ::http::data $page ] match
     set match
-} {[var get lstvar1] = a b c d}
+} {[::rivet::var get lstvar1] = a b c d}
 
 ::tcltest::test getvariables-3.2 {GET multi-value variable as list} {
     set page [ ::http::geturl "${urlbase}get.rvt?lstvar2=a&lstvar2=b&lstvar2=c+d" ]
-    regexp -line {\[var list lstvar2\] = a b {c d}$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var list lstvar2\] = a b {c d}$} [ ::http::data $page ] match
     set match
-} {[var list lstvar2] = a b {c d}}
+} {[::rivet::var list lstvar2] = a b {c d}}
 
 ::tcltest::test getvariables-4.1 {var_qs} {
     set page [ ::http::geturl "${urlbase}get.rvt?foobar=goober" ]
-    regexp -line {\[var_qs get foobar\] = goober$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var_qs get foobar\] = goober$} [::http::data $page] match
     set match
-} {[var_qs get foobar] = goober}
+} {[::rivet::var_qs get foobar] = goober}
diff --git a/tests/headers.rvt b/tests/headers.rvt
index 13f80e6..1489029 100644
--- a/tests/headers.rvt
+++ b/tests/headers.rvt
@@ -9,7 +9,7 @@
 
 <?
 
-load_headers hdrs
+::rivet::load_headers hdrs
 parray hdrs
 
 ?>
diff --git a/tests/headers.test b/tests/headers.test
index 287e756..698ee2f 100644
--- a/tests/headers.test
+++ b/tests/headers.test
@@ -14,4 +14,4 @@
     set match [string trim $match]
     ::http::cleanup $page
     set match
-} $result
\ No newline at end of file
+} $result
diff --git a/tests/include.html b/tests/include.html
index 213a7ff..f18b8fa 100644
--- a/tests/include.html
+++ b/tests/include.html
@@ -1,11 +1,11 @@
     <table>
       <tbody>
-	<tr>
-	  <td>row 1</td>
-	</tr>
-	<tr>
-	  <td>row 2</td>
-	</tr>
+    <tr>
+      <td>row 1</td>
+    </tr>
+    <tr>
+      <td>row 2</td>
+    </tr>
       </tbody>
     </table>
 <p>ÆüËܸì(EUC-JP Japanese text)</p>
\ No newline at end of file
diff --git a/tests/include.rvt b/tests/include.rvt
index d8b2a69..c837f48 100644
--- a/tests/include.rvt
+++ b/tests/include.rvt
@@ -1,11 +1,9 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
-  <head>
-    <title>Include Test</title>
-  </head>
+  <head><title>Include Test</title></head>
 
   <body>
     <h1>Include Test</h1>
-    <? include include.html ?>
+    <? ::rivet::include include.html ?>
   </body>
 </html>
\ No newline at end of file
diff --git a/tests/include.test b/tests/include.test
index 1161c73..386b29c 100644
--- a/tests/include.test
+++ b/tests/include.test
@@ -7,20 +7,18 @@
     ::http::data $page
 } {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
-  <head>
-    <title>Include Test</title>
-  </head>
+  <head><title>Include Test</title></head>
 
   <body>
     <h1>Include Test</h1>
         <table>
       <tbody>
-	<tr>
-	  <td>row 1</td>
-	</tr>
-	<tr>
-	  <td>row 2</td>
-	</tr>
+    <tr>
+      <td>row 1</td>
+    </tr>
+    <tr>
+      <td>row 2</td>
+    </tr>
       </tbody>
     </table>
 <p>ÆüËܸì(EUC-JP Japanese text)</p>
diff --git a/tests/lang.test b/tests/lang.test
index 04ab8a3..13a0d68 100644
--- a/tests/lang.test
+++ b/tests/lang.test
@@ -7,24 +7,22 @@
     set testfilename1 include.rvt
 
     ::tcltest::test lang-1.1 {"include" with LANG} {
-	set page [ ::http::geturl "${urlbase}$testfilename1" ]
-	::http::data $page
+    set page [ ::http::geturl "${urlbase}$testfilename1" ]
+    ::http::data $page
     } {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
-  <head>
-    <title>Include Test</title>
-  </head>
+  <head><title>Include Test</title></head>
 
   <body>
     <h1>Include Test</h1>
         <table>
       <tbody>
-	<tr>
-	  <td>row 1</td>
-	</tr>
-	<tr>
-	  <td>row 2</td>
-	</tr>
+    <tr>
+      <td>row 1</td>
+    </tr>
+    <tr>
+      <td>row 2</td>
+    </tr>
       </tbody>
     </table>
 <p>ÆüËܸì(EUC-JP Japanese text)</p>
@@ -34,8 +32,8 @@
     set testfilename1 parse.rvt
 
     ::tcltest::test parse-1.1 {Parse command} {
-	set page [ ::http::geturl "${urlbase}$testfilename1" ]
-	::http::data $page
+    set page [ ::http::geturl "${urlbase}$testfilename1" ]
+    ::http::data $page
     } {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
   <head>
diff --git a/tests/makeurl.rvt b/tests/makeurl.rvt
index 1b69b66..41b89c2 100644
--- a/tests/makeurl.rvt
+++ b/tests/makeurl.rvt
@@ -1,6 +1,25 @@
 <?
 
-# makeurl-1.1
-puts [makeurl /foo]
+    if {[::rivet::var exists urltype]} {
 
-?>
\ No newline at end of file
+        switch [::rivet::var get urltype] {
+
+            absolute {
+# makeurl-1.1
+                puts [::rivet::makeurl /foo]
+            }
+
+            relative {
+# makeurl-1.2
+                puts [::rivet::makeurl foo/]
+
+            }
+            
+        }
+    } else {
+
+# makeurl-1.3
+        puts [::rivet::makeurl]
+
+    }
+?>
diff --git a/tests/makeurl.test b/tests/makeurl.test
index d242abb..f07b9c8 100644
--- a/tests/makeurl.test
+++ b/tests/makeurl.test
@@ -3,8 +3,20 @@
 set testfilename1 makeurl.rvt
 
 ::tcltest::test makeurl-1.1 {makeurl} {
-    set page [ ::http::geturl "${urlbase}$testfilename1" ]
+    set page [ ::http::geturl "${urlbase}${testfilename1}?urltype=absolute" ]
     set match [string trim [ ::http::data $page ]]
     set match
 } {http://localhost:8081/foo}
 
+::tcltest::test makeurl-1.2 {makeurl} {
+    set page [ ::http::geturl "${urlbase}${testfilename1}?urltype=relative" ]
+    set match [string trim [ ::http::data $page ]]
+    set match
+} {http://localhost:8081/makeurl.rvt/foo/}
+
+::tcltest::test makeurl-1.3 {makeurl} {
+    set page [ ::http::geturl "${urlbase}${testfilename1}" ]
+    set match [string trim [ ::http::data $page ]]
+    set match
+} {http://localhost:8081/makeurl.rvt}
+
diff --git a/tests/parse.rvt b/tests/parse.rvt
index 922bc11..4ce0313 100644
--- a/tests/parse.rvt
+++ b/tests/parse.rvt
@@ -6,6 +6,6 @@
 
   <body>
     <h1>Parse Test</h1>
-    <? parse hello.rvt ?>
+    <? ::rivet::parse hello.rvt ?>
   </body>
 </html>
\ No newline at end of file
diff --git a/tests/post.rvt b/tests/post.rvt
index fc45201..1257750 100644
--- a/tests/post.rvt
+++ b/tests/post.rvt
@@ -1,21 +1,21 @@
 <?
 
-if { [ var number ] > 0 } {
+if { [ ::rivet::var number ] > 0 } {
     # get/post variables 1.1
-    if { [ var exists foobar ] } {
-	puts "\[var get foobar\] = [var get foobar]\n"
-	puts "\[var_post get foobar\] = [var_post get foobar]\n"
+    if { [ ::rivet::var exists foobar ] } {
+        puts "\[::rivet::var get foobar\] = [::rivet::var get foobar]\n"
+        puts "\[::rivet::var_post get foobar\] = [::rivet::var_post get foobar]\n"
     }
     # get/post variables 1.{2,3}
-    if { [ var exists Más ] } {
-	puts "\[var get Más\] = [var get Más]\n"
+    if { [ ::rivet::var exists Más ] } {
+        puts "\[::rivet::var get Más\] = [::rivet::var get Más]\n"
     }
-    if { [var exists lstvar1] } {
-	puts "\[var get lstvar1\] = [var get lstvar1]\n"
+    if { [::rivet::var exists lstvar1] } {
+        puts "\[::rivet::var get lstvar1\] = [::rivet::var get lstvar1]\n"
     }
-    if { [var exists lstvar2] } {
-	puts "\[var list lstvar2\] = [var list lstvar2]\n"
+    if { [::rivet::var exists lstvar2] } {
+        puts "\[::rivet::var list lstvar2\] = [::rivet::var list lstvar2]\n"
     }
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/tests/post.test b/tests/post.test
index a7392b8..77e9bf8 100644
--- a/tests/post.test
+++ b/tests/post.test
@@ -4,36 +4,36 @@
 
 ::tcltest::test postvariables-1.1 {POST variables} {
     set page [ ::http::geturl "${urlbase}$testfilename1" -query foobar=goober ]
-    regexp -line {^\[var get foobar\] = goober$} [ ::http::data $page ] match
+    regexp -line {^\[::rivet::var get foobar\] = goober$} [ ::http::data $page ] match
     set match
-} {[var get foobar] = goober}
+} {[::rivet::var get foobar] = goober}
 
 ::tcltest::test postvariables-2.1 {POST variables + I18N} {
     set page [ ::http::geturl "${urlbase}$testfilename1" -query Más=Tú ]
-    regexp -line {^\[var get Más\] = Tú$} [ ::http::data $page ] match
+    regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
-} {[var get Más] = Tú}
+} {[::rivet::var get Más] = Tú}
 
 ::tcltest::test postvariables-2.2 {POST variables + I18N + encoding} {
     set page [ ::http::geturl "${urlbase}$testfilename1" -query [ ::http::formatQuery Más Tú ] ]
-    regexp -line {^\[var get Más\] = Tú$} [ ::http::data $page ] match
+    regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
-} {[var get Más] = Tú}
+} {[::rivet::var get Más] = Tú}
 
 ::tcltest::test postvariables-3.1 {POST multi-value variable} {
     set page [ ::http::geturl "${urlbase}get.rvt" -query [::http::formatQuery lstvar1 a lstvar1 b lstvar1 {c d}]]
-    regexp -line {\[var get lstvar1\] = a b c d$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var get lstvar1\] = a b c d$} [ ::http::data $page ] match
     set match
-} {[var get lstvar1] = a b c d}
+} {[::rivet::var get lstvar1] = a b c d}
 
 ::tcltest::test postvariables-3.2 {POST multi-value variable as list} {
     set page [ ::http::geturl "${urlbase}get.rvt" -query [::http::formatQuery lstvar2 a lstvar2 b lstvar2 {c d}]]
-    regexp -line {\[var list lstvar2\] = a b {c d}$} [ ::http::data $page ] match
+    regexp -line {\[::rivet::var list lstvar2\] = a b {c d}$} [ ::http::data $page ] match
     set match
-} {[var list lstvar2] = a b {c d}}
+} {[::rivet::var list lstvar2] = a b {c d}}
 
 ::tcltest::test postvariables-4.1 {var_post} {
     set page [ ::http::geturl "${urlbase}$testfilename1" -query foobar=goober ]
-    regexp -line {^\[var_post get foobar\] = goober$} [ ::http::data $page ] match
+    regexp -line {^\[::rivet::var_post get foobar\] = goober$} [ ::http::data $page ] match
     set match
-} {[var_post get foobar] = goober}
+} {[::rivet::var_post get foobar] = goober}
diff --git a/tests/rivet.test b/tests/rivet.test
index f512255..7961086 100755
--- a/tests/rivet.test
+++ b/tests/rivet.test
@@ -32,11 +32,11 @@
     puts -nonewline "Running all tests against one server process."
     flush stdout
     apachetest::start {} {} {
-	foreach Test $TestList {
-	    puts -nonewline "."
-	    flush stdout
-	    source $Test
-	}
+        foreach Test $TestList {
+            puts -nonewline "."
+            flush stdout
+            source $Test
+        }
     }
     puts " done"
 }
@@ -45,10 +45,10 @@
 
 if { $testgroup2 } {
     foreach Test $TestList {
-	apachetest::start {} {} {
-	    puts "Running $Test"
-	    source $Test
-	}
+        apachetest::start {} {} {
+            puts "Running $Test"
+            source $Test
+        }
     }
 }
 
@@ -58,15 +58,16 @@
 
 if { $testgroup3 } {
     foreach Test {
-	broken.test
-	config.test
-	lang.test
-	parsepackage.test
-	virtualhost.test
+        broken.test
+        config.test
+        lang.test
+        parsepackage.test
+        virtualhost.test
     } {
-	puts "Running $Test"
-	source $Test
+        puts "Running $Test"
+        source $Test
     }
 }
 
 ::tcltest::cleanupTests
+
diff --git a/tests/runtests.tcl b/tests/runtests.tcl
index b9d9a5d..38aa6cc 100755
--- a/tests/runtests.tcl
+++ b/tests/runtests.tcl
@@ -50,9 +50,9 @@
 
 if { [encoding system] eq "utf-8" } {
     puts stderr {
-	System encoding is utf-8 - this is known to cause problems
-	with the test environment!  Continuing with tests in 5 seconds
-	using the iso8859-1 encoding.
+        System encoding is utf-8 - this is known to cause problems
+        with the test environment!  Continuing with tests in 5 seconds
+        using the iso8859-1 encoding.
     }
     after 5000
 }
@@ -68,11 +68,11 @@
 if {$httpd_version == 1} {
 	apachetest::need_modules {
 		{mod_log_config		config_log_module}
-		{mod_mime		mime_module}
+		{mod_mime		    mime_module}
 		{mod_negotiation	negotiation_module}
-		{mod_dir		dir_module}
-		{mod_auth		auth_module}
-		{mod_access		access_module}
+		{mod_dir		    dir_module}
+		{mod_auth		    auth_module}
+		{mod_access		    access_module}
 	}
 } else {
 	apachetest::need_modules {
@@ -129,10 +129,10 @@
 
 switch -exact -- [lindex $argv 1] {
     startserver {
-	apachetest::startserver
+	    apachetest::startserver
     }
     default {
-	set argv [lrange $argv 1 end]
-	source [file join . rivet.test]
+        set argv [lrange $argv 1 end]
+        source [file join . rivet.test]
     }
 }
diff --git a/tests/upload.rvt b/tests/upload.rvt
index 665ef26..5e84818 100644
--- a/tests/upload.rvt
+++ b/tests/upload.rvt
@@ -1,2 +1 @@
-<? puts "[upload names] [upload exists uploadtest] [upload size uploadtest] -[upload type uploadtest]- [upload filename uploadtest]" ?>
-
+<? puts "[::rivet::upload names] [::rivet::upload exists uploadtest] [::rivet::upload size uploadtest] -[::rivet::upload type uploadtest]- [::rivet::upload filename uploadtest]" ?>
diff --git a/tests/uploadsave.rvt b/tests/uploadsave.rvt
index d9c505b..e64a785 100644
--- a/tests/uploadsave.rvt
+++ b/tests/uploadsave.rvt
@@ -1,3 +1,3 @@
 <?
-upload save [upload names] uploadedjpeg.jpg
-?>
\ No newline at end of file
+::rivet::upload save [::rivet::upload names] uploadedjpeg.jpg
+?>
diff --git a/tests/virtualhost.test b/tests/virtualhost.test
index 3c17c18..6061baf 100644
--- a/tests/virtualhost.test
+++ b/tests/virtualhost.test
@@ -22,15 +22,15 @@
 
 ::tcltest::test vhost-1.1 {basic virtual host} {
     apachetest::start {} $vhostconf {
-	set page1 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
-	set page2 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
-	set match1 [::http::data $page1]
-	set match2 [::http::data $page2]
-	::http::cleanup $page1
-	::http::cleanup $page2
+        set page1 [::http::geturl "${urlbase}basic1.rvt" -headers [list Host vhost1]]
+        set page2 [::http::geturl "${urlbase}basic2.rvt" -headers [list Host vhost2]]
+        set match1 [::http::data $page1]
+        set match2 [::http::data $page2]
+        ::http::cleanup $page1
+        ::http::cleanup $page2
     }
     list [string match {Virtual Host1 Test*} $match1] \
-	[string match {Virtual Host2 Test*} $match2]
+	     [string match {Virtual Host2 Test*} $match2]
 } {1 1}
 
 # Try virtual hosts with and without a childinitscript.
@@ -38,28 +38,28 @@
 ::tcltest::test vhost-2.1 {virtual host w/ ChildInitScript} {
     set data {}
     apachetest::start {} {
-	RivetServerConf ChildInitScript "source [file join $docroot1 childinit.tcl]"
-	NameVirtualHost 127.0.0.1
-	<VirtualHost 127.0.0.1>
-	DocumentRoot $docroot1
-	ServerName vhost1
-	</VirtualHost>
+        RivetServerConf SeparateVirtualInterps off
+        RivetServerConf ChildInitScript "source [file join $docroot1 childinit.tcl]"
+        NameVirtualHost 127.0.0.1
+        <VirtualHost 127.0.0.1>
+            DocumentRoot $docroot1
+            ServerName vhost1
+        </VirtualHost>
 
-	<VirtualHost 127.0.0.1>
-	RivetServerConf ChildInitScript "source [file join $docroot2 childinit.tcl]"
-	DocumentRoot $docroot2
-	ServerName vhost2
-	</VirtualHost>
+        <VirtualHost 127.0.0.1>
+            RivetServerConf ChildInitScript "source [file join $docroot2 childinit.tcl]"
+            DocumentRoot $docroot2
+            ServerName vhost2
+        </VirtualHost>
     } {
-	set page {}
-	lappend page [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
-	lappend page [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
-	foreach p $page {
-	    lappend data [::http::data $p]
-	    ::http::cleanup $p
-	}
+        set page2 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
+        set page1 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
+        set data "[::http::data $page1][::http::data $page2]"
+        ::http::cleanup $page1
+        ::http::cleanup $page2
     }
-    regexp "childinit1 exists.*childinit2 exists" $data match
+#   puts ">>>$data<<<"
+    regexp "::childinit1 exists.*::childinit2 exists" $data match
 } 1
 
 # Test out a ChildInitScript that is only in a vhost.
@@ -69,26 +69,26 @@
     apachetest::start {} {
 	NameVirtualHost 127.0.0.1
 	<VirtualHost 127.0.0.1>
-	DocumentRoot $docroot1
-	ServerName vhost1
+        DocumentRoot $docroot1
+        ServerName vhost1
 	</VirtualHost>
 
 	<VirtualHost 127.0.0.1>
-	RivetServerConf ChildInitScript "source [file join $docroot2 childinit.tcl]"
-	DocumentRoot $docroot2
-	ServerName vhost2
+        RivetServerConf ChildInitScript "source [file join $docroot2 childinit.tcl]"
+        DocumentRoot $docroot2
+        ServerName vhost2
 	</VirtualHost>
     } {
-	set page {}
-	lappend page [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
-	lappend page [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
-	foreach p $page {
-	    lappend data [::http::data $p]
-	    ::http::cleanup $p
-	}
+        set page {}
+        lappend page [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
+        lappend page [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
+        foreach p $page {
+            lappend data [::http::data $p]
+            ::http::cleanup $p
+        }
     }
-    regexp "vhost2 hello world\nchildinit2 exists" $data match
-#    set data
+#   set data
+    regexp "vhost2 hello world<br>\n::childinit2 exists<br>" $data match
 } 1
 
 # Test out a beforescript in a virtual host.
@@ -109,16 +109,15 @@
 	ServerName vhost2
 	</VirtualHost>
     } {
-	set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
-	set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
-	set data1 [::http::data $page1]
-	set data2 [::http::data $page2]
-	::http::cleanup $page1
-	::http::cleanup $page2
+        set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
+        set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
+        set data1 [::http::data $page1]
+        set data2 [::http::data $page2]
+        ::http::cleanup $page1
+        ::http::cleanup $page2
     }
-    list \
-	[regexp "^beforescript2\nVirtual Host2 Test" $data1 match] \
-	[regexp "^beforescript1\nVirtual Host1 Test" $data2 match]
+    list [regexp "^beforescript2\nVirtual Host2 Test" $data1 match] \
+	     [regexp "^beforescript1\nVirtual Host1 Test" $data2 match]
 #    list $data1 $data2
 } {1 1}
 
@@ -128,28 +127,32 @@
 ::tcltest::test vhost-4.1 {virtual host w/ separate interps} {
     set data {}
     apachetest::start {} {
-	RivetServerConf SeparateVirtualInterps on
-	NameVirtualHost 127.0.0.1
-	<VirtualHost 127.0.0.1>
-	DocumentRoot $docroot1
-	ServerName vhost1
-	</VirtualHost>
+        RivetServerConf SeparateVirtualInterps on
+        NameVirtualHost 127.0.0.1
+        <VirtualHost 127.0.0.1>
+            RivetServerConf ChildInitScript "set ::childinit1 1"
+            DocumentRoot $docroot1
+            ServerName vhost1
+        </VirtualHost>
 
-	<VirtualHost 127.0.0.1>
-	DocumentRoot $docroot2
-	ServerName vhost2
-	</VirtualHost>
+        <VirtualHost 127.0.0.1>
+            RivetServerConf ChildInitScript "set ::childinit2 1"
+            DocumentRoot $docroot2
+            ServerName vhost2
+        </VirtualHost>
     } {
-	set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
-	set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
-	set data1 [::http::data $page1]
-	set data2 [::http::data $page2]
-	::http::cleanup $page1
-	::http::cleanup $page2
+        set page1 [::http::geturl "${urlbase}vhost2.rvt" -headers [list Host vhost2]]
+        set page2 [::http::geturl "${urlbase}vhost1.rvt" -headers [list Host vhost1]]
+        set data1 [::http::data $page1]
+        set data2 [::http::data $page2]
+        ::http::cleanup $page1
+        ::http::cleanup $page2
     }
+#   puts "--$data1--"
+#   puts "--$data2--"
     list \
-	[regexp "vhost2 hello world\nvhost2 exists<br>" $data1 match] \
-	[regexp "vhost1 hello world<br>\nvhost1 exists<br>" $data2 match]
+	[regexp "vhost2 hello world<br>\n::childinit2 exists<br>" $data1 match] \
+	[regexp "vhost1 hello world<br>\n::childinit1 exists<br>" $data2 match]
 #    list $data1 $data2
 } {1 1}
 
@@ -158,7 +161,8 @@
 
 # Format: directive, file, 2 regexps to match
 set configs {
-    ChildInitScript childinit.tcl "childinit1 exists<br>\nchildinit2 exists<br>" "childinit1 exists<br>\nchildinit2 exists<br>"
+    ChildInitScript childinit.tcl "vhost2 hello world<br>\n::childinit2 exists<br>\n::childinit1 exists<br>\n" \
+                                  "vhost1 hello world<br>\n::childinit1 exists<br>\n::childinit2 exists<br>"
     BeforeScript beforescript.tcl "^beforescript2\nVirtual Host2 Test" "^beforescript1\nVirtual Host1 Test"
     AfterScript afterscript.tcl "afterscript2" "afterscript1"
 }
@@ -167,6 +171,7 @@
 foreach {conf file re1 re2} $configs {
     ::tcltest::test vhost-5.$i [list vhost with $conf] {
 	apachetest::start {} "
+RivetServerConf SeparateVirtualInterps off
 RivetServerConf $conf \"source [file join $docroot1 $file]\"
 NameVirtualHost 127.0.0.1
 <VirtualHost 127.0.0.1>
@@ -187,13 +192,16 @@
 	::http::cleanup $page1
 	::http::cleanup $page2
 }
+#puts "--$re1--\n--$data1--"
+#puts "--$re2--\n--$data2--"
+
 list [regexp $re1 $data1 match] [regexp $re1 $data1 match]
 #list $data1 $data2
     } {1 1}
 }
 
 set configs {
-    ChildInitScript childinit.tcl "vhost2 hello world\nchildinit2 exists<br>\nvhost2 exists<br>" "vhost1 hello world<br>\nvhost1 exists<br>"
+    ChildInitScript childinit.tcl "vhost2 hello world<br>\n::childinit2 exists<br>\n" "vhost1 hello world<br>\n::childinit1 exists<br>\n"
     BeforeScript beforescript.tcl "^beforescript2\nVirtual Host2 Test" "^beforescript1\nVirtual Host1 Test"
     AfterScript afterscript.tcl "afterscript2" "afterscript1"
 }
@@ -225,8 +233,10 @@
 	::http::cleanup $page1
 	::http::cleanup $page2
 }
+#puts "--$re1--\n--$data1--"
+#puts "--$re2--\n--$data2--"
+
 list [regexp $re1 $data1 match] [regexp $re1 $data1 match]
-#list $data1 $data2
     } {1 1}
 
 incr i