[117084] branches/new-help-system/base

raimue at macports.org raimue at macports.org
Sat Feb 15 06:35:04 PST 2014


Revision: 117084
          https://trac.macports.org/changeset/117084
Author:   raimue at macports.org
Date:     2014-02-15 06:35:04 -0800 (Sat, 15 Feb 2014)
Log Message:
-----------
Merge from trunk

Modified Paths:
--------------
    branches/new-help-system/base/ChangeLog
    branches/new-help-system/base/HACKING
    branches/new-help-system/base/Mk/macports.autoconf.mk.in
    branches/new-help-system/base/aclocal.m4
    branches/new-help-system/base/config/RELEASE_URL
    branches/new-help-system/base/configure
    branches/new-help-system/base/configure.ac
    branches/new-help-system/base/doc/portfile.7
    branches/new-help-system/base/portmgr/ReleaseProcess
    branches/new-help-system/base/portmgr/autosubmit.tcl
    branches/new-help-system/base/portmgr/jobs/PortIndex2MySQL.tcl
    branches/new-help-system/base/portmgr/jobs/mprsyncup
    branches/new-help-system/base/portmgr/jobs/port_binary_distributable.tcl
    branches/new-help-system/base/portmgr/packaging/dpkgall.tcl
    branches/new-help-system/base/portmgr/packaging/mpkgall.tcl
    branches/new-help-system/base/portmgr/packaging/packageall.tcl
    branches/new-help-system/base/portmgr/packaging/rpmall.tcl
    branches/new-help-system/base/src/Makefile.in
    branches/new-help-system/base/src/config.h.in
    branches/new-help-system/base/src/cregistry/file.c
    branches/new-help-system/base/src/cregistry/registry.c
    branches/new-help-system/base/src/cregistry/util.c
    branches/new-help-system/base/src/cregistry/vercomp.c
    branches/new-help-system/base/src/darwintracelib1.0/Makefile
    branches/new-help-system/base/src/darwintracelib1.0/darwintrace.c
    branches/new-help-system/base/src/images_to_archives.tcl
    branches/new-help-system/base/src/machista1.0/libmachista.c
    branches/new-help-system/base/src/machista1.0/tests/test.tcl
    branches/new-help-system/base/src/macports1.0/Makefile
    branches/new-help-system/base/src/macports1.0/get_systemconfiguration_proxies.c
    branches/new-help-system/base/src/macports1.0/macports.tcl
    branches/new-help-system/base/src/macports1.0/macports_autoconf.tcl.in
    branches/new-help-system/base/src/macports1.0/macports_dlist.tcl
    branches/new-help-system/base/src/macports1.0/macports_util.tcl
    branches/new-help-system/base/src/package1.0/Makefile
    branches/new-help-system/base/src/package1.0/portarchivefetch.tcl
    branches/new-help-system/base/src/package1.0/portdmg.tcl
    branches/new-help-system/base/src/package1.0/portdpkg.tcl
    branches/new-help-system/base/src/package1.0/portmdmg.tcl
    branches/new-help-system/base/src/package1.0/portmpkg.tcl
    branches/new-help-system/base/src/package1.0/portpkg.tcl
    branches/new-help-system/base/src/package1.0/portrpm.tcl
    branches/new-help-system/base/src/package1.0/portsrpm.tcl
    branches/new-help-system/base/src/package1.0/portunarchive.tcl
    branches/new-help-system/base/src/pextlib1.0/Makefile.in
    branches/new-help-system/base/src/pextlib1.0/Pextlib.c
    branches/new-help-system/base/src/pextlib1.0/curl.c
    branches/new-help-system/base/src/pextlib1.0/filemap.c
    branches/new-help-system/base/src/pextlib1.0/strsed.c
    branches/new-help-system/base/src/pextlib1.0/system.c
    branches/new-help-system/base/src/pextlib1.0/tests/filemap.tcl
    branches/new-help-system/base/src/pextlib1.0/tests/fs-traverse.tcl
    branches/new-help-system/base/src/pextlib1.0/tracelib.c
    branches/new-help-system/base/src/port/port.tcl
    branches/new-help-system/base/src/port/portindex.tcl
    branches/new-help-system/base/src/port/portmirror.tcl
    branches/new-help-system/base/src/port1.0/Makefile
    branches/new-help-system/base/src/port1.0/fetch_common.tcl
    branches/new-help-system/base/src/port1.0/portactivate.tcl
    branches/new-help-system/base/src/port1.0/portbuild.tcl
    branches/new-help-system/base/src/port1.0/portchecksum.tcl
    branches/new-help-system/base/src/port1.0/portclean.tcl
    branches/new-help-system/base/src/port1.0/portconfigure.tcl
    branches/new-help-system/base/src/port1.0/portdestroot.tcl
    branches/new-help-system/base/src/port1.0/portdistcheck.tcl
    branches/new-help-system/base/src/port1.0/portdistfiles.tcl
    branches/new-help-system/base/src/port1.0/portextract.tcl
    branches/new-help-system/base/src/port1.0/portfetch.tcl
    branches/new-help-system/base/src/port1.0/portinstall.tcl
    branches/new-help-system/base/src/port1.0/portlint.tcl
    branches/new-help-system/base/src/port1.0/portlivecheck.tcl
    branches/new-help-system/base/src/port1.0/portload.tcl
    branches/new-help-system/base/src/port1.0/portmain.tcl
    branches/new-help-system/base/src/port1.0/portmirror.tcl
    branches/new-help-system/base/src/port1.0/portpatch.tcl
    branches/new-help-system/base/src/port1.0/portsandbox.tcl
    branches/new-help-system/base/src/port1.0/portstartupitem.tcl
    branches/new-help-system/base/src/port1.0/porttrace.tcl
    branches/new-help-system/base/src/port1.0/portunload.tcl
    branches/new-help-system/base/src/port1.0/portutil.tcl
    branches/new-help-system/base/src/programs/daemondo/main.c
    branches/new-help-system/base/src/registry2.0/portimage.tcl
    branches/new-help-system/base/src/registry2.0/portuninstall.tcl
    branches/new-help-system/base/src/registry2.0/receipt_flat.tcl
    branches/new-help-system/base/src/registry2.0/receipt_sqlite.tcl
    branches/new-help-system/base/src/registry2.0/registry.tcl
    branches/new-help-system/base/src/registry2.0/registry_util.tcl
    branches/new-help-system/base/src/registry2.0/tests/entry.tcl
    branches/new-help-system/base/src/registry2.0/util.c
    branches/new-help-system/base/src/upgrade_sources_conf_default.tcl
    branches/new-help-system/base/tests/test/checksums-1/Portfile

Added Paths:
-----------
    branches/new-help-system/base/src/darwintracelib1.0/access.c
    branches/new-help-system/base/src/darwintracelib1.0/close.c
    branches/new-help-system/base/src/darwintracelib1.0/darwintrace.h
    branches/new-help-system/base/src/darwintracelib1.0/dup2.c
    branches/new-help-system/base/src/darwintracelib1.0/mkdir.c
    branches/new-help-system/base/src/darwintracelib1.0/open.c
    branches/new-help-system/base/src/darwintracelib1.0/proc.c
    branches/new-help-system/base/src/darwintracelib1.0/readdir.c
    branches/new-help-system/base/src/darwintracelib1.0/readlink.c
    branches/new-help-system/base/src/darwintracelib1.0/rename.c
    branches/new-help-system/base/src/darwintracelib1.0/rmdir.c
    branches/new-help-system/base/src/darwintracelib1.0/stat.c
    branches/new-help-system/base/src/darwintracelib1.0/unlink.c
    branches/new-help-system/base/src/macports1.0/macports_test_autoconf.tcl.in
    branches/new-help-system/base/src/macports1.0/tests/Portfile
    branches/new-help-system/base/src/macports1.0/tests/library.tcl
    branches/new-help-system/base/src/macports1.0/tests/macports.test
    branches/new-help-system/base/src/macports1.0/tests/macports_dlist.test
    branches/new-help-system/base/src/macports1.0/tests/macports_util.test
    branches/new-help-system/base/src/macports1.0/tests/sources.conf
    branches/new-help-system/base/src/macports1.0/tests/test.tcl
    branches/new-help-system/base/src/package1.0/package_test_autoconf.tcl.in
    branches/new-help-system/base/src/package1.0/tests/
    branches/new-help-system/base/src/port1.0/port_test_autoconf.tcl.in
    branches/new-help-system/base/src/port1.0/tests/Portfile
    branches/new-help-system/base/src/port1.0/tests/library.tcl
    branches/new-help-system/base/src/port1.0/tests/portactivate.test
    branches/new-help-system/base/src/port1.0/tests/portchecksum.test
    branches/new-help-system/base/src/port1.0/tests/portclean.test
    branches/new-help-system/base/src/port1.0/tests/portdeactivate.test
    branches/new-help-system/base/src/port1.0/tests/portdepends.test
    branches/new-help-system/base/src/port1.0/tests/portdistcheck.test
    branches/new-help-system/base/src/port1.0/tests/portinstall.test
    branches/new-help-system/base/src/port1.0/tests/portload.test
    branches/new-help-system/base/src/port1.0/tests/portmain.test
    branches/new-help-system/base/src/port1.0/tests/portpatch.test
    branches/new-help-system/base/src/port1.0/tests/porttest.test
    branches/new-help-system/base/src/port1.0/tests/portuninstall.test
    branches/new-help-system/base/src/port1.0/tests/portutil.test
    branches/new-help-system/base/src/port1.0/tests/statefile
    branches/new-help-system/base/src/port1.0/tests/test.tcl
    branches/new-help-system/base/tests/Makefile
    branches/new-help-system/base/tests/test/case-insensitive-deactivate/DESCRIPTION
    branches/new-help-system/base/tests/test/case-insensitive-deactivate/test.tcl
    branches/new-help-system/base/tests/test/checksums-1/DESCRIPTION
    branches/new-help-system/base/tests/test/checksums-1/test.tcl
    branches/new-help-system/base/tests/test/dependencies-a/DESCRIPTION
    branches/new-help-system/base/tests/test/dependencies-a/test.tcl
    branches/new-help-system/base/tests/test/dependencies-b/DESCRIPTION
    branches/new-help-system/base/tests/test/dependencies-b/test.tcl
    branches/new-help-system/base/tests/test/dependencies-c/DESCRIPTION
    branches/new-help-system/base/tests/test/dependencies-c/test.tcl
    branches/new-help-system/base/tests/test/dependencies-d/DESCRIPTION
    branches/new-help-system/base/tests/test/dependencies-d/test.tcl
    branches/new-help-system/base/tests/test/dependencies-e/DESCRIPTION
    branches/new-help-system/base/tests/test/dependencies-e/test.tcl
    branches/new-help-system/base/tests/test/envvariables/DESCRIPTION
    branches/new-help-system/base/tests/test/envvariables/test.tcl
    branches/new-help-system/base/tests/test/library.tcl
    branches/new-help-system/base/tests/test/site-tags/DESCRIPTION
    branches/new-help-system/base/tests/test/site-tags/test.tcl
    branches/new-help-system/base/tests/test/statefile-unknown-version/DESCRIPTION
    branches/new-help-system/base/tests/test/statefile-unknown-version/test.tcl
    branches/new-help-system/base/tests/test/statefile-version1/DESCRIPTION
    branches/new-help-system/base/tests/test/statefile-version1/test.tcl
    branches/new-help-system/base/tests/test/statefile-version1-outdated/DESCRIPTION
    branches/new-help-system/base/tests/test/statefile-version1-outdated/test.tcl
    branches/new-help-system/base/tests/test/statefile-version2/DESCRIPTION
    branches/new-help-system/base/tests/test/statefile-version2/test.tcl
    branches/new-help-system/base/tests/test/statefile-version2-invalid/DESCRIPTION
    branches/new-help-system/base/tests/test/statefile-version2-invalid/test.tcl
    branches/new-help-system/base/tests/test/statefile-version2-outdated/DESCRIPTION
    branches/new-help-system/base/tests/test/statefile-version2-outdated/test.tcl
    branches/new-help-system/base/tests/test/svn-and-patchsites/DESCRIPTION
    branches/new-help-system/base/tests/test/svn-and-patchsites/test.tcl
    branches/new-help-system/base/tests/test/trace/DESCRIPTION
    branches/new-help-system/base/tests/test/trace/test.tcl
    branches/new-help-system/base/tests/test/universal/DESCRIPTION
    branches/new-help-system/base/tests/test/universal/Portfile.in
    branches/new-help-system/base/tests/test/universal/test.tcl
    branches/new-help-system/base/tests/test/variants/DESCRIPTION
    branches/new-help-system/base/tests/test/variants/test.tcl
    branches/new-help-system/base/tests/test/xcodeversion/DESCRIPTION
    branches/new-help-system/base/tests/test/xcodeversion/test.tcl
    branches/new-help-system/base/tests/test.tcl

Removed Paths:
-------------
    branches/new-help-system/base/src/macports1.0/tests/macports_dlist.tcl
    branches/new-help-system/base/src/macports1.0/tests/macports_util.tcl
    branches/new-help-system/base/src/port1.0/tests/common.tcl
    branches/new-help-system/base/src/port1.0/tests/portdestroot.tcl
    branches/new-help-system/base/src/port1.0/tests/portfetch.tcl
    branches/new-help-system/base/src/port1.0/tests/portutil.tcl
    branches/new-help-system/base/tests/Makefile
    branches/new-help-system/base/tests/test/case-insensitive-deactivate/Makefile
    branches/new-help-system/base/tests/test/checksums-1/master
    branches/new-help-system/base/tests/test/dependencies-c/master
    branches/new-help-system/base/tests/test/dependencies-d/master
    branches/new-help-system/base/tests/test/dependencies-e/error_expected
    branches/new-help-system/base/tests/test/dependencies-e/master
    branches/new-help-system/base/tests/test/envvariables/Makefile
    branches/new-help-system/base/tests/test/envvariables/master
    branches/new-help-system/base/tests/test/site-tags/master
    branches/new-help-system/base/tests/test/statefile-unknown-version/Makefile
    branches/new-help-system/base/tests/test/statefile-unknown-version/master
    branches/new-help-system/base/tests/test/statefile-version1/Makefile
    branches/new-help-system/base/tests/test/statefile-version1/master
    branches/new-help-system/base/tests/test/statefile-version1-outdated/Makefile
    branches/new-help-system/base/tests/test/statefile-version1-outdated/master
    branches/new-help-system/base/tests/test/statefile-version2/Makefile
    branches/new-help-system/base/tests/test/statefile-version2/master
    branches/new-help-system/base/tests/test/statefile-version2-invalid/Makefile
    branches/new-help-system/base/tests/test/statefile-version2-invalid/master
    branches/new-help-system/base/tests/test/statefile-version2-outdated/Makefile
    branches/new-help-system/base/tests/test/statefile-version2-outdated/master
    branches/new-help-system/base/tests/test/svn-and-patchsites/master
    branches/new-help-system/base/tests/test/universal/Makefile
    branches/new-help-system/base/tests/test/universal/Portfile
    branches/new-help-system/base/tests/test/universal/master
    branches/new-help-system/base/tests/test/universal-2/
    branches/new-help-system/base/tests/test/variants/master
    branches/new-help-system/base/tests/test/xcodeversion/master

Property Changed:
----------------
    branches/new-help-system/base/
    branches/new-help-system/base/src/macports1.0/
    branches/new-help-system/base/src/package1.0/
    branches/new-help-system/base/src/pextlib1.0/Makefile.in
    branches/new-help-system/base/src/pextlib1.0/sha2.c
    branches/new-help-system/base/src/pextlib1.0/sha2.h
    branches/new-help-system/base/src/pextlib1.0/sha256cmd.c
    branches/new-help-system/base/src/pextlib1.0/sha256cmd.h
    branches/new-help-system/base/src/port1.0/
    branches/new-help-system/base/src/registry2.0/receipt_sqlite.tcl


Property changes on: branches/new-help-system/base
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:49341-110831
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692
   + /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/gsoc11-statistics/base:79520,79666
/branches/gsoc13-tests:106692-111324
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:49341-117083
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692

Modified: branches/new-help-system/base/ChangeLog
===================================================================
--- branches/new-help-system/base/ChangeLog	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/ChangeLog	2014-02-15 14:35:04 UTC (rev 117084)
@@ -3,7 +3,40 @@
 # $Id$
 ###
 
-Release 2.2.1 (unreleased)
+Release 2.3 (unreleased)
+    - Display a progress indicator for slow downloads. (cal in r117044)
+
+    - Allow ports to select a specific version of the Mac OS X SDK
+      for builds. (larryv in r116437)
+
+    - Enhance the "move" Portfile builtin to support case-only renames
+      on case-insensitive filesystems. (#41679, ryandesign in r114289)
+
+    - Disable Spotlight indexing on build directories, distfiles,
+      registry, log files, archives, base source and the default ports
+      tree. (cal in r113649)
+
+    - Detect when base is running on a different platform than the one
+      it was configured for and refer user to migration instructions.
+      (raimue in r113478)
+
+    - In debug output, sort environment variables and print one per
+      line. (#40703, ryandesign in r113037)
+
+    - Fix incorrect lint messages when an uppercase letter is used in
+      a PortGroup name. (#40733, ryandesign in r112064)
+
+    - Add "-prepend" command for Portfile options (similar to existing
+      "-append" command). (#40655, ryandesign in r111990)
+
+Release 2.2.1 (2013-10-26 by jmr)
+    - Fixed a problem where dependency calculation could sometimes fail for
+      ports that only support 32-bit architectures when the configured
+      build_arch is 64-bit and dependencies thus need to be +universal
+      (#40721, jmr in r112067)
+
+    - Fixed a potential crash in the strsed procedure (toby in r110985)
+
     - Provide choice of GCC version when compiling with DragonEgg.
       (larryv in r108040)
 

Modified: branches/new-help-system/base/HACKING
===================================================================
--- branches/new-help-system/base/HACKING	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/HACKING	2014-02-15 14:35:04 UTC (rev 117084)
@@ -70,3 +70,6 @@
 
  *  All other files (documentation, etc) SHOULD NOT use a modeline as it
     is probably meant for human consumption.
+
+ -  When adding new features, always add test cases.
+    See "https://trac.macports.org/wiki/Tests".

Modified: branches/new-help-system/base/Mk/macports.autoconf.mk.in
===================================================================
--- branches/new-help-system/base/Mk/macports.autoconf.mk.in	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/Mk/macports.autoconf.mk.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -16,6 +16,8 @@
 CFLAGS_PEDANTIC		= @CFLAGS_PEDANTIC@
 CFLAGS_WERROR		= @CFLAGS_WERROR@
 
+UNIVERSAL_ARCHFLAGS	= @UNIVERSAL_ARCHFLAGS@
+
 READLINE_CFLAGS		=
 MD5_CFLAGS		=
 SQLITE3_CFLAGS		= @CFLAGS_SQLITE3@

Modified: branches/new-help-system/base/aclocal.m4
===================================================================
--- branches/new-help-system/base/aclocal.m4	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/aclocal.m4	2014-02-15 14:35:04 UTC (rev 117084)
@@ -511,6 +511,9 @@
 
   if test "x$UNIVERSAL_ARCHS" = "x"; then
     case "$MACOSX_VERSION" in
+      10.1[[0-9]]*)
+        UNIVERSAL_ARCHS="x86_64 i386"
+        ;;
       10.[[0-5]]*)
         UNIVERSAL_ARCHS="i386 ppc"
         ;;
@@ -520,9 +523,15 @@
     esac
   fi
 
+  UNIVERSAL_ARCHFLAGS=
+  for arch in $UNIVERSAL_ARCHS; do
+    UNIVERSAL_ARCHFLAGS="$UNIVERSAL_ARCHFLAGS -arch $arch"
+  done
+
   AC_MSG_CHECKING([for Universal CPU architectures])
   AC_MSG_RESULT([$UNIVERSAL_ARCHS])
   AC_SUBST(UNIVERSAL_ARCHS)
+  AC_SUBST(UNIVERSAL_ARCHFLAGS)
 ])
 
 # MP_LIB_MD5
@@ -883,7 +892,7 @@
 	
 ])
 
-dnl This macro ensures MP installation prefix bin/sbin paths are NOT in PATH
+dnl This macro ensures MP installation prefix paths are NOT in PATH
 dnl for configure to prevent potential problems when base/ code is updated
 dnl and ports are installed that would match needed items.
 AC_DEFUN([MP_PATH_SCAN],[
@@ -897,14 +906,17 @@
 	for as_dir in $oldPATH
 	do
 		IFS=$as_save_IFS
-		if test "x$as_dir" != "x$prefix/bin" &&
-			test "x$as_dir" != "x$prefix/sbin"; then
-			if test -z "$newPATH"; then
-				newPATH=$as_dir
-			else
-				newPATH=$newPATH$PATH_SEPARATOR$as_dir
-			fi
-		fi
+		case "$as_dir" in
+			$prefix/*)
+				;;
+			*)
+				if test -z "$newPATH"; then
+					newPATH=$as_dir
+				else
+					newPATH=$newPATH$PATH_SEPARATOR$as_dir
+				fi
+				;;
+		esac
 	done
 	PATH=$newPATH; export PATH
 	AC_SUBST(PATH_CLEANED,$newPATH)
@@ -1138,3 +1150,83 @@
 	CPPFLAGS=$mp_check_sqlite_version_cppflags_save
 ])
 
+#------------------------------------------------------------------------
+# MP_TCL_PLATFORM --
+#
+#       Export target platform and major version
+#
+# Arguments:
+#       none.
+#
+# Requires:
+#       TCLSH must be set.
+#
+# Depends:
+#       none.
+#
+# Results:
+#       Defines OS_PLATFORM and OS_MAJOR.
+#
+#------------------------------------------------------------------------
+AC_DEFUN([MP_TCL_PLATFORM],[
+        AC_MSG_CHECKING([for Tcl target platform])
+        OS_PLATFORM=`echo 'puts -nonewline [[string tolower \$tcl_platform(os)]]' | $TCLSH`
+        OS_MAJOR=`echo 'puts -nonewline [[lindex [split \$tcl_platform(osVersion) .] 0]]' | $TCLSH`
+        AC_MSG_RESULT($OS_PLATFORM $OS_MAJOR)
+        AC_SUBST(OS_PLATFORM)
+        AC_SUBST(OS_MAJOR)
+])
+
+#------------------------------------------------------------------------
+# MP_TRACEMODE_SUPPORT --
+#
+#       Check whether trace mode is supported on this platform
+#
+# Arguments:
+#       none.
+#
+# Requires:
+#       OS_PLATOFRM and OS_MAJOR from MP_TCL_PLATFORM.
+#
+# Depends:
+#       none.
+#
+# Results:
+#       Defines the TRACEMODE_SUPPORT substitution and the
+#       HAVE_TRACEMODE_SUPPORT macro.
+#
+#------------------------------------------------------------------------
+AC_DEFUN([MP_TRACEMODE_SUPPORT],[
+		AC_REQUIRE([MP_TCL_PLATFORM])
+
+		AC_CHECK_FUNCS([kqueue kevent])
+
+		AC_MSG_CHECKING([whether trace mode is supported on this platform])
+		if test x"${OS_PLATFORM}" != "xdarwin"; then
+			AC_MSG_RESULT([not darwin, no])
+			TRACEMODE_SUPPORT=0
+		elif test x"${ac_cv_func_kqueue}" != "xyes"; then
+			AC_MSG_RESULT([kqueue() not available, no])
+			TRACEMODE_SUPPORT=0
+		elif test x"${ac_cv_func_kevent}" != "xyes"; then
+			AC_MSG_RESULT([kevent() not available, no])
+			TRACEMODE_SUPPORT=0
+		else
+			AC_EGREP_CPP(yes_have_ev_receipt, [
+				#include <sys/types.h>
+				#include <sys/event.h>
+				#include <sys/time.h>
+				#ifdef EV_RECEIPT
+				yes_have_ev_receipt
+				#endif
+			],[
+				AC_MSG_RESULT([yes])
+				TRACEMODE_SUPPORT=1
+				AC_DEFINE([HAVE_TRACEMODE_SUPPORT], [1], [Platform supports tracemode.])
+			],[
+				AC_MSG_RESULT([EV_RECEIPT not available, no])
+				TRACEMODE_SUPPORT=0
+			])
+		fi
+        AC_SUBST(TRACEMODE_SUPPORT)
+])

Modified: branches/new-help-system/base/config/RELEASE_URL
===================================================================
--- branches/new-help-system/base/config/RELEASE_URL	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/config/RELEASE_URL	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1 +1 @@
-https://svn.macports.org/repository/macports/tags/release_2_2_0/base
+https://svn.macports.org/repository/macports/tags/release_2_2_1/base

Modified: branches/new-help-system/base/configure
===================================================================
--- branches/new-help-system/base/configure	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/configure	2014-02-15 14:35:04 UTC (rev 117084)
@@ -640,6 +640,7 @@
 STLIB_LD
 INCLUDES
 subdirs
+TRACEMODE_SUPPORT
 SQLITE3_TCL_DIR
 LDFLAGS_SQLITE3
 CFLAGS_SQLITE3
@@ -647,6 +648,8 @@
 LDFLAGS_LIBCURL
 CFLAGS_LIBCURL
 CURL_CONFIG
+OS_MAJOR
+OS_PLATFORM
 TCLSH
 TCL_INCLUDES
 TCL_STUB_LIB_SPEC
@@ -663,6 +666,7 @@
 READLINK_IS_NOT_P1003_1A
 ac_cv_func_strlcat
 CPP
+UNIVERSAL_ARCHFLAGS
 UNIVERSAL_ARCHS
 MPFRAMEWORKSDIR
 MPAPPLICATIONSDIR
@@ -2806,14 +2810,17 @@
 	for as_dir in $oldPATH
 	do
 		IFS=$as_save_IFS
-		if test "x$as_dir" != "x$prefix/bin" &&
-			test "x$as_dir" != "x$prefix/sbin"; then
-			if test -z "$newPATH"; then
-				newPATH=$as_dir
-			else
-				newPATH=$newPATH$PATH_SEPARATOR$as_dir
-			fi
-		fi
+		case "$as_dir" in
+			$prefix/*)
+				;;
+			*)
+				if test -z "$newPATH"; then
+					newPATH=$as_dir
+				else
+					newPATH=$newPATH$PATH_SEPARATOR$as_dir
+				fi
+				;;
+		esac
 	done
 	PATH=$newPATH; export PATH
 	PATH_CLEANED=$newPATH
@@ -2951,17 +2958,17 @@
 fi
 
 case "$MACOSX_VERSION" in
-  10.0*|10.1*|10.2*|10.3*)
+  10.0*|10.1|10.1.*|10.2*|10.3*)
     as_fn_error $? "This version of Mac OS X is not supported
                   Please upgrade at http://store.apple.com/" "$LINENO" 5
     ;;
-  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-4]|10.8.[0-3])
+  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-4]|10.8.[0-4])
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: This version of Mac OS X is out of date" >&5
 $as_echo "$as_me: WARNING: This version of Mac OS X is out of date" >&2;}
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please run Software Update to update it" >&5
 $as_echo "$as_me: WARNING: Please run Software Update to update it" >&2;}
     ;;
-  10.4*|10.5*|10.6*|10.7*|10.8*)
+  10.4*|10.5*|10.6*|10.7*|10.8*|10.9*)
         ;;
   *)
     ;;
@@ -3018,7 +3025,7 @@
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please consider upgrading as some ports fail compiling" >&5
 $as_echo "$as_me: WARNING: Please consider upgrading as some ports fail compiling" >&2;}
     ;;
-  2.*|3.*|4.*)
+  2.*|3.*|4.*|5.*)
         ;;
   *)
     ;;
@@ -3031,197 +3038,7 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
-set dummy ${ac_tool_prefix}gcc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_CC="${ac_tool_prefix}gcc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-fi
-if test -z "$ac_cv_prog_CC"; then
-  ac_ct_CC=$CC
-  # Extract the first word of "gcc", so it can be a program name with args.
-set dummy gcc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$ac_ct_CC"; then
-  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_ac_ct_CC="gcc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-ac_ct_CC=$ac_cv_prog_ac_ct_CC
-if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
-$as_echo "$ac_ct_CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-  if test "x$ac_ct_CC" = x; then
-    CC=""
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    CC=$ac_ct_CC
-  fi
-else
-  CC="$ac_cv_prog_CC"
-fi
-
-if test -z "$CC"; then
-          if test -n "$ac_tool_prefix"; then
-    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
-set dummy ${ac_tool_prefix}cc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_CC="${ac_tool_prefix}cc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-  fi
-fi
-if test -z "$CC"; then
-  # Extract the first word of "cc", so it can be a program name with args.
-set dummy cc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-  ac_prog_rejected=no
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
-       ac_prog_rejected=yes
-       continue
-     fi
-    ac_cv_prog_CC="cc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-if test $ac_prog_rejected = yes; then
-  # We found a bogon in the path, so make sure we never use it.
-  set dummy $ac_cv_prog_CC
-  shift
-  if test $# != 0; then
-    # We chose a different compiler from the bogus one.
-    # However, it has the same basename, so the bogon will be chosen
-    # first if we set CC to just the basename; use the full file name.
-    shift
-    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
-  fi
-fi
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-fi
-if test -z "$CC"; then
-  if test -n "$ac_tool_prefix"; then
-  for ac_prog in cl.exe
+  for ac_prog in clang cc gcc
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
@@ -3265,7 +3082,7 @@
 fi
 if test -z "$CC"; then
   ac_ct_CC=$CC
-  for ac_prog in cl.exe
+  for ac_prog in clang cc gcc
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
@@ -3320,9 +3137,7 @@
   fi
 fi
 
-fi
 
-
 test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "no acceptable C compiler found in \$PATH
@@ -3955,7 +3770,7 @@
 ac_link='$OBJC -o conftest$ac_exeext $OBJCFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_objc_compiler_gnu
 if test -n "$ac_tool_prefix"; then
-  for ac_prog in gcc objcc objc cc CC
+  for ac_prog in clang cc gcc
   do
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
@@ -3999,7 +3814,7 @@
 fi
 if test -z "$OBJC"; then
   ac_ct_OBJC=$OBJC
-  for ac_prog in gcc objcc objc cc CC
+  for ac_prog in clang cc gcc
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
@@ -8360,6 +8175,9 @@
 
   if test "x$UNIVERSAL_ARCHS" = "x"; then
     case "$MACOSX_VERSION" in
+      10.1[0-9]*)
+        UNIVERSAL_ARCHS="x86_64 i386"
+        ;;
       10.[0-5]*)
         UNIVERSAL_ARCHS="i386 ppc"
         ;;
@@ -8369,6 +8187,11 @@
     esac
   fi
 
+  UNIVERSAL_ARCHFLAGS=
+  for arch in $UNIVERSAL_ARCHS; do
+    UNIVERSAL_ARCHFLAGS="$UNIVERSAL_ARCHFLAGS -arch $arch"
+  done
+
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Universal CPU architectures" >&5
 $as_echo_n "checking for Universal CPU architectures... " >&6; }
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $UNIVERSAL_ARCHS" >&5
@@ -8376,6 +8199,7 @@
 
 
 
+
 # Check for standard header files.
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
@@ -8826,8 +8650,9 @@
 
 fi
 
-for ac_header in limits.h paths.h sys/file.h crt_externs.h fcntl.h sys/fcntl.h sys/cdefs.h err.h sys/socket.h \
-	sys/event.h sys/sysctl.h readline/readline.h readline/history.h pwd.h sys/paths.h utime.h
+for ac_header in crt_externs.h err.h fcntl.h libkern/OSAtomic.h limits.h paths.h pwd.h \
+	readline/history.h readline/readline.h spawn.h sys/cdefs.h sys/event.h sys/fcntl.h sys/file.h \
+	sys/paths.h sys/socket.h sys/sysctl.h utime.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -8844,7 +8669,9 @@
 INCLUDES="-I.. -I. $INCLUDES"
 
 # Checks for library functions.
-for ac_func in bzero memset fgetln lockf flock setmode strcasecmp strncasecmp strlcpy strlcat copyfile clearenv sysctlbyname kqueue
+for ac_func in OSAtomicCompareAndSwap32 OSAtomicCompareAndSwap64 OSAtomicCompareAndSwapPtr bzero \
+	clearenv copyfile fgetln flock fls kqueue lockf memset posix_spawn setmode strcasecmp strlcat \
+	strlcpy strncasecmp sysctlbyname
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -9583,6 +9410,18 @@
 
 
 
+# Substitute Tcl platform for base compatibility check
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl target platform" >&5
+$as_echo_n "checking for Tcl target platform... " >&6; }
+        OS_PLATFORM=`echo 'puts -nonewline [string tolower \$tcl_platform(os)]' | $TCLSH`
+        OS_MAJOR=`echo 'puts -nonewline [lindex [split \$tcl_platform(osVersion) .] 0]' | $TCLSH`
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OS_PLATFORM $OS_MAJOR" >&5
+$as_echo "$OS_PLATFORM $OS_MAJOR" >&6; }
+
+
+
+
 # Check for Tcl package path
 
 
@@ -10006,6 +9845,72 @@
 
 fi
 
+# check whether trace mode is supported on this platform
+
+
+
+		for ac_func in kqueue kevent
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether trace mode is supported on this platform" >&5
+$as_echo_n "checking whether trace mode is supported on this platform... " >&6; }
+		if test x"${OS_PLATFORM}" != "xdarwin"; then
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not darwin, no" >&5
+$as_echo "not darwin, no" >&6; }
+			TRACEMODE_SUPPORT=0
+		elif test x"${ac_cv_func_kqueue}" != "xyes"; then
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: kqueue() not available, no" >&5
+$as_echo "kqueue() not available, no" >&6; }
+			TRACEMODE_SUPPORT=0
+		elif test x"${ac_cv_func_kevent}" != "xyes"; then
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: kevent() not available, no" >&5
+$as_echo "kevent() not available, no" >&6; }
+			TRACEMODE_SUPPORT=0
+		else
+			cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+				#include <sys/types.h>
+				#include <sys/event.h>
+				#include <sys/time.h>
+				#ifdef EV_RECEIPT
+				yes_have_ev_receipt
+				#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes_have_ev_receipt" >/dev/null 2>&1; then :
+
+				{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+				TRACEMODE_SUPPORT=1
+
+$as_echo "#define HAVE_TRACEMODE_SUPPORT 1" >>confdefs.h
+
+
+else
+
+				{ $as_echo "$as_me:${as_lineno-$LINENO}: result: EV_RECEIPT not available, no" >&5
+$as_echo "EV_RECEIPT not available, no" >&6; }
+				TRACEMODE_SUPPORT=0
+
+fi
+rm -f conftest*
+
+		fi
+
+
+
 # Determine if we need to install some bundled packages
 OUR_INCLUDED_PACKAGES=
 
@@ -10140,7 +10045,7 @@
 
 
 # Output
-ac_config_files="$ac_config_files Doxyfile Makefile Mk/macports.autoconf.mk doc/base.mtree doc/macosx.mtree doc/macports.conf doc/prefix.mtree doc/pubkeys.conf portmgr/freebsd/Makefile setupenv.bash src/Makefile src/machista1.0/Makefile src/macports1.0/macports_autoconf.tcl src/macports1.0/macports_fastload.tcl src/pextlib1.0/Makefile src/port1.0/port_autoconf.tcl src/programs/Makefile src/registry2.0/registry_autoconf.tcl"
+ac_config_files="$ac_config_files Doxyfile Makefile Mk/macports.autoconf.mk doc/base.mtree doc/macosx.mtree doc/macports.conf doc/prefix.mtree doc/pubkeys.conf portmgr/freebsd/Makefile setupenv.bash src/Makefile src/machista1.0/Makefile src/macports1.0/macports_autoconf.tcl src/macports1.0/macports_test_autoconf.tcl src/macports1.0/macports_fastload.tcl src/package1.0/package_test_autoconf.tcl src/pextlib1.0/Makefile src/port1.0/port_autoconf.tcl src/port1.0/port_test_autoconf.tcl src/programs/Makefile src/registry2.0/registry_autoconf.tcl"
 
 
 ac_config_files="$ac_config_files src/pkg_mkindex.sh"
@@ -10851,9 +10756,12 @@
     "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
     "src/machista1.0/Makefile") CONFIG_FILES="$CONFIG_FILES src/machista1.0/Makefile" ;;
     "src/macports1.0/macports_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_autoconf.tcl" ;;
+    "src/macports1.0/macports_test_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_test_autoconf.tcl" ;;
     "src/macports1.0/macports_fastload.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_fastload.tcl" ;;
+    "src/package1.0/package_test_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/package1.0/package_test_autoconf.tcl" ;;
     "src/pextlib1.0/Makefile") CONFIG_FILES="$CONFIG_FILES src/pextlib1.0/Makefile" ;;
     "src/port1.0/port_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/port1.0/port_autoconf.tcl" ;;
+    "src/port1.0/port_test_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/port1.0/port_test_autoconf.tcl" ;;
     "src/programs/Makefile") CONFIG_FILES="$CONFIG_FILES src/programs/Makefile" ;;
     "src/registry2.0/registry_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/registry2.0/registry_autoconf.tcl" ;;
     "src/pkg_mkindex.sh") CONFIG_FILES="$CONFIG_FILES src/pkg_mkindex.sh" ;;

Modified: branches/new-help-system/base/configure.ac
===================================================================
--- branches/new-help-system/base/configure.ac	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/configure.ac	2014-02-15 14:35:04 UTC (rev 117084)
@@ -28,15 +28,15 @@
 fi
 
 case "$MACOSX_VERSION" in
-  10.0*|10.1*|10.2*|10.3*)
+  10.0*|10.1|10.1.*|10.2*|10.3*)
     AC_MSG_ERROR([This version of Mac OS X is not supported
                   Please upgrade at http://store.apple.com/])
     ;;
-  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-4]]|10.8.[[0-3]])
+  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-4]]|10.8.[[0-4]])
     AC_MSG_WARN([This version of Mac OS X is out of date])
     AC_MSG_WARN([Please run Software Update to update it])
     ;;
-  10.4*|10.5*|10.6*|10.7*|10.8*)
+  10.4*|10.5*|10.6*|10.7*|10.8*|10.9*)
     dnl Supported version
     ;;
   *)
@@ -86,7 +86,7 @@
     AC_MSG_WARN([This version of Xcode Tools is out of date])
     AC_MSG_WARN([Please consider upgrading as some ports fail compiling])
     ;;
-  2.*|3.*|4.*)
+  2.*|3.*|4.*|5.*)
     dnl Supported version
     ;;
   *)
@@ -94,11 +94,11 @@
 esac
 
 # Checks for programs.
-AC_PROG_CC
+AC_PROG_CC([clang cc gcc])
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
-AC_PROG_OBJC
+AC_PROG_OBJC([clang cc gcc])
 
 AC_PATH_PROGS(BSDMAKE, [bsdmake pmake], [])
 AC_PATH_PROG(BZIP2, [bzip2], [])
@@ -239,14 +239,17 @@
 AC_HEADER_STDC
 AC_HEADER_DIRENT
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([limits.h paths.h sys/file.h crt_externs.h fcntl.h sys/fcntl.h sys/cdefs.h err.h sys/socket.h \
-	sys/event.h sys/sysctl.h readline/readline.h readline/history.h pwd.h sys/paths.h utime.h])
+AC_CHECK_HEADERS([crt_externs.h err.h fcntl.h libkern/OSAtomic.h limits.h paths.h pwd.h \
+	readline/history.h readline/readline.h spawn.h sys/cdefs.h sys/event.h sys/fcntl.h sys/file.h \
+	sys/paths.h sys/socket.h sys/sysctl.h utime.h])
 
 INCLUDES="-I.. -I. $INCLUDES"
 
 # Checks for library functions.
-AC_CHECK_FUNCS([bzero memset fgetln lockf flock setmode strcasecmp strncasecmp strlcpy strlcat copyfile clearenv sysctlbyname kqueue])
-AC_SUBST(ac_cv_func_strlcat)
+AC_CHECK_FUNCS([OSAtomicCompareAndSwap32 OSAtomicCompareAndSwap64 OSAtomicCompareAndSwapPtr bzero \
+	clearenv copyfile fgetln flock fls kqueue lockf memset posix_spawn setmode strcasecmp strlcat \
+	strlcpy strncasecmp sysctlbyname])
+AC_SUBST([ac_cv_func_strlcat])
 
 MP_CHECK_READLINK_IS_P1003_1A
 
@@ -286,6 +289,9 @@
 # Check for tclsh binary
 MP_PROG_TCLSH
 
+# Substitute Tcl platform for base compatibility check
+MP_TCL_PLATFORM
+
 # Check for Tcl package path
 MP_TCL_PACKAGE_DIR
 
@@ -303,6 +309,9 @@
 	AC_DEFINE([sqlite3_prepare_v2], [sqlite3_prepare], [define sqlite3_prepare to sqlite_prepare_v2 if the latter is not available])
 fi
 
+# check whether trace mode is supported on this platform
+MP_TRACEMODE_SUPPORT
+
 # Determine if we need to install some bundled packages
 OUR_INCLUDED_PACKAGES=
 
@@ -398,9 +407,12 @@
 	src/Makefile
 	src/machista1.0/Makefile
 	src/macports1.0/macports_autoconf.tcl
+	src/macports1.0/macports_test_autoconf.tcl
 	src/macports1.0/macports_fastload.tcl
+	src/package1.0/package_test_autoconf.tcl
 	src/pextlib1.0/Makefile
 	src/port1.0/port_autoconf.tcl
+	src/port1.0/port_test_autoconf.tcl
 	src/programs/Makefile
 	src/registry2.0/registry_autoconf.tcl
 ])

Modified: branches/new-help-system/base/doc/portfile.7
===================================================================
--- branches/new-help-system/base/doc/portfile.7	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/doc/portfile.7	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,6 +1,6 @@
 .\" portfile.7
 .\"
-.\" Copyright (c) 2004-2013 The MacPorts Project
+.\" Copyright (c) 2004-2014 The MacPorts Project
 .\" Copyright (c) 2002-2003 Apple Inc.
 .\" All rights reserved.
 .\"
@@ -319,7 +319,7 @@
 .Em (current OS version)
 .br
 .Sy Example:
-.Dl macosx_deployment_target 10.4
+.Dl macosx_deployment_target 10.8
 .It Ic use_parallel_build
 If set to yes (and the user has enabled buildmakejobs in
 .Pa macports.conf
@@ -821,7 +821,7 @@
 .Em optional
 .br
 .Sy Default:
-.Em [suffix ${distname}]
+.Em ${distname}${extract.suffix}
 .br
 .Sy Example:
 .Dl distfiles magicsource.tar.gz cluebat.tar.bz2
@@ -1132,7 +1132,7 @@
 .Em optional
 .br
 .Sy Default:
-.Em -I${prefix}/include
+.Em -isystem${prefix}/include
 .It Ic configure.cxxflags
 Flags to put in the CXXFLAGS environment variable when invoking the configure script.
 .br
@@ -1156,7 +1156,7 @@
 .Em optional
 .br
 .Sy Default:
-.Em -L${prefix}/lib
+.Em -L${prefix}/lib -Wl,-headerpad_max_install_names
 .It Ic configure.fflags
 Flags to put in the FFLAGS environment variable when invoking the configure script.
 .br 
@@ -1261,6 +1261,17 @@
 .br
 .Sy Example:
 .Dl configure.compiler llvm-gcc-4.2
+.It Ic configure.sdk_version
+Mac OS X SDK version to build against.
+.br 
+.Sy Type:
+.Em optional
+.br 
+.Sy Default:
+.Em (current OS version)
+.br
+.Sy Example:
+.Dl configure.sdk_version 10.8
 .\" FOOBAR
 .El
 .Ss UNIVERSAL TARGET HOOKS

Modified: branches/new-help-system/base/portmgr/ReleaseProcess
===================================================================
--- branches/new-help-system/base/portmgr/ReleaseProcess	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/ReleaseProcess	2014-02-15 14:35:04 UTC (rev 117084)
@@ -231,6 +231,7 @@
  * The macports-announce@, macports-users@ and macports-dev@ mailing lists.
  * The MacPorts website, by adapting the $macports_version_major and $macports_version_latest variables as
    appropriate in the trunk/www/includes/common.inc file.
+ * The &macports-version; entity in trunk/doc-new/guide/xml/installing.xml.
  * [https://trac.macports.org/news/] The MacOSforge news section (submitter: portmgr@)
  * [http://freecode.com/projects/macports/ Freecode] (submitter: mww@)
  * [http://www.versiontracker.com/dyn/moreinfo/macosx/26679 VersionTracker] (submitter: mij@)

Modified: branches/new-help-system/base/portmgr/autosubmit.tcl
===================================================================
--- branches/new-help-system/base/portmgr/autosubmit.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/autosubmit.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -66,7 +66,7 @@
 			db eval { select * from submitinfo where porturl=$porturl } values {
 				set none 0
 				
-				if { $values(last_mod_date) == "" || $values(last_mod_date) != $mod_date } {
+				if { $values(last_mod_date) eq "" || $values(last_mod_date) != $mod_date } {
 				
 					# The last_mod_date has changed, so just update it to provide
 					# hysteresis for file changes
@@ -118,7 +118,7 @@
 			}
 			
 			# Do update or insert post processing
-			if { $post != "" } {
+			if { $post ne "" } {
 				db eval $post
 			}
 		}

Modified: branches/new-help-system/base/portmgr/jobs/PortIndex2MySQL.tcl
===================================================================
--- branches/new-help-system/base/portmgr/jobs/PortIndex2MySQL.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/jobs/PortIndex2MySQL.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -75,7 +75,7 @@
 # handle command line arguments
 set create_tables true
 if {[llength $argv]} {
-    if {[lindex $argv 0] == "--create-tables"} {
+    if {[lindex $argv 0] eq "--create-tables"} {
         set create_tables true
     }
 }

Modified: branches/new-help-system/base/portmgr/jobs/mprsyncup
===================================================================
--- branches/new-help-system/base/portmgr/jobs/mprsyncup	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/jobs/mprsyncup	2014-02-15 14:35:04 UTC (rev 117084)
@@ -55,7 +55,7 @@
 PATH=${PREFIX}/bin:/bin:/usr/bin:/usr/sbin:/opt/local/bin
 
 # platforms we generate indexes for
-PLATFORMS="8_powerpc 8_i386 9_powerpc 9_i386 10_i386 11_i386 12_i386"
+PLATFORMS="8_powerpc 8_i386 9_powerpc 9_i386 10_i386 11_i386 12_i386 13_i386"
 
 # Sources information:
 SVNURL=https://svn.macports.org/repository/macports

Modified: branches/new-help-system/base/portmgr/jobs/port_binary_distributable.tcl
===================================================================
--- branches/new-help-system/base/portmgr/jobs/port_binary_distributable.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/jobs/port_binary_distributable.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -122,7 +122,7 @@
     mportclose $mport
 
     foreach dependencyType $check_deptypes {
-        if {[info exists portInfo($dependencyType)] && [string length $portInfo($dependencyType)] > 0} {
+        if {[info exists portInfo($dependencyType)] && $portInfo($dependencyType) ne ""} {
             foreach dependency $portInfo($dependencyType) {
                 set afterColon [expr {[string last ":" $dependency] + 1}]
                 lappend dependencyList [string range $dependency $afterColon end]
@@ -146,8 +146,8 @@
 # return license with any trailing dash followed by a number and/or plus sign removed
 proc remove_version {license} {
     set dash [string last - $license]
-    if {$dash != -1 && [regexp {[0-9.+]+} [string range $license [expr $dash + 1] end]]} {
-        return [string range $license 0 [expr $dash - 1]]
+    if {$dash != -1 && [regexp {[0-9.+]+} [string range $license [expr {$dash + 1}] end]]} {
+        return [string range $license 0 [expr {$dash - 1}]]
     } else {
         return $license
     }

Modified: branches/new-help-system/base/portmgr/packaging/dpkgall.tcl
===================================================================
--- branches/new-help-system/base/portmgr/packaging/dpkgall.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/packaging/dpkgall.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -12,14 +12,14 @@
 # modification, are permitted provided that the following conditions
 # are met:
 # 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
+#	 notice, this list of conditions and the following disclaimer.
 # 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
+#	 notice, this list of conditions and the following disclaimer in the
+#	 documentation and/or other materials provided with the distribution.
 # 3. Neither the name of Apple Inc. nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-# 
+#	 may be used to endorse or promote products derived from this software
+#	 without specific prior written permission.
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -88,27 +88,27 @@
 
 # MacPorts UI Event Callbacks
 proc ui_prefix {priority} {
-    switch $priority {
-        debug {
-        	return "Debug: "
-        }
-        error {
-        	return "Error: "
-        }
-        warn {
-        	return "Warning: "
-        }
-        default {
-        	return ""
-        }
-    }
+	switch $priority {
+		debug {
+			return "Debug: "
+		}
+		error {
+			return "Error: "
+		}
+		warn {
+			return "Warning: "
+		}
+		default {
+			return ""
+		}
+	}
 }
 
 proc ui_channels {priority} {
 	global dpkg::logfd
-	if {[info exists logfd] && [string length $logfd] > 0 } {
+	if {[info exists logfd] && $logfd ne ""} {
 		return {$logfd}
-	} elseif {$message(priority) != "debug"} {
+	} elseif {$message(priority) ne "debug"} {
 		# If there's no log file, echo to stdout
 		return {stdout}
 	}
@@ -302,7 +302,7 @@
 		exit 0
 	}
 
-	# We must have dpkg by now 
+	# We must have dpkg by now
 	if {[catch {set_architecture} result]} {
 		puts "$result."
 		puts "Have you initialized the build system? Use the -i flag:"
@@ -432,16 +432,16 @@
 		array set portinfo [lindex $res 1]
 
 		if {![info exists portinfo(name)] ||
-			![info exists portinfo(version)] || 
-			![info exists portinfo(revision)] || 
+			![info exists portinfo(version)] ||
+			![info exists portinfo(revision)] ||
 			![info exists portinfo(categories)]} {
 			ui_noisy_error "Internal error: $name missing some portinfo keys"
 			close $logfd
 			continue
 		}
 
-        # open correct subport
-        set options(subport) $portinfo(name)
+		# open correct subport
+		set options(subport) $portinfo(name)
 
 		# Skip un-supported ports
 		if {[info exists portinfo(platforms)] && ${anyplatform_flag} != "true"} {
@@ -555,7 +555,7 @@
 		}
 
 		ui_silent "Package build for $portinfo(name) succeeded"
-		
+
 		# Into the apt repository you go!
 		copy_pkg_to_apt $portinfo(name) $portinfo(version) $portinfo(revision) [lindex $portinfo(categories) 0]
 
@@ -597,7 +597,7 @@
 			}
 		}
 
-		if {[info exists newpkglist]} {		
+		if {[info exists newpkglist]} {
 			set pkglist [lsort -unique [concat $newpkglist $pkglist]]
 		}
 
@@ -640,7 +640,7 @@
 	set reqlist ""
 
 	foreach {binary port} $requiredports {
-		if {[find_binary $binary] == ""} {
+		if {[find_binary $binary] eq ""} {
 			lappend reqlist $port
 		}
 	}
@@ -685,7 +685,7 @@
 	set buildlist [lsort -unique $builddeps]
 
 	foreach port $builddeps {
-		if {[lsearch -exact $port $rundeps] >= 0 } {
+		if {[lsearch -exact $port $rundeps] >= 0} {
 			lappend removelist $port
 		}
 	}
@@ -694,7 +694,7 @@
 	set variations ""
 
 	foreach port [get_required_ports] {
-	    set options(subport) $port
+		set options(subport) $port
 		if {[catch {do_portexec $port [array get options] [array get variants] activate} result]} {
 			global errorInfo
 			ui_debug "$errorInfo"
@@ -718,8 +718,8 @@
 		}
 		ui_msg "Done."
 	}
-			
 
+
 	if {[catch {set_architecture} result]} {
 		puts "Fatal error: $result."
 		exit 1
@@ -858,14 +858,14 @@
 
 proc get_dependencies_recurse {portname includeBuildDeps} {
 	set result {}
-	
+
 	set res [get_portinfo $portname]
 
 	foreach {name array} $res {
 		array set portinfo $array
 		if {![info exists portinfo(name)] ||
-			![info exists portinfo(version)] || 
-			![info exists portinfo(revision)] || 
+			![info exists portinfo(version)] ||
+			![info exists portinfo(revision)] ||
 			![info exists portinfo(categories)]} {
 			ui_error "Internal error: $name missing some portinfo keys"
 			continue
@@ -877,13 +877,13 @@
 		set depends {}
 		if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
 		if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
-		if {$includeBuildDeps == "true" && [info exists portinfo(depends_build)]} { 
+		if {$includeBuildDeps == "true" && [info exists portinfo(depends_build)]} {
 			eval "lappend depends $portinfo(depends_build)"
 		}
-		if {$includeBuildDeps == "true" && [info exists portinfo(depends_fetch)]} { 
+		if {$includeBuildDeps == "true" && [info exists portinfo(depends_fetch)]} {
 			eval "lappend depends $portinfo(depends_fetch)"
 		}
-		if {$includeBuildDeps == "true" && [info exists portinfo(depends_extract)]} { 
+		if {$includeBuildDeps == "true" && [info exists portinfo(depends_extract)]} {
 			eval "lappend depends $portinfo(depends_extract)"
 		}
 		foreach depspec $depends {
@@ -913,7 +913,7 @@
 	} else {
 		set verstring ${portversion}
 	}
-	
+
 	set receiptdir [file join $portprefix var db receipts ${portname} ${verstring}]
 	set pkgpath [get_pkgpath ${portname} ${portversion} ${portrevision}]
 

Modified: branches/new-help-system/base/portmgr/packaging/mpkgall.tcl
===================================================================
--- branches/new-help-system/base/portmgr/packaging/mpkgall.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/packaging/mpkgall.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -10,14 +10,14 @@
 # modification, are permitted provided that the following conditions
 # are met:
 # 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
+#	 notice, this list of conditions and the following disclaimer.
 # 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
+#	 notice, this list of conditions and the following disclaimer in the
+#	 documentation and/or other materials provided with the distribution.
 # 3. Neither the name of Apple Inc. nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-# 
+#	 may be used to endorse or promote products derived from this software
+#	 without specific prior written permission.
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -53,7 +53,7 @@
 	# XXX: don't overwrite Apple X11
 	# XXX: probably should exclude KDE here too
 	if {$portname == "XFree86"} { return {} }
-	
+
 	if {[catch {set res [mportsearch "^$portname\$"]} error]} {
 		puts stderr "Internal error: port search failed: $error"
 		return
@@ -63,11 +63,11 @@
 		if {![info exists portinfo(name)]} { return -1 }
 		if {![info exists portinfo(version)]} { return -1 }
 		if {![info exists portinfo(categories)]} { return -1 }
-		
+
 		set portname $portinfo(name)
 		set portversion $portinfo(version)
 		set category [lindex $portinfo(categories) 0]
-		
+
 		set depends {}
 		if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
 		if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
@@ -75,13 +75,13 @@
 		foreach depspec $depends {
 			set dep [lindex [split $depspec :] end]
 			set result [copy_package_if_available $dep $basepath $destpath]
-			if {$result == -1} { 
+			if {$result == -1} {
 				return -1
 			} else {
 				eval "lappend dependencies $result"
 			}
 		}
-		
+
 		set pkgname "${portname}-${portversion}.pkg"
 		lappend dependencies $pkgname
 		set pkgpath "${basepath}/${category}/${pkgname}"
@@ -95,7 +95,7 @@
 			return -1
 		}
 	}
-	
+
 	return $dependencies
 }
 
@@ -120,10 +120,10 @@
 }
 
 proc write_welcome_html {filename portname portversion long_description description homepage} {
-    set fd [open ${filename} w+]
-    if {$long_description == ""} {
-	set long_description $description
-    }
+	set fd [open ${filename} w+]
+	if {$long_description eq ""} {
+		set long_description $description
+	}
 
 puts $fd "
 <html lang=\"en\">
@@ -137,15 +137,15 @@
 <font face=\"Helvetica\">${long_description}</font>
 <p>"
 
-    if {$homepage != ""} {
-	puts $fd "<font face=\"Helvetica\">${homepage}</font><p>"
-    }
+	if {$homepage ne ""} {
+		puts $fd "<font face=\"Helvetica\">${homepage}</font><p>"
+	}
 
-    puts $fd "<font face=\"Helvetica\">This installer guides you through the steps necessary to install ${portname} ${portversion} for Mac OS X. To get started, click Continue.</font>
+	puts $fd "<font face=\"Helvetica\">This installer guides you through the steps necessary to install ${portname} ${portversion} for Mac OS X. To get started, click Continue.</font>
 </body>
 </html>"
 
-    close $fd
+	close $fd
 }
 
 proc write_PkgInfo {infofile} {
@@ -156,11 +156,11 @@
 
 proc mpkg_write_info_plist {infofile portname portversion portrevision destination dependencies} {
 	set vers [split $portversion "."]
-	
-	if {[string index $destination end] != "/"} {
+
+	if {[string index $destination end] ne "/"} {
 		append destination /
 	}
-	
+
 	set depxml ""
 	foreach dep $dependencies {
 		append depxml "<dict>
@@ -206,9 +206,9 @@
 # Standard procedures
 
 proc fatal args {
-    global argv0
-    puts stderr "$argv0: $args"
-    exit
+	global argv0
+	puts stderr "$argv0: $args"
+	exit
 }
 
 # Main
@@ -217,120 +217,118 @@
 #	set ui_options(ports_verbose) yes
 
 if {[catch {mportinit ui_options options variations} result]} {
-    puts "Failed to initialize ports system, $result"
-    exit 1
+	puts "Failed to initialize ports system, $result"
+	exit 1
 }
 
 package require Pextlib
 
 # If no arguments were given, default to all ports.
 if {[llength $argv] == 0} {
-        lappend argv ".*"
+	lappend argv ".*"
 }
 
 foreach pname $argv {
+	if {[catch {set res [mportsearch "^${pname}\$"]} result]} {
+		puts "port search failed: $result"
+		exit 1
+	}
 
-if {[catch {set res [mportsearch "^${pname}\$"]} result]} {
-	puts "port search failed: $result"
-	exit 1
-}
+	foreach {name array} $res {
+		global prefix
+		array unset portinfo
+		array set portinfo $array
 
-foreach {name array} $res {
-	global prefix
-	array unset portinfo
-	array set portinfo $array
+		if {![info exists portinfo(porturl)]} {
+			puts stderr "Internal error: no porturl for $name"
+			continue
+		}
 
-	if {![info exists portinfo(porturl)]} {
-		puts stderr "Internal error: no porturl for $name"
-		continue
-	}
-	
-	set pkgbase "/darwinports/pkgs/"
-	set mpkgbase "/darwinports/mpkgs/"
-	set porturl $portinfo(porturl)
-	set prefix "/opt/local"
+		set pkgbase "/darwinports/pkgs/"
+		set mpkgbase "/darwinports/mpkgs/"
+		set porturl $portinfo(porturl)
+		set prefix "/opt/local"
 
-	# Skip up-to-date packages
-	if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
-		if {[info exists portinfo(name)] &&
-			[info exists portinfo(version)] &&
-			[info exists portinfo(categories)]} {
-			set portname $portinfo(name)
-			set portversion $portinfo(version)
-			set category [lindex $portinfo(categories) 0]
-			set mpkgfile ${mpkgbase}/${category}/${portname}-${portversion}.mpkg/Contents/Info.plist
-			if {[file readable $mpkgfile] && ([file mtime ${mpkgfile}] > [file mtime ${portpath}/Portfile])} {
-				puts stderr "Skipping ${portname}-${portversion}; meta-package is up to date."
-				continue
+		# Skip up-to-date packages
+		if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
+			if {[info exists portinfo(name)] &&
+				[info exists portinfo(version)] &&
+				[info exists portinfo(categories)]} {
+				set portname $portinfo(name)
+				set portversion $portinfo(version)
+				set category [lindex $portinfo(categories) 0]
+				set mpkgfile ${mpkgbase}/${category}/${portname}-${portversion}.mpkg/Contents/Info.plist
+				if {[file readable $mpkgfile] && ([file mtime ${mpkgfile}] > [file mtime ${portpath}/Portfile])} {
+					puts stderr "Skipping ${portname}-${portversion}; meta-package is up to date."
+					continue
+				}
 			}
 		}
-	}
-	
-	# Skipt packages which previously failed
-		
-	# Building the mpkg:
-	# - create an mpkg skeleton
-	# - copy dependent pkgs into Contents/Resources directory
 
-	set portname ""
-	set portversion ""
-	set description ""
-	set long_description ""
-	set homepage ""
-	set category ""
+		# Skipt packages which previously failed
 
-	if {[info exists portinfo(name)]} {	set portname $portinfo(name) }
-	if {[info exists portinfo(version)]} { set portversion $portinfo(version) }
-	if {[info exists portinfo(description)]} { set description $portinfo(description) }
-	if {[info exists portinfo(long_description)]} { set long_description $portinfo(long_description) }
-	if {[info exists portinfo(homepage)]} { set homepage $portinfo(homepage) }
-	if {[info exists portinfo(categories)]} { set category [lindex $portinfo(categories) 0] }
-	if {[info exists portinfo(maintainers)]} { set maintainers $portinfo(maintainers) }
-	
-	puts "meta-packaging ${category}/${portname}-${portversion}"
+		# Building the mpkg:
+		# - create an mpkg skeleton
+		# - copy dependent pkgs into Contents/Resources directory
 
-	set mpkgpath "${mpkgbase}/${category}/${portname}-${portversion}.mpkg"
+		set portname ""
+		set portversion ""
+		set description ""
+		set long_description ""
+		set homepage ""
+		set category ""
 
-	if {[catch {system "mkdir -p -m 0755 ${mpkgpath}/Contents/Resources"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	
-	# list of .pkg names for dependencies,
-	# built up by copy_package_if_available, and used in the Info.plist
-	set dependencies {}
-	set result [copy_package_if_available ${portname} $pkgbase "${mpkgpath}/Contents/Resources/"]
-	if {$result == -1} {
-		puts stderr "aborting; one or more dependencies was missing."
-		if {[catch {system "rm -R ${mpkgpath}"} error]} {
+		if {[info exists portinfo(name)]} {	set portname $portinfo(name) }
+		if {[info exists portinfo(version)]} { set portversion $portinfo(version) }
+		if {[info exists portinfo(description)]} { set description $portinfo(description) }
+		if {[info exists portinfo(long_description)]} { set long_description $portinfo(long_description) }
+		if {[info exists portinfo(homepage)]} { set homepage $portinfo(homepage) }
+		if {[info exists portinfo(categories)]} { set category [lindex $portinfo(categories) 0] }
+		if {[info exists portinfo(maintainers)]} { set maintainers $portinfo(maintainers) }
+
+		puts "meta-packaging ${category}/${portname}-${portversion}"
+
+		set mpkgpath "${mpkgbase}/${category}/${portname}-${portversion}.mpkg"
+
+		if {[catch {system "mkdir -p -m 0755 ${mpkgpath}/Contents/Resources"} error]} {
 			puts stderr "Internal error: $error"
 		}
-		continue
-	} else {
-		set result [lsort -uniq $result]
-		eval "lappend dependencies $result"
-	}
-	
-	#
-	# Begin quote from portmpkg.tcl
-	#
-    write_PkgInfo ${mpkgpath}/Contents/PkgInfo
-    mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $prefix $dependencies
-    write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description
-    # long_description, description, or homepage may not exist
-    foreach variable {long_description description homepage} {
-	if {![info exists $variable]} {
-	    set pkg_$variable ""
-	} else {
-	    set pkg_$variable [set $variable]
-	}
-    }
-    write_welcome_html ${mpkgpath}/Contents/Resources/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
-    file copy -force -- /opt/local/share/darwinports/resources/port1.0/package/background.tiff \
+
+		# list of .pkg names for dependencies,
+		# built up by copy_package_if_available, and used in the Info.plist
+		set dependencies {}
+		set result [copy_package_if_available ${portname} $pkgbase "${mpkgpath}/Contents/Resources/"]
+		if {$result == -1} {
+			puts stderr "aborting; one or more dependencies was missing."
+			if {[catch {system "rm -R ${mpkgpath}"} error]} {
+				puts stderr "Internal error: $error"
+			}
+			continue
+		} else {
+			set result [lsort -uniq $result]
+			eval "lappend dependencies $result"
+		}
+
+		#
+		# Begin quote from portmpkg.tcl
+		#
+		write_PkgInfo ${mpkgpath}/Contents/PkgInfo
+		mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $prefix $dependencies
+		write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description
+		# long_description, description, or homepage may not exist
+		foreach variable {long_description description homepage} {
+			if {![info exists $variable]} {
+				set pkg_$variable ""
+			} else {
+				set pkg_$variable [set $variable]
+			}
+		}
+		write_welcome_html ${mpkgpath}/Contents/Resources/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
+		file copy -force -- /opt/local/share/darwinports/resources/port1.0/package/background.tiff \
 			${mpkgpath}/Contents/Resources/background.tiff
-	#
-	# End quote from portmpkg.tcl
-	#
+		#
+		# End quote from portmpkg.tcl
+		#
+	}
 }
-
-}
 # end foreach pname

Modified: branches/new-help-system/base/portmgr/packaging/packageall.tcl
===================================================================
--- branches/new-help-system/base/portmgr/packaging/packageall.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/packaging/packageall.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -11,14 +11,14 @@
 # modification, are permitted provided that the following conditions
 # are met:
 # 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
+#	 notice, this list of conditions and the following disclaimer.
 # 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
+#	 notice, this list of conditions and the following disclaimer in the
+#	 documentation and/or other materials provided with the distribution.
 # 3. Neither the name of Apple Inc. nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-# 
+#	 may be used to endorse or promote products derived from this software
+#	 without specific prior written permission.
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -44,82 +44,82 @@
 
 # ui_options accessor
 proc ui_isset {val} {
-    global ui_options
-    if {[info exists ui_options($val)]} {
-	if {$ui_options($val) == "yes"} {
-	    return 1
+	global ui_options
+	if {[info exists ui_options($val)]} {
+		if {$ui_options($val) eq "yes"} {
+			return 1
+		}
 	}
-    }
-    return 0
+	return 0
 }
 
-# UI Callback 
+# UI Callback
 
 proc ui_prefix {priority} {
-    switch $priority {
-        debug {
-        	return "DEBUG: "
-        }
-        error {
-        	return "Error: "
-        }
-        warn {
-        	return "Warning: "
-        }
-        default {
-        	return ""
-        }
-    }
+	switch $priority {
+		debug {
+			return "DEBUG: "
+		}
+		error {
+			return "Error: "
+		}
+		warn {
+			return "Warning: "
+		}
+		default {
+			return ""
+		}
+	}
 }
 
 proc ui_channels {priority} {
-    global logfd
-    switch $priority {
-        debug {
-            if {[ui_isset ports_debug]} {
-            	return {stdout}
-            } else {
-            	return {}
-            }
-        }
-        info {
+	global logfd
+	switch $priority {
+		debug {
+			if {[ui_isset ports_debug]} {
+				return {stdout}
+			} else {
+				return {}
+			}
+		}
+		info {
 			# put verbose stuff only to the log file
-            if {[ui_isset ports_verbose]} {
-                return {$logfd}
-            } else {
-                return {}
+			if {[ui_isset ports_verbose]} {
+				return {$logfd}
+			} else {
+				return {}
 			}
 		}
-        msg {
-            if {[ui_isset ports_quiet]} {
-                return {}
+		msg {
+			if {[ui_isset ports_quiet]} {
+				return {}
 			} else {
 				return {stdout}
 			}
 		}
-        default {
-        	return {stdout}
-        }
-    }
+		default {
+			return {stdout}
+		}
+	}
 }
-	
+
 proc pkg_ui_log {message} {
-    global logfd
-    if {[string length $logfd] > 0 } {
-	log_message $logfd $message
-    }
+	global logfd
+	if {$logfd ne ""} {
+		log_message $logfd $message
+	}
 }
 
 proc log_message {channel message} {
-    seek $channel 0 end
-    puts $channel $message
-    flush $channel
+	seek $channel 0 end
+	puts $channel $message
+	flush $channel
 }
 
 # Recursive bottom-up approach of building a list of dependencies.
 proc get_dependencies {portname includeBuildDeps} {
 	set result {}
-	
+
 	if {[catch {set res [mportsearch "^$portname\$"]} error]} {
 		global errorInfo
 		ui_debug "$errorInfo"
@@ -129,12 +129,12 @@
 	foreach {name array} $res {
 		array set portinfo $array
 		if {![info exists portinfo(name)] ||
-			![info exists portinfo(version)] || 
+			![info exists portinfo(version)] ||
 			![info exists portinfo(categories)]} {
 			ui_error "Internal error: $name missing some portinfo keys"
 			continue
 		}
-		
+
 		set portname $portinfo(name)
 		set portversion $portinfo(version)
 		set category [lindex $portinfo(categories) 0]
@@ -147,16 +147,16 @@
 		set depends {}
 		if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
 		if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
-		if {$includeBuildDeps != "" && [info exists portinfo(depends_build)]} { 
+		if {$includeBuildDeps ne "" && [info exists portinfo(depends_build)]} {
 			eval "lappend depends $portinfo(depends_build)"
 		}
-		if {$includeBuildDeps != "" && [info exists portinfo(depends_fetch)]} { 
+		if {$includeBuildDeps ne "" && [info exists portinfo(depends_fetch)]} {
 			eval "lappend depends $portinfo(depends_fetch)"
 		}
-		if {$includeBuildDeps != "" && [info exists portinfo(depends_extract)]} { 
+		if {$includeBuildDeps ne "" && [info exists portinfo(depends_extract)]} {
 			eval "lappend depends $portinfo(depends_extract)"
 		}
-		
+
 		foreach depspec $depends {
 			set dep [lindex [split $depspec :] end]
 			set x [get_dependencies $dep $includeBuildDeps]
@@ -175,7 +175,7 @@
 	set portname [lindex $dep 0]
 	set portversion [lindex $dep 1]
 	set category [lindex $dep 2]
-	
+
 	set pkgpath ${basepath}/${category}/${portname}-${portversion}.pkg
 	if {[file readable $pkgpath]} {
 		ui_msg "installing binary: $pkgpath"
@@ -194,13 +194,12 @@
 	}
 }
 
-
 # Standard procedures
 
 proc fatal args {
-    global argv0
-    puts stderr "$argv0: $args"
-    exit
+	global argv0
+	puts stderr "$argv0: $args"
+	exit
 }
 
 # Main
@@ -209,8 +208,8 @@
 #	set ui_options(ports_verbose) yes
 
 if {[catch {mportinit ui_options options variations} result]} {
-    puts "Failed to initialize ports system, $result"
-    exit 1
+	puts "Failed to initialize ports system, $result"
+	exit 1
 }
 
 package require Pextlib
@@ -221,210 +220,208 @@
 }
 
 foreach pname $argv {
+	if {[catch {set res [mportsearch "^${pname}\$"]} result]} {
+		puts "port search failed: $result"
+		exit 1
+	}
 
-if {[catch {set res [mportsearch "^${pname}\$"]} result]} {
-	puts "port search failed: $result"
-	exit 1
-}
+	set logpath "/darwinports/logs"
+	set logfd ""
 
-set logpath "/darwinports/logs"
-set logfd ""
+	foreach {name array} $res {
+		array unset portinfo
+		array set portinfo $array
 
-foreach {name array} $res {
-	array unset portinfo
-	array set portinfo $array
+		# Start with verbose output off;
+		# this will prevent the repopulation of /opt/local from getting logged.
+		set ui_options(ports_verbose) no
 
-	# Start with verbose output off;
-	# this will prevent the repopulation of /opt/local from getting logged.
-	set ui_options(ports_verbose) no
+		if {![info exists portinfo(porturl)]} {
+			puts stderr "Internal error: no porturl for $name"
+			continue
+		}
 
-	if {![info exists portinfo(porturl)]} {
-		puts stderr "Internal error: no porturl for $name"
-		continue
-	}
-	
-	set pkgbase /darwinports/pkgs/
-	set porturl $portinfo(porturl)
+		set pkgbase /darwinports/pkgs/
+		set porturl $portinfo(porturl)
 
-	# Skip up-to-date packages
-	if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
-		if {[info exists portinfo(name)] &&
-			[info exists portinfo(version)] &&
-			[info exists portinfo(categories)]} {
-			set portname $portinfo(name)
-			set portversion $portinfo(version)
-			set category [lindex $portinfo(categories) 0]
-			set pkgfile ${pkgbase}/${category}/${portname}-${portversion}.pkg/Contents/Archive.pax.gz
-			if {[file readable $pkgfile] && ([file mtime ${pkgfile}] > [file mtime ${portpath}/Portfile])} {
-				puts stderr "Skipping ${portname}-${portversion}; package is up to date."
-				continue
+		# Skip up-to-date packages
+		if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
+			if {[info exists portinfo(name)] &&
+				[info exists portinfo(version)] &&
+				[info exists portinfo(categories)]} {
+				set portname $portinfo(name)
+				set portversion $portinfo(version)
+				set category [lindex $portinfo(categories) 0]
+				set pkgfile ${pkgbase}/${category}/${portname}-${portversion}.pkg/Contents/Archive.pax.gz
+				if {[file readable $pkgfile] && ([file mtime ${pkgfile}] > [file mtime ${portpath}/Portfile])} {
+					puts stderr "Skipping ${portname}-${portversion}; package is up to date."
+					continue
+				}
 			}
 		}
-	}
-	
-	# Skipt packages which previously failed
-		
-	# Building the port:
-	# - remove /opt/local so it won't pollute the port.
-	# - re-install MacPorts.
-	# - keep distfiles outside /opt/local so we don't have to keep fetching them.
-	# - send out an email to the maintainer if any errors occurred.
 
-	ui_msg "removing /opt/local"
-	#unset ui_options(ports_verbose)
-	if {[catch {system "rm -Rf /opt/local"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "rm -Rf /usr/X11R6"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "rm -Rf /etc/X11"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "rm -Rf /etc/fonts"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "cd $env(HOME)/darwinports && make && make install"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "rmdir /opt/local/var/db/dports/distfiles"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "ln -s /darwinports/distfiles /opt/local/var/db/dports/distfiles"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	#set ui_options(ports_verbose) yes
+		# Skipt packages which previously failed
 
-	# If there was a log file left over from the previous pass,
-	# then the port failed with an error.  Send the log in an
-	# email to the maintainers.
-	if {[string length $logfd] > 0} {
-		close $logfd
-		set logfd ""
-	}
-	#if {[file readable $logfilename]} {
-	#	if {[catch {system "<$logfilename /usr/sbin/sendmail -t"} error]} {
-	#		puts stderr "Internal error: $error"
-	#	}
-	#}
+		# Building the port:
+		# - remove /opt/local so it won't pollute the port.
+		# - re-install MacPorts.
+		# - keep distfiles outside /opt/local so we don't have to keep fetching them.
+		# - send out an email to the maintainer if any errors occurred.
 
-	# Open the log file for writing
-	set logfd [open ${logpath}/${name}.log w]
+		ui_msg "removing /opt/local"
+		#unset ui_options(ports_verbose)
+		if {[catch {system "rm -Rf /opt/local"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "rm -Rf /usr/X11R6"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "rm -Rf /etc/X11"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "rm -Rf /etc/fonts"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "cd $env(HOME)/darwinports && make && make install"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "rmdir /opt/local/var/db/dports/distfiles"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "ln -s /darwinports/distfiles /opt/local/var/db/dports/distfiles"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		#set ui_options(ports_verbose) yes
 
-	set valid 1
+		# If there was a log file left over from the previous pass,
+		# then the port failed with an error.  Send the log in an
+		# email to the maintainers.
+		if {$logfd ne ""} {
+			close $logfd
+			set logfd ""
+		}
+		#if {[file readable $logfilename]} {
+		#	if {[catch {system "<$logfilename /usr/sbin/sendmail -t"} error]} {
+		#		puts stderr "Internal error: $error"
+		#	}
+		#}
 
-	set lint_errors {}
-	set portname ""
-	set portversion ""
-	set description ""
-	set category ""
+		# Open the log file for writing
+		set logfd [open ${logpath}/${name}.log w]
 
-	if {![info exists portinfo(name)]} {
-		lappend lint_errors "missing name key"
-		set valid 0
-	} else {
-		set portname $portinfo(name)
-	}
-	
-	if {![info exists portinfo(description)]} {
-		lappend lint_errors "missing description key"
-		set valid 0
-	} else {
-		set description $portinfo(description)
-	}
-	
-	if {![info exists portinfo(version)]} {
-		lappend lint_errors "missing version key"
-		set valid 0
-	} else {
-		set portversion $portinfo(version)
-	}
-	
-	if {![info exists portinfo(categories)]} {
-		lappend lint_errors "missing categories key"
-		set valid 0
-	} else {
-		set category [lindex $portinfo(categories) 0]
-	}
-	
-	if {![info exists portinfo(maintainers)]} {
-		append lint_errors "missing maintainers key"
-		set valid 0
-		set maintainers kevin at opendarwin.org
-	} else {
-		set maintainers $portinfo(maintainers)
-	}
-	
-	pkg_ui_log "To: [join $maintainers {, }]"
-	pkg_ui_log "From: donotreply at opendarwin.org"
-	pkg_ui_log "Subject: MacPorts $portinfo(name)-$portinfo(version) build failure"
-	pkg_ui_log ""
-	pkg_ui_log "The following is a transcript produced by the MacPorts automated build       "
-	pkg_ui_log "system.  You are receiving this email because you are listed as a maintainer    "
-	pkg_ui_log "of this port, which has failed the automated packaging process.  Please update  "
-	pkg_ui_log "the port as soon as possible."
-	pkg_ui_log ""
-	pkg_ui_log ""
-	pkg_ui_log "Thank you,"
-	pkg_ui_log "The MacPorts Team"
-	pkg_ui_log ""
-	pkg_ui_log "================================================================================"
-	pkg_ui_log ""
+		set valid 1
 
-	if {!$valid} {
-		foreach error $lint_errors {
-			ui_error $error
+		set lint_errors {}
+		set portname ""
+		set portversion ""
+		set description ""
+		set category ""
+
+		if {![info exists portinfo(name)]} {
+			lappend lint_errors "missing name key"
+			set valid 0
+		} else {
+			set portname $portinfo(name)
 		}
-	}
 
-	ui_msg "packaging ${category}/${portname}-${portversion}"
+		if {![info exists portinfo(description)]} {
+			lappend lint_errors "missing description key"
+			set valid 0
+		} else {
+			set description $portinfo(description)
+		}
 
-	# Install binary dependencies if we can, to speed things up.
-	#set depends {}
-	#if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
-	#if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
-	#if {[info exists portinfo(depends_build)]} { eval "lappend depends $portinfo(depends_build)" }
-	#foreach depspec $depends {
-	#	set dep [lindex [split $depspec :] end]
-		#install_binary_if_available $dep $pkgbase
-	#}
-	set dependencies [get_dependencies $portname 1]
-	set dependencies [lsort -unique $dependencies]
-	foreach dep $dependencies {
-		install_binary_if_available $dep $pkgbase
-	}
+		if {![info exists portinfo(version)]} {
+			lappend lint_errors "missing version key"
+			set valid 0
+		} else {
+			set portversion $portinfo(version)
+		}
 
-	set options(package.type) pkg
-	set options(package.destpath) ${pkgbase}/${category}/
+		if {![info exists portinfo(categories)]} {
+			lappend lint_errors "missing categories key"
+			set valid 0
+		} else {
+			set category [lindex $portinfo(categories) 0]
+		}
 
-	# Turn on verbose output for the build
-	set ui_options(ports_verbose) yes
-	set options(subport) $name
-	if {[catch {set workername [mportopen $porturl [array get options] [array get variations] yes]} result] ||
-		$result == 1} {
-		global errorInfo
-		ui_debug "$errorInfo"
-	    ui_error "Internal error: unable to open port: $result"
-	    continue
-	}	
-	if {[catch {set result [mportexec $workername pkg]} result] ||
-		$result == 1} {
-		global errorInfo
-		ui_debug "$errorInfo"
-	    ui_error "port package failed: $result"
-		mportclose $workername
-	    continue
-	}
-	set ui_options(ports_verbose) no
-	# Turn verbose output off after the build
+		if {![info exists portinfo(maintainers)]} {
+			append lint_errors "missing maintainers key"
+			set valid 0
+			set maintainers kevin at opendarwin.org
+		} else {
+			set maintainers $portinfo(maintainers)
+		}
 
-	mportclose $workername
+		pkg_ui_log "To: [join $maintainers {, }]"
+		pkg_ui_log "From: donotreply at opendarwin.org"
+		pkg_ui_log "Subject: MacPorts $portinfo(name)-$portinfo(version) build failure"
+		pkg_ui_log ""
+		pkg_ui_log "The following is a transcript produced by the MacPorts automated build		 "
+		pkg_ui_log "system.  You are receiving this email because you are listed as a maintainer	"
+		pkg_ui_log "of this port, which has failed the automated packaging process.  Please update	"
+		pkg_ui_log "the port as soon as possible."
+		pkg_ui_log ""
+		pkg_ui_log ""
+		pkg_ui_log "Thank you,"
+		pkg_ui_log "The MacPorts Team"
+		pkg_ui_log ""
+		pkg_ui_log "================================================================================"
+		pkg_ui_log ""
 
-	# We made it to the end.  We can delete the log file.
-	close $logfd
-	set logfd ""
-	file delete ${logpath}/${name}.log
-}
+		if {!$valid} {
+			foreach error $lint_errors {
+				ui_error $error
+			}
+		}
 
+		ui_msg "packaging ${category}/${portname}-${portversion}"
+
+		# Install binary dependencies if we can, to speed things up.
+		#set depends {}
+		#if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
+		#if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
+		#if {[info exists portinfo(depends_build)]} { eval "lappend depends $portinfo(depends_build)" }
+		#foreach depspec $depends {
+		#	set dep [lindex [split $depspec :] end]
+			#install_binary_if_available $dep $pkgbase
+		#}
+		set dependencies [get_dependencies $portname 1]
+		set dependencies [lsort -unique $dependencies]
+		foreach dep $dependencies {
+			install_binary_if_available $dep $pkgbase
+		}
+
+		set options(package.type) pkg
+		set options(package.destpath) ${pkgbase}/${category}/
+
+		# Turn on verbose output for the build
+		set ui_options(ports_verbose) yes
+		set options(subport) $name
+		if {[catch {set workername [mportopen $porturl [array get options] [array get variations] yes]} result] ||
+			$result == 1} {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error "Internal error: unable to open port: $result"
+			continue
+		}
+		if {[catch {set result [mportexec $workername pkg]} result] ||
+			$result == 1} {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error "port package failed: $result"
+			mportclose $workername
+			continue
+		}
+		set ui_options(ports_verbose) no
+		# Turn verbose output off after the build
+
+		mportclose $workername
+
+		# We made it to the end.  We can delete the log file.
+		close $logfd
+		set logfd ""
+		file delete ${logpath}/${name}.log
+	}
 }
 # end foreach pname

Modified: branches/new-help-system/base/portmgr/packaging/rpmall.tcl
===================================================================
--- branches/new-help-system/base/portmgr/packaging/rpmall.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/portmgr/packaging/rpmall.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -12,14 +12,14 @@
 # modification, are permitted provided that the following conditions
 # are met:
 # 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
+#	 notice, this list of conditions and the following disclaimer.
 # 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
+#	 notice, this list of conditions and the following disclaimer in the
+#	 documentation and/or other materials provided with the distribution.
 # 3. Neither the name of Apple Inc. nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-# 
+#	 may be used to endorse or promote products derived from this software
+#	 without specific prior written permission.
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -45,84 +45,84 @@
 
 # ui_options accessor
 proc ui_isset {val} {
-    global ui_options
-    if {[info exists ui_options($val)]} {
-	if {$ui_options($val) == "yes"} {
-	    return 1
+	global ui_options
+	if {[info exists ui_options($val)]} {
+		if {$ui_options($val) eq "yes"} {
+			return 1
+		}
 	}
-    }
-    return 0
+	return 0
 }
 
 set options(package.destpath) "/darwinports/rpms"
 
-# UI Callback 
+# UI Callback
 
 proc ui_prefix {priority} {
-    switch $priority {
-        debug {
-        	return "DEBUG: "
-        }
-        error {
-        	return "Error: "
-        }
-        warn {
-        	return "Warning: "
-        }
-        default {
-        	return ""
-        }
-    }
+	switch $priority {
+		debug {
+			return "DEBUG: "
+		}
+		error {
+			return "Error: "
+		}
+		warn {
+			return "Warning: "
+		}
+		default {
+			return ""
+		}
+	}
 }
 
 proc ui_channels {priority} {
-    global logfd
-    switch $priority {
-        debug {
-            if {[ui_isset ports_debug]} {
-            	return {stdout}
-            } else {
-            	return {}
-            }
-        }
-        info {
+	global logfd
+	switch $priority {
+		debug {
+			if {[ui_isset ports_debug]} {
+				return {stdout}
+			} else {
+				return {}
+			}
+		}
+		info {
 			# put verbose stuff only to the log file
-            if {[ui_isset ports_verbose]} {
-                return {$logfd}
-            } else {
-                return {}
+			if {[ui_isset ports_verbose]} {
+				return {$logfd}
+			} else {
+				return {}
 			}
 		}
-        msg {
-            if {[ui_isset ports_quiet]} {
-                return {}
+		msg {
+			if {[ui_isset ports_quiet]} {
+				return {}
 			} else {
 				return {stdout}
 			}
 		}
-        default {
-        	return {stdout}
-        }
-    }
+		default {
+			return {stdout}
+		}
+	}
 }
-	
+
 proc pkg_ui_log {message} {
-    global logfd
-    if {[string length $logfd] > 0 } {
-	log_message $logfd $message
-    }
+	global logfd
+	if {$logfd ne ""} {
+		log_message $logfd $message
+	}
 }
 
 proc log_message {channel message} {
-    seek $channel 0 end
-    puts $channel $message
-    flush $channel
+	seek $channel 0 end
+	puts $channel $message
+	flush $channel
 }
 
 # Recursive bottom-up approach of building a list of dependencies.
 proc get_dependencies {portname includeBuildDeps} {
 	set result {}
-	
+
 	if {[catch {set search [mportsearch "^$portname\$"]} error]} {
 		global errorInfo
 		ui_debug "$errorInfo"
@@ -132,7 +132,7 @@
 	foreach {name array} $search {
 		array set portinfo $array
 		if {![info exists portinfo(name)] ||
-			![info exists portinfo(version)] || 
+			![info exists portinfo(version)] ||
 			![info exists portinfo(categories)]} {
 			ui_error "Internal error: $name missing some portinfo keys"
 			continue
@@ -140,7 +140,7 @@
 		if {![info exists portinfo(revision)]} {
 			set portinfo(revision) 0
 		}
-		
+
 		set portname $portinfo(name)
 		set portversion $portinfo(version)
 		set revision $portinfo(revision)
@@ -152,13 +152,13 @@
 		set depends {}
 		if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
 		if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
-		if {$includeBuildDeps != "" && [info exists portinfo(depends_build)]} { 
+		if {$includeBuildDeps ne "" && [info exists portinfo(depends_build)]} {
 			eval "lappend depends $portinfo(depends_build)"
 		}
-		if {$includeBuildDeps != "" && [info exists portinfo(depends_fetch)]} { 
+		if {$includeBuildDeps ne "" && [info exists portinfo(depends_fetch)]} {
 			eval "lappend depends $portinfo(depends_fetch)"
 		}
-		if {$includeBuildDeps != "" && [info exists portinfo(depends_extract)]} { 
+		if {$includeBuildDeps ne "" && [info exists portinfo(depends_extract)]} {
 			eval "lappend depends $portinfo(depends_extract)"
 		}
 		foreach depspec $depends {
@@ -202,9 +202,9 @@
 # Standard procedures
 
 proc fatal args {
-    global argv0
-    puts stderr "$argv0: $args"
-    exit
+	global argv0
+	puts stderr "$argv0: $args"
+	exit
 }
 
 # Main
@@ -217,8 +217,8 @@
 }
 
 if {[catch {mportinit ui_options options variations} result]} {
-    puts "Failed to initialize ports system, $result"
-    exit 1
+	puts "Failed to initialize ports system, $result"
+	exit 1
 }
 
 package require Pextlib
@@ -229,275 +229,274 @@
 }
 
 foreach pname $argv {
+	if {[catch {set allpackages [mportsearch "^${pname}\$"]} result]} {
+		puts "port search failed: $result"
+		exit 1
+	}
 
-if {[catch {set allpackages [mportsearch "^${pname}\$"]} result]} {
-	puts "port search failed: $result"
-	exit 1
-}
+	set logpath "/darwinports/logs"
+	set logfd ""
 
-set logpath "/darwinports/logs"
-set logfd ""
+	foreach {name array} $allpackages {
+		array unset portinfo
+		array set portinfo $array
 
-foreach {name array} $allpackages {
-	array unset portinfo
-	array set portinfo $array
+		#ui_msg "foo $portinfo(porturl)"
 
-	#ui_msg "foo $portinfo(porturl)"
+		# Start with verbose output off;
+		# this will prevent the repopulation of /opt/local from getting logged.
+		set ui_options(ports_verbose) no
 
-	# Start with verbose output off;
-	# this will prevent the repopulation of /opt/local from getting logged.
-	set ui_options(ports_verbose) no
+		if {![info exists portinfo(porturl)]} {
+			puts stderr "Internal error: no porturl for $name"
+			continue
+		}
+		if {![info exists portinfo(revision)]} {
+			set portinfo(revision) 0
+		}
 
-	if {![info exists portinfo(porturl)]} {
-		puts stderr "Internal error: no porturl for $name"
-		continue
-	}
-	if {![info exists portinfo(revision)]} {
-		set portinfo(revision) 0
-	}
+		set porturl $portinfo(porturl)
 
-	set porturl $portinfo(porturl)
+		# this is used to short-circuit the RPM check and
+		# move on to the next package
 
-	# this is used to short-circuit the RPM check and
-	# move on to the next package
+		global exit_loop
+		set exit_loop false
 
-	global exit_loop
-	set exit_loop false
+		# Skip up-to-date packages
+		if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
+			if {[info exists portinfo(name)] &&
+				[info exists portinfo(version)] &&
+				[info exists portinfo(revision)]} {
+				set portname $portinfo(name)
+				set portversion $portinfo(version)
+				set revision $portinfo(revision)
 
-	# Skip up-to-date packages
-	if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
-		if {[info exists portinfo(name)] &&
-			[info exists portinfo(version)] &&
-			[info exists portinfo(revision)]} {
-			set portname $portinfo(name)
-			set portversion $portinfo(version)
-			set revision $portinfo(revision)
-
-			foreach dir {"/opt/local/src/apple/RPMS" "/usr/src/apple/RPMS" "/darwinports/rpms/RPMS"} {
-				foreach arch {"ppc" "i386" "fat"} {
-					set rpmpath "${dir}/${arch}/${portname}-${portversion}-${revision}.${arch}.rpm"
-					#ui_msg "trying ${rpmpath}"
-					if {[file readable $rpmpath] && ([file mtime ${rpmpath}] >= [file mtime ${portpath}/Portfile])} {
-						puts stderr "->    skipping ${portname}-${portversion}; package is up to date."
-						set exit_loop true
+				foreach dir {"/opt/local/src/apple/RPMS" "/usr/src/apple/RPMS" "/darwinports/rpms/RPMS"} {
+					foreach arch {"ppc" "i386" "fat"} {
+						set rpmpath "${dir}/${arch}/${portname}-${portversion}-${revision}.${arch}.rpm"
+						#ui_msg "trying ${rpmpath}"
+						if {[file readable $rpmpath] && ([file mtime ${rpmpath}] >= [file mtime ${portpath}/Portfile])} {
+							puts stderr "->    skipping ${portname}-${portversion}; package is up to date."
+							set exit_loop true
+							break
+						}
+					}
+					if {${exit_loop}} {
 						break
 					}
 				}
-				if {${exit_loop}} {
-					break
+			}
+		}
+		if {${exit_loop}} {
+			continue
+		}
+
+		# Skip packages which previously failed
+		set exit_loop false
+
+		# Skip up-to-date packages
+		if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
+			if {[info exists portinfo(name)] &&
+				[info exists portinfo(version)] &&
+				[info exists portinfo(revision)]} {
+				set portname $portinfo(name)
+				set portversion $portinfo(version)
+				set revision $portinfo(revision)
+
+				set logfilepath "${logpath}/${portname}.log"
+				if {[file readable ${logfilepath}] && ([file mtime ${logfilepath}] > [file mtime ${portpath}/Portfile])} {
+					puts stderr "->    skipping ${portname}-${portversion}; package failed, but has not changed."
+					set exit_loop true
 				}
 			}
 		}
-	}
-	if {${exit_loop}} {
-		continue
-	}
-	
-	# Skip packages which previously failed
-	set exit_loop false
-		
-	# Skip up-to-date packages
-	if {[regsub {^file://} $portinfo(porturl) "" portpath]} {
-		if {[info exists portinfo(name)] &&
-			[info exists portinfo(version)] &&
-			[info exists portinfo(revision)]} {
-			set portname $portinfo(name)
-			set portversion $portinfo(version)
-			set revision $portinfo(revision)
+		if {${exit_loop}} {
+			continue
+		}
 
-			set logfilepath "${logpath}/${portname}.log"
-			if {[file readable ${logfilepath}] && ([file mtime ${logfilepath}] > [file mtime ${portpath}/Portfile])} {
-				puts stderr "->    skipping ${portname}-${portversion}; package failed, but has not changed."
-				set exit_loop true
+		# Building the port:
+		# - remove /opt/local so it won't pollute the port.
+		# - re-install MacPorts.
+		# - keep distfiles outside /opt/local so we don't have to keep fetching them.
+		# - send out an email to the maintainer if any errors occurred.
+
+		set remove_files ""
+		foreach dir {"/opt/local/src/apple/RPMS" "/usr/src/apple/RPMS" "/darwinports/rpms/RPMS"} {
+			foreach arch {"ppc" "i386" "fat"} {
+				set remove_files "${remove_files} '${dir}/${arch}/'*.rpm"
 			}
 		}
-	}
-	if {${exit_loop}} {
-		continue
-	}
-	
-	# Building the port:
-	# - remove /opt/local so it won't pollute the port.
-	# - re-install MacPorts.
-	# - keep distfiles outside /opt/local so we don't have to keep fetching them.
-	# - send out an email to the maintainer if any errors occurred.
+		system "rpm -q --queryformat='%{name} ' -p ${remove_files} | xargs rpm -e || true"
 
-	set remove_files ""
-	foreach dir {"/opt/local/src/apple/RPMS" "/usr/src/apple/RPMS" "/darwinports/rpms/RPMS"} {
-		foreach arch {"ppc" "i386" "fat"} {
-			set remove_files "${remove_files} '${dir}/${arch}/'*.rpm"
+		ui_msg "->	  Removing /opt/local"
+		#unset ui_options(ports_verbose)
+		if {[catch {system "rm -Rf /opt/local"} error]} {
+			puts stderr "Internal error: $error"
 		}
-	}
-	system "rpm -q --queryformat='%{name} ' -p ${remove_files} | xargs rpm -e || true"
+		# this is bad on pure darwin  :)
+		#if {[catch {system "rm -Rf /usr/X11R6"} error]} {
+		#	puts stderr "Internal error: $error"
+		#}
+		#if {[catch {system "rm -Rf /etc/X11"} error]} {
+		#	puts stderr "Internal error: $error"
+		#}
+		#if {[catch {system "rm -Rf /etc/fonts"} error]} {
+		#	puts stderr "Internal error: $error"
+		#}
+		ui_msg "->	  Installing MacPorts"
+		if {[catch {system "cd $env(HOME)/darwinports && make && make install"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "rmdir /opt/local/var/db/dports/distfiles"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		if {[catch {system "ln -s /darwinports/distfiles /opt/local/var/db/dports/distfiles"} error]} {
+			puts stderr "Internal error: $error"
+		}
+		#set ui_options(ports_verbose) yes
 
-	ui_msg "->    Removing /opt/local"
-	#unset ui_options(ports_verbose)
-	if {[catch {system "rm -Rf /opt/local"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	# this is bad on pure darwin  :)
-	#if {[catch {system "rm -Rf /usr/X11R6"} error]} {
-	#	puts stderr "Internal error: $error"
-	#}
-	#if {[catch {system "rm -Rf /etc/X11"} error]} {
-	#	puts stderr "Internal error: $error"
-	#}
-	#if {[catch {system "rm -Rf /etc/fonts"} error]} {
-	#	puts stderr "Internal error: $error"
-	#}
-	ui_msg "->    Installing MacPorts"
-	if {[catch {system "cd $env(HOME)/darwinports && make && make install"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "rmdir /opt/local/var/db/dports/distfiles"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	if {[catch {system "ln -s /darwinports/distfiles /opt/local/var/db/dports/distfiles"} error]} {
-		puts stderr "Internal error: $error"
-	}
-	#set ui_options(ports_verbose) yes
+		# If there was a log file left over from the previous pass,
+		# then the port failed with an error.  Send the log in an
+		# email to the maintainers.
+		if {$logfd ne ""} {
+			close $logfd
+			set logfd ""
+		}
+		#if {[file readable $logfilename]} {
+		#	if {[catch {system "<$logfilename /usr/sbin/sendmail -t"} error]} {
+		#		puts stderr "Internal error: $error"
+		#	}
+		#}
 
-	# If there was a log file left over from the previous pass,
-	# then the port failed with an error.  Send the log in an
-	# email to the maintainers.
-	if {[string length $logfd] > 0} {
-		close $logfd
-		set logfd ""
-	}
-	#if {[file readable $logfilename]} {
-	#	if {[catch {system "<$logfilename /usr/sbin/sendmail -t"} error]} {
-	#		puts stderr "Internal error: $error"
-	#	}
-	#}
+		# Open the log file for writing
+		set logfd [open ${logpath}/${name}.log w]
 
-	# Open the log file for writing
-	set logfd [open ${logpath}/${name}.log w]
+		set valid 1
 
-	set valid 1
+		set lint_errors {}
+		set portname ""
+		set portversion ""
+		set description ""
+		set category ""
 
-	set lint_errors {}
-	set portname ""
-	set portversion ""
-	set description ""
-	set category ""
+		if {![info exists portinfo(name)]} {
+			lappend lint_errors "missing name key"
+			set valid 0
+		} else {
+			set portname $portinfo(name)
+		}
 
-	if {![info exists portinfo(name)]} {
-		lappend lint_errors "missing name key"
-		set valid 0
-	} else {
-		set portname $portinfo(name)
-	}
-	
-	if {![info exists portinfo(description)]} {
-		lappend lint_errors "missing description key"
-		set valid 0
-	} else {
-		set description $portinfo(description)
-	}
-	
-	if {![info exists portinfo(version)]} {
-		lappend lint_errors "missing version key"
-		set valid 0
-	} else {
-		set portversion $portinfo(version)
-	}
-	
-	if {![info exists portinfo(categories)]} {
-		lappend lint_errors "missing categories key"
-		set valid 0
-	} else {
-		set category [lindex $portinfo(categories) 0]
-	}
-	
-	if {![info exists portinfo(maintainers)]} {
-		append lint_errors "missing maintainers key"
-		set valid 0
-		set maintainers kevin at opendarwin.org
-	} else {
-		set maintainers $portinfo(maintainers)
-	}
-	
-	pkg_ui_log "To: [join $maintainers {, }]"
-	pkg_ui_log "From: donotreply at opendarwin.org"
-	pkg_ui_log "Subject: MacPorts $portinfo(name)-$portinfo(version) build failure"
-	pkg_ui_log ""
-	pkg_ui_log "The following is a transcript produced by the MacPorts automated build       "
-	pkg_ui_log "system.  You are receiving this email because you are listed as a maintainer    "
-	pkg_ui_log "of this port, which has failed the automated packaging process.  Please update  "
-	pkg_ui_log "the port as soon as possible."
-	pkg_ui_log ""
-	pkg_ui_log ""
-	pkg_ui_log "Thank you,"
-	pkg_ui_log "The MacPorts Team"
-	pkg_ui_log ""
-	pkg_ui_log "================================================================================"
-	pkg_ui_log ""
+		if {![info exists portinfo(description)]} {
+			lappend lint_errors "missing description key"
+			set valid 0
+		} else {
+			set description $portinfo(description)
+		}
 
-	if {!$valid} {
-		foreach error $lint_errors {
-			ui_error $error
+		if {![info exists portinfo(version)]} {
+			lappend lint_errors "missing version key"
+			set valid 0
+		} else {
+			set portversion $portinfo(version)
 		}
-	}
 
-	ui_msg "-->   Packaging ${category}/${portname}-${portversion}"
+		if {![info exists portinfo(categories)]} {
+			lappend lint_errors "missing categories key"
+			set valid 0
+		} else {
+			set category [lindex $portinfo(categories) 0]
+		}
 
-	foreach prebuild {"ccache" "rpm" "unzip"} {
-		if {![file exists /bin/${prebuild}] && ![file exists /usr/bin/${prebuild}]} {
-			ui_msg "--->  Pre-installing ${prebuild}"
-			if {[catch {set search [mportsearch "^${prebuild}\$"]} error]} {
-				global errorInfo
-				ui_debug "$errorInfo"
-				ui_error "Internal error: port search ${prebuild} failed: $error"
+		if {![info exists portinfo(maintainers)]} {
+			append lint_errors "missing maintainers key"
+			set valid 0
+			set maintainers kevin at opendarwin.org
+		} else {
+			set maintainers $portinfo(maintainers)
+		}
+
+		pkg_ui_log "To: [join $maintainers {, }]"
+		pkg_ui_log "From: donotreply at opendarwin.org"
+		pkg_ui_log "Subject: MacPorts $portinfo(name)-$portinfo(version) build failure"
+		pkg_ui_log ""
+		pkg_ui_log "The following is a transcript produced by the MacPorts automated build		 "
+		pkg_ui_log "system.  You are receiving this email because you are listed as a maintainer	"
+		pkg_ui_log "of this port, which has failed the automated packaging process.  Please update	"
+		pkg_ui_log "the port as soon as possible."
+		pkg_ui_log ""
+		pkg_ui_log ""
+		pkg_ui_log "Thank you,"
+		pkg_ui_log "The MacPorts Team"
+		pkg_ui_log ""
+		pkg_ui_log "================================================================================"
+		pkg_ui_log ""
+
+		if {!$valid} {
+			foreach error $lint_errors {
+				ui_error $error
 			}
-			array set prebuildinfo [lindex $search 1]
-			set ui_options(ports_verbose) yes
-			set options(subport) ${prebuild}
-			if {[catch {set workername [mportopen $prebuildinfo(porturl) [array get options] [array get variations] yes]} result] ||
-				$result == 1} {
-				global errorInfo
-				ui_debug "$errorInfo"
-				ui_error "Internal error: unable to install ${prebuild}... exiting"
-				exit 1
+		}
+
+		ui_msg "-->   Packaging ${category}/${portname}-${portversion}"
+
+		foreach prebuild {"ccache" "rpm" "unzip"} {
+			if {![file exists /bin/${prebuild}] && ![file exists /usr/bin/${prebuild}]} {
+				ui_msg "--->  Pre-installing ${prebuild}"
+				if {[catch {set search [mportsearch "^${prebuild}\$"]} error]} {
+					global errorInfo
+					ui_debug "$errorInfo"
+					ui_error "Internal error: port search ${prebuild} failed: $error"
+				}
+				array set prebuildinfo [lindex $search 1]
+				set ui_options(ports_verbose) yes
+				set options(subport) ${prebuild}
+				if {[catch {set workername [mportopen $prebuildinfo(porturl) [array get options] [array get variations] yes]} result] ||
+					$result == 1} {
+					global errorInfo
+					ui_debug "$errorInfo"
+					ui_error "Internal error: unable to install ${prebuild}... exiting"
+					exit 1
+				}
+				if {[catch {set result [mportexec $workername activate]} result] ||
+					$result == 1} {
+					global errorInfo
+					ui_debug "$errorInfo"
+					ui_error "installation of ${prebuild} failed: $result"
+					mportclose $workername
+					exit 1
+				}
 			}
-			if {[catch {set result [mportexec $workername activate]} result] ||
-				$result == 1} {
-				global errorInfo
-				ui_debug "$errorInfo"
-				ui_error "installation of ${prebuild} failed: $result"
-				mportclose $workername
-				exit 1
-			}
 		}
-	}
 
-	# Turn on verbose output for the build
-	set ui_options(ports_verbose) yes
-	set options(subport) $name
-	if {[catch {set workername [mportopen $porturl [array get options] [array get variations]]} result] ||
-		$result == 1} {
-		global errorInfo
-		ui_debug "$errorInfo"
-	    ui_error "Internal error: unable to open port: $result"
-	    continue
-	}
-	if {[catch {set result [mportexec $workername rpmpackage]} result] ||
-		$result == 1} {
-		global errorInfo
-		ui_debug "$errorInfo"
-	    ui_error "port package failed: $result"
+		# Turn on verbose output for the build
+		set ui_options(ports_verbose) yes
+		set options(subport) $name
+		if {[catch {set workername [mportopen $porturl [array get options] [array get variations]]} result] ||
+			$result == 1} {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error "Internal error: unable to open port: $result"
+			continue
+		}
+		if {[catch {set result [mportexec $workername rpmpackage]} result] ||
+			$result == 1} {
+			global errorInfo
+			ui_debug "$errorInfo"
+			ui_error "port package failed: $result"
+			mportclose $workername
+			continue
+		}
+		set ui_options(ports_verbose) no
+		# Turn verbose output off after the build
+
 		mportclose $workername
-	    continue
+
+		# We made it to the end.  We can delete the log file.
+		close $logfd
+		set logfd ""
+		file delete ${logpath}/${name}.log
 	}
-	set ui_options(ports_verbose) no
-	# Turn verbose output off after the build
 
-	mportclose $workername
-
-	# We made it to the end.  We can delete the log file.
-	close $logfd
-	set logfd ""
-	file delete ${logpath}/${name}.log
 }
-
-}
 # end foreach pname

Modified: branches/new-help-system/base/src/Makefile.in
===================================================================
--- branches/new-help-system/base/src/Makefile.in	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/Makefile.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -8,7 +8,7 @@
 			machista1.0
 SUBDIR=		${TCLPKG} port programs
 
-ifeq ($(shell uname),Darwin)
+ifeq (@TRACEMODE_SUPPORT@,1)
 TCLPKG+= darwintracelib1.0
 endif
 

Modified: branches/new-help-system/base/src/config.h.in
===================================================================
--- branches/new-help-system/base/src/config.h.in	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/config.h.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -67,6 +67,9 @@
 /* Define to 1 if you have the `flock' function. */
 #undef HAVE_FLOCK
 
+/* Define to 1 if you have the `fls' function. */
+#undef HAVE_FLS
+
 /* Define if CoreFoundation framework is available */
 #undef HAVE_FRAMEWORK_COREFOUNDATION
 
@@ -83,12 +86,18 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the `kevent' function. */
+#undef HAVE_KEVENT
+
 /* Define to 1 if you have the `kqueue' function. */
 #undef HAVE_KQUEUE
 
 /* Define if you have the `crypto' library (-lcrypto). */
 #undef HAVE_LIBCRYPTO
 
+/* Define to 1 if you have the <libkern/OSAtomic.h> header file. */
+#undef HAVE_LIBKERN_OSATOMIC_H
+
 /* Define if you have the `md' library (-lmd). */
 #undef HAVE_LIBMD
 
@@ -125,9 +134,21 @@
 /* Define to 1 if you have the <openssl/sha.h> header file. */
 #undef HAVE_OPENSSL_SHA_H
 
+/* Define to 1 if you have the `OSAtomicCompareAndSwap32' function. */
+#undef HAVE_OSATOMICCOMPAREANDSWAP32
+
+/* Define to 1 if you have the `OSAtomicCompareAndSwap64' function. */
+#undef HAVE_OSATOMICCOMPAREANDSWAP64
+
+/* Define to 1 if you have the `OSAtomicCompareAndSwapPtr' function. */
+#undef HAVE_OSATOMICCOMPAREANDSWAPPTR
+
 /* Define to 1 if you have the <paths.h> header file. */
 #undef HAVE_PATHS_H
 
+/* Define to 1 if you have the `posix_spawn' function. */
+#undef HAVE_POSIX_SPAWN
+
 /* Define if you have POSIX threads libraries and header files. */
 #undef HAVE_PTHREAD
 
@@ -158,6 +179,9 @@
 /* Define to 1 if you have the <sha.h> header file. */
 #undef HAVE_SHA_H
 
+/* Define to 1 if you have the <spawn.h> header file. */
+#undef HAVE_SPAWN_H
+
 /* Define to 1 if you have the <sqlite3ext.h> header file. */
 #undef HAVE_SQLITE3EXT_H
 
@@ -226,6 +250,9 @@
 /* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
 #undef HAVE_SYS_WAIT_H
 
+/* Platform supports tracemode. */
+#undef HAVE_TRACEMODE_SUPPORT
+
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 

Modified: branches/new-help-system/base/src/cregistry/file.c
===================================================================
--- branches/new-help-system/base/src/cregistry/file.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/cregistry/file.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -97,7 +97,7 @@
  *
  * @param [in] reg      registry to open entry in
  * @param [in] id       port id in the dabatase
- * @param [in] path     file path in the database
+ * @param [in] name     file path in the database
  * @param [out] errPtr  on error, a description of the error that occures
  * @return              the file if success, NULL if failure
  */

Modified: branches/new-help-system/base/src/cregistry/registry.c
===================================================================
--- branches/new-help-system/base/src/cregistry/registry.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/cregistry/registry.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -189,19 +189,6 @@
         }
     }
     /* can_write is still true if one of the stat calls succeeded */
-    if (can_write) {
-        if (sb.st_uid == getuid()) {
-            if (!(sb.st_mode & S_IWUSR)) {
-                can_write = 0;
-            }
-        } else if (sb.st_gid == getgid()) {
-            if (!(sb.st_mode & S_IWGRP)) {
-                can_write = 0;
-            }
-        } else if (!(sb.st_mode & S_IWOTH) && getuid() != 0) {
-            can_write = 0;
-        }
-    }
     if (initialized || can_write) {
         sqlite3_stmt* stmt = NULL;
         char* query = sqlite3_mprintf("ATTACH DATABASE '%q' AS registry", path);

Modified: branches/new-help-system/base/src/cregistry/util.c
===================================================================
--- branches/new-help-system/base/src/cregistry/util.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/cregistry/util.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -123,7 +123,7 @@
  * @param [in] query_len length of the query (or -1 for automatic)
  * @param [out] objects  the objects selected
  * @param [in] fn        a function to convert sqlite3_stmts to the desired type
- * @param [inout] data   data passed along to the cast function
+ * @param [in,out] castcalldata data passed along to the cast function
  * @param [in] del       a function to delete the desired type of object
  * @param [out] errPtr   on error, a description of the error that occurred
  * @return               the number of objects if success; negative if failure

Modified: branches/new-help-system/base/src/cregistry/vercomp.c
===================================================================
--- branches/new-help-system/base/src/cregistry/vercomp.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/cregistry/vercomp.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -55,7 +55,7 @@
  * @param [in] versionA first version string, i.e. "1.4.1"
  * @param [in] lengthA  length of first version string, or -1 to use strlen
  * @param [in] versionB second version string, i.e. "1.4.2"
- * @param [in] lengthA  length of second version string, or -1 to use strlen
+ * @param [in] lengthB  length of second version string, or -1 to use strlen
  * @return              -1 if A < B; 0 if A = B; 1 if A > B
  */
 static int vercmp (const char *versionA, int lengthA, const char *versionB,
@@ -65,12 +65,12 @@
 	const char *eptrA, *eptrB;
 
     if (lengthA < 0)
-        lengthA = strlen(versionA);
+        lengthA = (int)strlen(versionA);
     if (lengthB < 0)
-        lengthB = strlen(versionB);
+        lengthB = (int)strlen(versionB);
 
 	/* if versions equal, return zero */
-	if(lengthA == lengthB && !strncmp(versionA, versionB, lengthA))
+	if(lengthA == lengthB && !strncmp(versionA, versionB, (size_t)lengthA))
 		return 0;
 
 	ptrA = versionA;

Modified: branches/new-help-system/base/src/darwintracelib1.0/Makefile
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/darwintracelib1.0/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,11 +1,17 @@
-OBJS=		darwintrace.o
+# This Makefile will only be run on Darwin systems; we can safely use
+# Apple-specifics here
+SRCS=		$(wildcard *.c)
+OBJS=		$(SRCS:%.c=%.o)
 SHLIB_NAME=	darwintrace${SHLIB_SUFFIX}
 INSTALLDIR=	${DESTDIR}${datadir}/macports/Tcl/darwintrace1.0
 
 include ../../Mk/macports.autoconf.mk
 
-CFLAGS+= -fPIC -Wno-deprecated-declarations
+# Yes, we know having $ signs in identifiers is not a very good idea; in the
+# case of darwintrace we still need them, though.
 CFLAGS_PEDANTIC=
+CFLAGS+= -fPIC ${UNIVERSAL_ARCHFLAGS}
+SHLIB_LDFLAGS+=${UNIVERSAL_ARCHFLAGS}
 
 all:: ${SHLIB_NAME}
 

Copied: branches/new-help-system/base/src/darwintracelib1.0/access.c (from rev 117083, trunk/base/src/darwintracelib1.0/access.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/access.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/access.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+int access(const char *path, int amode) {
+#define access(x, y) syscall(SYS_access, (x), (y))
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = access(path, amode);
+	}
+
+	debug_printf("access(%s) = %d\n", path, result);
+
+	return result;
+#undef access
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/close.c (from rev 117083, trunk/base/src/darwintracelib1.0/close.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/close.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/close.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#define DARWINTRACE_USE_PRIVATE_API 1
+#include "darwintrace.h"
+
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+/**
+ * Wrapper around \c close(2) to deny closing the file descriptor used by
+ * darwintrace to communicate with the control socket. Since we sometimes want
+ * to close our socket using \c fclose(3) and that internally calls \c
+ * close(2), we need a way to specifically allow closing the socket when we
+ * need to. This possibility is the \c __darwintrace_close_sock variable, which
+ * will be set to the FD to be closed when closing should be allowed.
+ */
+int close(int fd) {
+#define close(x) syscall(SYS_close, (x))
+	__darwintrace_setup();
+
+	FILE *stream = __darwintrace_sock();
+	if (stream) {
+		int dtsock = fileno(stream);
+		if (fd == dtsock && dtsock != __darwintrace_close_sock) {
+			errno = EBADF;
+			return -1;
+		}
+	}
+
+	return close(fd);
+#undef close
+}

Modified: branches/new-help-system/base/src/darwintracelib1.0/darwintrace.c
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/darwintrace.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/darwintracelib1.0/darwintrace.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -35,44 +35,17 @@
  * @APPLE_BSD_LICENSE_HEADER_END@
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#define DARWINTRACE_USE_PRIVATE_API 1
+#include "darwintrace.h"
 
-#if HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
+#ifdef HAVE_LIBKERN_OSATOMIC_H
+#include <libkern/OSAtomic.h>
 #endif
 
-#if defined(_DARWIN_FEATURE_64_BIT_INODE) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
-/* The architecture we're building for has multiple versions of stat.
-   We need to undo sys/cdefs.h changes for _DARWIN_FEATURE_64_BIT_INODE */
-#undef  __DARWIN_64_BIT_INO_T
-#define __DARWIN_64_BIT_INO_T 0
-#undef  __DARWIN_SUF_64_BIT_INO_T
-#define __DARWIN_SUF_64_BIT_INO_T ""
-#undef _DARWIN_FEATURE_64_BIT_INODE
-#endif
-
-#ifdef HAVE_CRT_EXTERNS_H
-#include <crt_externs.h>
-#endif
-
-#ifdef HAVE_SYS_PATHS_H
-#include <sys/paths.h>
-#endif
-
-#include <ctype.h>
-#include <dirent.h>
-#include <dlfcn.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <pthread.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
+#include <sys/attr.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -81,6 +54,14 @@
 #include <sys/un.h>
 #include <unistd.h>
 
+#if __DARWIN_64_BIT_INO_T
+#define STATSYSNUM SYS_stat64
+#define LSTATSYSNUM SYS_lstat64
+#else
+#define STATSYSNUM SYS_stat
+#define LSTATSYSNUM SYS_lstat
+#endif
+
 #ifndef HAVE_STRLCPY
 /* Define strlcpy if it's not available. */
 size_t strlcpy(char *dst, const char *src, size_t size) {
@@ -99,59 +80,43 @@
 
 #include "../pextlib1.0/strlcat.c"
 
-/* global variables (only checked when setup is first called)
- * DARWINTRACE_LOG
- *    path to the log file (no logging happens if it's unset).
- * DARWINTRACE_SANDBOX_BOUNDS
- *    : separated allowed paths for the creation of files.
- *    \: -> :
- *    \\ -> \
- */
-
-/*
- * DARWINTRACE_DEBUG: verbose output of operations to debug darwintrace
- */
-#ifndef DARWINTRACE_DEBUG
-#define DARWINTRACE_DEBUG (0)
-#endif
-
-static inline int __darwintrace_strbeginswith(const char *str, const char *prefix);
-static inline int __darwintrace_pathbeginswith(const char *str, const char *prefix);
-static inline void __darwintrace_log_op(const char *op, const char *path, int fd);
-static void __darwintrace_copy_env() __attribute__((constructor));
-static void __darwintrace_setup_tls() __attribute__((constructor));
-static inline char *__darwintrace_alloc_env(const char *varName, const char *varValue);
-static inline char *const *__darwintrace_restore_env(char *const envp[]);
-static inline void __darwintrace_setup();
-static inline void __darwintrace_cleanup_path(char *path);
-static char *__send(const char *buf, uint32_t len, int answer);
-
+// Global Variables
 /**
  * PID of the process darwintrace was last used in. This is used to detect
  * forking and opening a new connection to the control socket in the child
  * process. Not doing so would potentially cause two processes writing to the
  * same socket.
  */
-static pid_t __darwintrace_pid = (pid_t) - 1;
+pid_t __darwintrace_pid = (pid_t) - 1;
 
 /**
- * pthread_key_ts for the pthread_t returned by pthread_self() and the
- * darwintrace socket to ensure the socket is only used from a single thread.
- */
-static pthread_key_t tid_key;
-static pthread_key_t sock_key;
-
-/**
  * Helper variable containing the number of the darwintrace socket, iff the
  * close(2) syscall should be allowed to close it. Used by \c
  * __darwintrace_close.
  */
-static volatile int __darwintrace_close_sock = -1;
+volatile int __darwintrace_close_sock = -1;
 
 /**
+ * Debug socket. Will be initialized by a constructor function.
+ */
+FILE *__darwintrace_stderr = NULL;
+
+static inline void __darwintrace_log_op(const char *op, const char *path);
+static void __darwintrace_setup_tls() __attribute__((constructor));
+static char *__send(const char *buf, uint32_t len, int answer);
+
+/**
+ * pthread_key_ts for the pthread_t returned by pthread_self() and the
+ * darwintrace socket to ensure the socket is only used from a single thread.
+ */
+static pthread_key_t tid_key;
+// The sock key is needed in close(2) and dup2(2)
+pthread_key_t sock_key;
+
+/**
  * size of the communication buffer
  */
-#define BUFFER_SIZE 1024
+#define BUFFER_SIZE 4096
 
 /**
  * Variable holding the sandbox bounds in the following format:
@@ -160,55 +125,18 @@
  *  <operation>     :: '0' | '1' | '2'
  * where
  *  0: allow
- *  1: map the path to the one given in additional_data
+ *  1: map the path to the one given in additional_data (currently unsupported)
  *  2: check for a dependency using the socket
  */
 static char *filemap;
 
 enum {
     FILEMAP_ALLOW = 0,
-    FILEMAP_REDIR = 1,
+    // FILEMAP_REDIR = 1,
     FILEMAP_ASK   = 2
 };
 
 /**
- * Copy of the DYLD_INSERT_LIBRARIES environment variable to restore it in
- * execve(2). DYLD_INSERT_LIBRARIES is needed to preload this library into any
- * process' address space.
- */
-static char *__env_dyld_insert_libraries;
-
-/**
- * Copy of the DYLD_FORCE_FLAT_NAMESPACE environment variable to restore it in
- * execve(2). DYLD_FORCE_FLAT_NAMESPACE=1 is needed for the preload-based
- * sandbox to work.
- */
-static char *__env_dyld_force_flat_namespace;
-
-/**
- * Copy of the DARWINTRACE_LOG environment variable to restore it in execve(2).
- * Contains the path to the unix socket used for communication with the
- * MacPorts-side of the sandbox.
- */
-static char *__env_darwintrace_log;
-
-#if DARWINTRACE_DEBUG
-#   if __STDC_VERSION__>=199901L
-#       define debug_printf(format, ...) \
-	fprintf(stderr, "darwintrace[%d]: " format, getpid(), __VA_ARGS__);
-#   else
-__attribute__((format(printf, 1, 2))) static inline void debug_printf(const char *format, ...) {
-	va_list args;
-	va_start(args, format);
-	vfprintf(stderr, format, args);
-	va_end(args);
-}
-#   endif
-#else
-#   define debug_printf(...)
-#endif
-
-/**
  * Setup method called as constructor to set up thread-local storage for the
  * thread id and the darwintrace socket.
  */
@@ -224,13 +152,6 @@
 }
 
 /**
- * Convenience getter function for the thread-local darwintrace socket
- */
-static inline FILE *__darwintrace_sock() {
-	return (FILE *) pthread_getspecific(sock_key);
-}
-
-/**
  * Convenience getter function for the thread ID
  */
 static inline pthread_t __darwintrace_tid() {
@@ -240,16 +161,6 @@
 /**
  * Convenience setter function for the thread-local darwintrace socket
  */
-static inline void __darwintrace_sock_set(FILE *stream) {
-	if (0 != (errno = pthread_setspecific(sock_key, stream))) {
-		perror("darwintrace: pthread_setspecific");
-		abort();
-	}
-}
-
-/**
- * Convenience setter function for the thread-local darwintrace socket
- */
 static inline void __darwintrace_tid_set() {
 	if (0 != (errno = pthread_setspecific(tid_key, (const void *) pthread_self()))) {
 		perror("darwintrace: pthread_setspecific");
@@ -258,16 +169,16 @@
 }
 
 /**
- * Return 0 if str doesn't begin with prefix, 1 otherwise. Note that this is
- * not a simple string comparison, but works on a path component level.
+ * Return false if str doesn't begin with prefix, true otherwise. Note that
+ * this is not a simple string comparison, but works on a path component level.
  * A prefix of /var/tmp will not match a string of /var/tmpfoo.
  */
-static inline int __darwintrace_pathbeginswith(const char *str, const char *prefix) {
+static inline bool __darwintrace_pathbeginswith(const char *str, const char *prefix) {
 	char s;
 	char p;
 
 	/* '/' is the allow all wildcard */
-	if (strcmp(prefix, "/") == 0) {
+	if (prefix[0] == '\0' || (prefix[0] == '/' && prefix[1] == '\0')) {
 		return 1;
 	}
 
@@ -275,132 +186,10 @@
 		s = *str++;
 		p = *prefix++;
 	} while (p && (p == s));
-	return (p == 0 && (s == '/' || s == '\0'));
+	return (p == '\0' && (s == '/' || s == '\0'));
 }
 
-/**
- * Return 0 if str doesn't begin with prefix, 1 otherwise.
- */
-static inline int __darwintrace_strbeginswith(const char *str, const char *prefix) {
-	char s;
-	char p;
-	do {
-		s = *str++;
-		p = *prefix++;
-	} while (p && (p == s));
-	return (p == 0);
-}
-
 /*
- * Copy the environment variables, if they're defined. This is run as
- * a constructor at startup.
- */
-static void __darwintrace_copy_env() {
-#define COPYENV(name, variable) \
-	if (NULL != (val = getenv(#name))) {\
-		if (NULL == (variable = strdup(val))) {\
-			perror("darwintrace: strdup");\
-			abort();\
-		}\
-	} else {\
-		variable = NULL;\
-	}
-
-	char *val;
-	COPYENV(DYLD_INSERT_LIBRARIES,     __env_dyld_insert_libraries)
-	COPYENV(DYLD_FORCE_FLAT_NAMESPACE, __env_dyld_force_flat_namespace)
-	COPYENV(DARWINTRACE_LOG,           __env_darwintrace_log)
-#undef COPYENV
-}
-
-/**
- * Allocate a X=Y string where X is the variable name and Y its value.
- * Return the new string.
- *
- * If the value is NULL, return NULL.
- */
-static inline char *__darwintrace_alloc_env(const char *name, const char *val) {
-	char *result = NULL;
-
-	if (val) {
-		size_t size = strlen(name) + strlen(val) + 2;
-		if (NULL == (result = malloc(size))) {
-			perror("darwintrace: malloc");
-			abort();
-		}
-		snprintf(result, size, "%s=%s", name, val);
-		if (size > 0) {
-			result[size - 1] = '\0';
-		}
-	}
-
-	return result;
-}
-
-/**
- * This function checks that envp contains the global variables we had when the
- * library was loaded and modifies it if it doesn't.
- */
-static inline char *const *__darwintrace_restore_env(char *const envp[]) {
-	/* allocate the strings. */
-	/* we don't care about the leak here because we're going to call execve,
-	 * which, if it succeeds, will get rid of our heap */
-	char *dyld_insert_libraries_ptr     = __darwintrace_alloc_env("DYLD_INSERT_LIBRARIES",     __env_dyld_insert_libraries);
-	char *dyld_force_flat_namespace_ptr = __darwintrace_alloc_env("DYLD_FORCE_FLAT_NAMESPACE", __env_dyld_force_flat_namespace);
-	char *darwintrace_log_ptr           = __darwintrace_alloc_env("DARWINTRACE_LOG",           __env_darwintrace_log);
-
-	char *const *enviter = envp;
-	size_t envlen = 0;
-	char **copy;
-	char **copyiter;
-
-	while (*enviter != NULL) {
-		envlen++;
-		enviter++;
-	}
-
-	/* 4 is sufficient for the three variables we copy and the terminator */
-	copy = malloc(sizeof(char *) * (envlen + 4));
-
-	enviter  = envp;
-	copyiter = copy;
-
-	while (*enviter != NULL) {
-		char *val = *enviter;
-		if (__darwintrace_strbeginswith(val, "DYLD_INSERT_LIBRARIES=")) {
-			val = dyld_insert_libraries_ptr;
-			dyld_insert_libraries_ptr = NULL;
-		} else if (__darwintrace_strbeginswith(val, "DYLD_FORCE_FLAT_NAMESPACE=")) {
-			val = dyld_force_flat_namespace_ptr;
-			dyld_force_flat_namespace_ptr = NULL;
-		} else if (__darwintrace_strbeginswith(val, "DARWINTRACE_LOG=")) {
-			val = darwintrace_log_ptr;
-			darwintrace_log_ptr = NULL;
-		}
-
-		if (val) {
-			*copyiter++ = val;
-		}
-
-		enviter++;
-	}
-
-	if (dyld_insert_libraries_ptr) {
-		*copyiter++ = dyld_insert_libraries_ptr;
-	}
-	if (dyld_force_flat_namespace_ptr) {
-		*copyiter++ = dyld_force_flat_namespace_ptr;
-	}
-	if (darwintrace_log_ptr) {
-		*copyiter++ = darwintrace_log_ptr;
-	}
-
-	*copyiter = 0;
-
-	return copy;
-}
-
-/*
  * Data structures and functions to iterate over the filemap received from
  * tracelib code.
  */
@@ -432,16 +221,13 @@
  *
  * \param[out] command location for the command specified for this filemap
  *                     entry
- * \param[out] replacement location for a replacement path, if any. This field
- *                         is only valid if the command field indicates
- *                         a replacement path is being used.
  * \param[in]  it pointer to a \c filemap_iterator_t keeping the state of this
  *                iteration
  * \return string containing the path this filemap entry corresponds to, or \c
  *         NULL if the end of the filemap was reached
  */
-static inline char *__darwintrace_filemap_iter(char *command, char **replacement, filemap_iterator_t *it) {
-	enum { PATH, COMMAND, REPLACEPATH, DONE } state = PATH;
+static inline char *__darwintrace_filemap_iter(char *command, filemap_iterator_t *it) {
+	enum { PATH, COMMAND, DONE } state = PATH;
 	char *t;
 	char *path;
 
@@ -459,31 +245,24 @@
 	while (state != DONE) {
 		switch (state) {
 			case DONE:
-				fprintf(stderr, "darwintrace: illegal state in dfa in " __FILE__ ":%d\n", __LINE__);
-				abort();
+				/* unreachable */
 				break;
 			case PATH:
-				if (!*t) {
+				if (*t == '\0') {
 					state = COMMAND;
 				}
 				break;
 			case COMMAND:
 				*command = *t;
 				if (*t == 1) {
-					state = REPLACEPATH;
-					*replacement = t + 1;
-				} else {
-					state = DONE;
-					/* the byte after the status code is 0, if the status
-					 * code isn't 1 */
-					t++;
+					fprintf(stderr, "darwintrace: unsupported state REPLACEPATH in dfa in " __FILE__ ":%d\n", __LINE__);
+					abort();
 				}
+				state = DONE;
+				/* the byte after the status code is '\0', if the status code
+				 * isn't 1 (which is no longer supported) */
+				t++;
 				break;
-			case REPLACEPATH:
-				if (!*t) {
-					state = DONE;
-				}
-				break;
 		}
 		t++;
 	}
@@ -500,11 +279,23 @@
 	char *newfilemap;
 #if DARWINTRACE_DEBUG && 0
 	filemap_iterator_t it;
-	char *path, *replacement, command;
+	char *path, command;
 #endif
 
-#if __GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
-#error Please build with gcc-4.2 or later
+#if defined(HAVE_OSATOMICCOMPAREANDSWAPPTR)
+#	define CAS(old, new, mem) OSAtomicCompareAndSwapPtr(old, new, (void * volatile *) (mem))
+#elif defined(__LP64__)
+#	ifdef HAVE_OSATOMICCOMPAREANDSWAP64
+#		define CAS(old, new, mem) OSAtomicCompareAndSwap64((int64_t) (old), (int64_t) (new), (volatile int64_t *) (mem))
+#	else
+#		error "No 64-bit compare and swap primitive available on 64-bit OS."
+#	endif
+#else
+#	ifdef HAVE_OSATOMICCOMPAREANDSWAP32
+#		define CAS(old, new, mem) OSAtomicCompareAndSwap32((int32_t) (old), (int32_t) (new), (volatile int32_t *) (mem))
+#	else
+#		error "No 32-bit compare and swap primitive available."
+#	endif
 #endif
 
 	/*
@@ -521,12 +312,12 @@
 		if (filemap != NULL)
 			break;
 		newfilemap = __send("filemap\t", (uint32_t) strlen("filemap\t"), 1);
-	} while (!__sync_bool_compare_and_swap(&filemap, NULL, newfilemap));
+	} while (!CAS(NULL, newfilemap, &filemap));
 
 #if DARWINTRACE_DEBUG && 0
 	for (__darwintrace_filemap_iterator_init(&it);
-	        (path = __darwintrace_filemap_iter(&command, &replacement, &it));) {
-		debug_printf("filemap: {cmd=%d, path=%-120s, replacement=%s}\n", command, path, (command == 1) ? replacement : "-");
+	        (path = __darwintrace_filemap_iter(&command, &it));) {
+		debug_printf("filemap: {cmd=%d, path=%s}\n", command, path);
 	}
 #endif
 }
@@ -537,7 +328,7 @@
  * library and this library prevents closing the socket to MacPorts, we use \c
  * __darwintrace_close_sock to allow closing specific FDs.
  */
-static inline void __darwintrace_close() {
+void __darwintrace_close() {
 	FILE *dtsock = __darwintrace_sock();
 	if (dtsock) {
 		__darwintrace_close_sock = fileno(dtsock);
@@ -553,7 +344,7 @@
  * called after \c fork(2), i.e. when the current PID doesn't match the one
  * stored when the function was called last.
  */
-static inline void __darwintrace_setup() {
+void __darwintrace_setup() {
 	/*
 	 * Check whether this is a child process and we've inherited the socket. We
 	 * want to avoid race conditions with our parent process when communicating
@@ -627,90 +418,62 @@
  * \param[in] op the operation (sent as-is to tracelib, should be interpreted
  *               as command)
  * \param[in] path the (not necessarily absolute) path to send to tracelib
- * \param[in] fd a FD to the file, or 0, if none available
  */
-static inline void __darwintrace_log_op(const char *op, const char *path, int fd) {
+static inline void __darwintrace_log_op(const char *op, const char *path) {
 	uint32_t size;
-	char somepath[MAXPATHLEN];
+	char pathbuf[MAXPATHLEN];
 	char logbuffer[BUFFER_SIZE];
+	const char *realpath;
 
 	do {
-#       ifdef __APPLE__ /* Only Darwin has volfs and F_GETPATH */
-		if ((fd > 0) && (strncmp(path, "/.vol/", 6) == 0)) {
-			if (fcntl(fd, F_GETPATH, somepath) != -1) {
+#if defined(__APPLE__) && defined(ATTR_CMN_FULLPATH) && 0
+		if (false && strncmp(path, "/.vol/", 6) == 0) {
+			// path in VOLFS, try to get inode -> name lookup from
+			// getattrlist(2).
+			struct attrlist attrlist;
+			attrlist.bitmapcount = ATTR_BIT_MAP_COUNT;
+			attrlist.reserved = 0;
+			attrlist.commonattr = ATTR_CMN_FULLPATH;
+			attrlist.volattr = 0;
+			attrlist.dirattr = 0;
+			attrlist.fileattr = 0;
+			attrlist.forkattr = 0;
+
+			char attrbuf[sizeof(uint32_t) + sizeof(attrreference_t) + (PATH_MAX)];
+			/*           attrlength         attrref_t for the name     UTF-8 name up to PATH_MAX chars */
+			if (-1 == (getattrlist(path, &attrlist, attrbuf, sizeof(attrbuf), FSOPT_NOFOLLOW))) {
+				perror("darwintrace: getattrlist");
+				// ignore and just print the /.vol/ path
+			} else {
+				attrreference_t *nameAttrRef = (attrreference_t *) (attrbuf + sizeof(uint32_t));
+				strlcpy(pathbuf, ((char *) nameAttrRef) + nameAttrRef->attr_dataoffset, sizeof(pathbuf));
+				realpath = pathbuf;
 				break;
 			}
 		}
-#       endif
+#endif
 
 		if (*path != '/') {
-			if (!getcwd(somepath, sizeof(somepath))) {
+			if (!getcwd(pathbuf, sizeof(pathbuf))) {
 				perror("darwintrace: getcwd");
 				abort();
 			}
 
-			strlcat(somepath, "/", sizeof(somepath));
-			strlcat(somepath, path, sizeof(somepath));
+			strlcat(pathbuf, "/", sizeof(pathbuf));
+			strlcat(pathbuf, path, sizeof(pathbuf));
+			realpath = pathbuf;
 			break;
 		}
 
 		/* otherwise, just copy the original path. */
-		strlcpy(somepath, path, sizeof(somepath));
+		realpath = path;
 	} while (0);
 
-	/* clean the path. */
-	__darwintrace_cleanup_path(somepath);
-
-	size = snprintf(logbuffer, sizeof(logbuffer), "%s\t%s", op, somepath);
+	size = snprintf(logbuffer, sizeof(logbuffer), "%s\t%s", op, realpath);
 	__send(logbuffer, size, 0);
 }
 
 /**
- * remap resource fork access to the data fork.
- * do a partial realpath(3) to fix "foo//bar" to "foo/bar"
- */
-static inline void __darwintrace_cleanup_path(char *path) {
-	size_t pathlen;
-#   ifdef __APPLE__
-	size_t rsrclen;
-#   endif
-	char *dst, *src;
-	enum { SAWSLASH, NOTHING } state = NOTHING;
-
-	/* if this is a foo/..namedfork/rsrc, strip it off */
-	pathlen = strlen(path);
-	/* ..namedfork/rsrc is only on OS X */
-#   ifdef __APPLE__
-	rsrclen = strlen(_PATH_RSRCFORKSPEC);
-	if (pathlen > rsrclen && 0 == strcmp(path + pathlen - rsrclen, _PATH_RSRCFORKSPEC)) {
-		path[pathlen - rsrclen] = '\0';
-		pathlen -= rsrclen;
-	}
-#   endif
-
-	/* for each position in string, check if we're in a run of multiple
-	 * slashes, and only emit the first one */
-	for (src = path, dst = path; *src; src++) {
-		if (state == SAWSLASH) {
-			if (*src == '/') {
-				/* consume it */
-				continue;
-			}
-			state = NOTHING;
-		} else {
-			if (*src == '/') {
-				state = SAWSLASH;
-			}
-		}
-		if (dst != src) {
-			// if dst == src, avoid the copy operation
-			*dst = *src;
-		}
-		dst++;
-	}
-}
-
-/**
  * Check whether the port currently being installed declares a dependency on
  * a given file. Communicates with MacPorts tracelib, which uses the registry
  * database to answer this question. Returns 1, if a dependency was declared,
@@ -721,14 +484,14 @@
  * \return 1, if access should be granted, 0, if access should be denied, and
  *         -1 if MacPorts doesn't know about the file.
  */
-static int dependency_check(char *path) {
-#define stat(y, z) syscall(SYS_stat, (y), (z))
+static int dependency_check(const char *path) {
+#define lstat(y, z) syscall(LSTATSYSNUM, (y), (z))
 	char buffer[BUFFER_SIZE], *p;
 	uint32_t len;
 	int result = 0;
 	struct stat st;
 
-	if (-1 == stat(path, &st)) {
+	if (-1 == lstat(path, &st)) {
 		return 1;
 	}
 	if (S_ISDIR(st.st_mode)) {
@@ -759,14 +522,14 @@
 		default:
 			fprintf(stderr, "darwintrace: unexpected answer from tracelib: '%c' (0x%x)\n", *p, *p);
 			abort();
-			break;
+			/*NOTREACHED*/
 	}
 
 	debug_printf("dependency_check: %s returned %d\n", path, result);
 
 	free(p);
 	return result;
-#undef stat
+#undef lstat
 }
 
 /**
@@ -813,7 +576,7 @@
  * protocol and supports reading and returning an answer.
  *
  * \param[in] buf buffer to send to tracelib
- * \param[in] size size of the buffer to send
+ * \param[in] len size of the buffer to send
  * \param[in] answer boolean indicating whether an answer is expected and
  *                   should be returned
  * \return allocated answer buffer. Callers should free this buffer. If an
@@ -843,129 +606,68 @@
 }
 
 /**
- * Check a path against the current sandbox
+ * Check a fully normalized path against the current sandbox. Helper function
+ * for __darwintrace_is_in_sandbox; do not use directly.
  *
- * \param[in] path the path to be checked; not necessarily absolute
- * \param[out] newpath buffer for a replacement path when redirection should
- *                     occur. Initialize the first byte with 0 before calling
- *                     this function. The buffer should be at least MAXPATHLEN
- *                     bytes large. If newpath[0] isn't 0 after the call,
- *                     redirection should occur and the path from newpath
- *                     should be used for the syscall instead.
- * \param[in] report If access to this path is being denied, report it as
- *                   sandbox violation. Set this to \c true for all operations
- *                   that read file contents. Set this to \c false for
- *                   operations that only check for the file's existance, e.g.,
- *                   reading a directory.
- * \return 1, if the file is within sandbox bounds, 0, if access should be denied
+ * \param[in] path the path to be checked; must be absolute and normalized.
+ * \param[in] flags A binary or combination of the following flags:
+ *                  - DT_REPORT: If access to this path is being denied, report
+ *                    it as sandbox violation. Set this for all operations that
+ *                    read file contents or check file attributes. Omit this
+ *                    flag for operations that might only attempt to access
+ *                    a file by chance, such as readdir(3).
+ *                  - DT_ALLOWDIR: Whether to always allow access if the given
+ *                    path references an existing directory. Set this for
+ *                    read operations such as stat(2), omit this for operations
+ *                    that modify directories like rmdir(2) and mkdir(2).
+ * \return \c true if the file is within sandbox bounds, \c false if access
+ *         should be denied
  */
-static inline int __darwintrace_is_in_sandbox(const char *path, char *newpath, bool report) {
-	char *t, *_;
-	char *strpos, *normpos;
-	char lpath[MAXPATHLEN];
-	char normalizedpath[MAXPATHLEN];
+static inline bool __darwintrace_sandbox_check(const char *path, int flags) {
+#define lstat(x,y) syscall(LSTATSYSNUM, (x), (y))
 	filemap_iterator_t filemap_it;
+
 	char command;
-	char *replacementpath;
+	char *t;
 
-	__darwintrace_setup();
-
-	if (!filemap) {
-		return 1;
+	if (path[0] == '/' && path[1] == '\0') {
+		// Always allow access to /. Strange things start to happen if you deny this.
+		return true;
 	}
 
-	/* Make sure the path is absolute. */
-	if (*path == '/') {
-		strcpy(lpath, path);
-	} else {
-		if (getcwd(lpath, MAXPATHLEN - 1) == NULL) {
-			perror("darwintrace: getcwd");
-			abort();
+	if ((flags & DT_ALLOWDIR) > 0) {
+		struct stat st;
+		if (-1 != lstat(path, &st) && S_ISDIR(st.st_mode)) {
+			return true;
 		}
-		strlcat(lpath, "/", MAXPATHLEN);
-		strlcat(lpath, path, MAXPATHLEN);
 	}
 
-	/* Make sure the path is normalized. NOTE: Do _not_ use realpath(3) here.
-	 * Doing so _will_ lead to problems. This is essentially a very simple
-	 * re-implementation of realpath(3). */
-	normalizedpath[0] = '\0';
-	strpos = lpath + 1;
-	normpos = normalizedpath;
-	for (;;) {
-		char *curpos = strsep(&strpos, "/");
-		if (curpos == NULL) {
-			/* reached the end of the path */
-			break;
-		} else if (*curpos == '\0') {
-			/* empty entry, ignore */
-			continue;
-		} else if (strcmp(curpos, ".") == 0) {
-			/* no-op directory, ignore */
-			continue;
-		} else if (strcmp(curpos, "..") == 0) {
-			/* walk up one directory */
-			char *lastSep = strrchr(normalizedpath, '/');
-			if (lastSep == NULL) {
-				/* path is completely empty */
-				normpos = normalizedpath;
-				*normpos = '\0';
-				continue;
-			}
-			/* remove last component by overwriting the slash with \0, update normpos */
-			*lastSep = '\0';
-			normpos = lastSep;
-			continue;
-		}
-		/* default case: standard path, copy */
-		strcat(normpos, "/");
-		normpos++;
-		strcat(normpos, curpos);
-	}
-	if (*normalizedpath == '\0') {
-		strcat(normalizedpath, "/");
-	}
-
-	/* Iterate over the sandbox bounds and try to find a directive matching this path */
+	// Iterate over the sandbox bounds and try to find a directive matching this path
 	for (__darwintrace_filemap_iterator_init(&filemap_it);
-	        (t = __darwintrace_filemap_iter(&command, &replacementpath, &filemap_it));) {
-		if (__darwintrace_pathbeginswith(normalizedpath, t)) {
-			/* move t to the integer describing how to handle this match */
-			t += strlen(t) + 1;
-			switch (*t) {
+	        (t = __darwintrace_filemap_iter(&command, &filemap_it));) {
+		if (__darwintrace_pathbeginswith(path, t)) {
+			switch (command) {
 				case FILEMAP_ALLOW:
-					return 1;
-				case FILEMAP_REDIR:
-					if (!newpath) {
-						return 0;
-					}
-					/* the redirected path starts right after the byte telling
-					 * us we should redirect */
-					strcpy(newpath, t + 1);
-					_ = newpath + strlen(newpath);
-					/* append '/' if it's missing */
-					if (_[-1] != '/') {
-						*_++ = '/';
-					}
-					strcpy(_, normalizedpath);
-					return 1;
+					return true;
 				case FILEMAP_ASK:
-					/* ask the socket whether this file is OK */
-					switch (dependency_check(normalizedpath)) {
+					// ask the socket whether this file is OK
+					switch (dependency_check(path)) {
 						case 1:
-							return 1;
+							return true;
 						case -1:
-							/* if the file isn't known to MacPorts, allow
-							 * access anyway, but report a sandbox violation.
-							 * TODO find a better solution */
-							if (report)
-								__darwintrace_log_op("sandbox_violation", normalizedpath, 0);
-							return 1;
+							// if the file isn't known to MacPorts, allow
+							// access anyway, but report a sandbox violation.
+							// TODO find a better solution
+							if ((flags & DT_REPORT) > 0) {
+								__darwintrace_log_op("sandbox_violation", path);
+							}
+							return true;
 						case 0:
-							/* file belongs to a foreign port, deny access */
-							if (report)
-								__darwintrace_log_op("sandbox_violation", normalizedpath, 0);
-							return 0;
+							// file belongs to a foreign port, deny access
+							if ((flags & DT_REPORT) > 0) {
+								__darwintrace_log_op("sandbox_violation", path);
+							}
+							return false;
 					}
 				default:
 					fprintf(stderr, "darwintrace: error: unexpected byte in file map: `%x'\n", *t);
@@ -974,547 +676,251 @@
 		}
 	}
 
-	if (report)
-		__darwintrace_log_op("sandbox_violation", normalizedpath, 0);
-	return 0;
+	if ((flags & DT_REPORT) > 0) {
+		__darwintrace_log_op("sandbox_violation", path);
+	}
+	return false;
+#undef lstat
 }
 
-/* wrapper for open(2) preventing opening files outside the sandbox */
-int open(const char *path, int flags, ...) {
-#define open(x,y,z) syscall(SYS_open, (x), (y), (z))
-	mode_t mode;
-	va_list args;
-	char newpath[MAXPATHLEN];
-
-	debug_printf("open(%s)\n", path);
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		debug_printf("open %s was forbidden\n", path);
-		errno = ((flags & O_CREAT) > 0) ? EACCES : ENOENT;
-		return -1;
+/**
+ * Check a path against the current sandbox
+ *
+ * \param[in] path the path to be checked; not necessarily absolute
+ * \param[in] flags A binary or combination of the following flags:
+ *                  - DT_REPORT: If access to this path is being denied, report
+ *                    it as sandbox violation. Set this for all operations that
+ *                    read file contents or check file attributes. Omit this
+ *                    flag for operations that might only attempt to access
+ *                    a file by chance, such as readdir(3).
+ *                  - DT_ALLOWDIR: Whether to always allow access if the given
+ *                    path references an existing directory. Set this for
+ *                    read operations such as stat(2), omit this for operations
+ *                    that modify directories like rmdir(2) and mkdir(2).
+ * \return \c true if the file is within sandbox bounds, \c false if access
+ *         should be denied
+ */
+bool __darwintrace_is_in_sandbox(const char *path, int flags) {
+#define lstat(x, y) syscall(LSTATSYSNUM, (x), (y))
+#define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z))
+	if (!filemap) {
+		return true;
 	}
 
-	if (*newpath) {
-		path = newpath;
-	}
+	typedef struct {
+		char *start;
+		size_t len;
+	} path_component_t;
 
-	/* Why mode here ? */
-	va_start(args, flags);
-	mode = va_arg(args, int);
-	va_end(args);
+	char normPath[MAXPATHLEN];
+	normPath[0] = '/';
+	normPath[1] = '\0';
 
-	return open(path, flags, mode);
-#undef open
-}
+	path_component_t pathComponents[MAXPATHLEN / 2 + 2];
+	size_t numComponents = 0;
 
-/* Log calls to readlink(2) into the file specified by DARWINTRACE_LOG.
-   Only logs if the DARWINTRACE_LOG environment variable is set.
-   Only logs files where the readlink succeeds.
-*/
-#ifdef READLINK_IS_NOT_P1003_1A
-int readlink(const char *path, char *buf, int bufsiz) {
-#else
-ssize_t readlink(const char *path, char *buf, size_t bufsiz) {
-#endif
-#define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z))
-	char newpath[MAXPATHLEN];
-
-	debug_printf("readlink(%s)\n", path);
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		errno = ENOENT;
-		return -1;
+	// Make sure the path is absolute.
+	if (path == NULL || *path == '\0') {
+		// this is most certainly invalid, let the syscall deal with it
+		return true;
 	}
 
-	if (*newpath) {
-		path = newpath;
-	}
+	char *dst = NULL;
+	const char *token = NULL;
+	size_t idx;
+	if (*path != '/') {
+		// The path isn't absolute, start by populating pathcomponents with the
+		// current working directory
+		if (getcwd(normPath, sizeof(normPath)) == NULL) {
+			perror("darwintrace: getcwd");
+			abort();
+		}
 
-	return readlink(path, buf, bufsiz);
-#undef readlink
-}
+		char *writableToken = normPath + 1;
+		while ((idx = strcspn(writableToken, "/")) > 0) {
+			// found a token, tokenize and store it
+			pathComponents[numComponents].start = writableToken;
+			pathComponents[numComponents].len   = idx;
+			numComponents++;
 
-int execve(const char *path, char *const argv[], char *const envp[]) {
-#define execve(x,y,z) syscall(SYS_execve, (x), (y), (z))
-#define open(x,y,z) syscall(SYS_open, (x), (y), (z))
-#define close(x) syscall(SYS_close, (x))
-#define lstat(x, y) syscall(SYS_lstat, (x), (y))
-	debug_printf("execve(%s)\n", path);
-	__darwintrace_setup();
-	struct stat sb;
-	/* for symlinks, we want to capture both the original path and the modified
-	 * one, since for $prefix/bin/gcc -> mp-gcc-4.8, both "gcc_select" and
-	 * "gcc48" are contributors. This requires changes to the select code such
-	 * that the symlinks are registered to the *_select ports. Since this
-	 * a general problem (when executing $prefix/libexec/mysql/bin/foo where
-	 * $prefix/libexec/mysql is a symlink to $prefix/libexec/mysql55, the
-	 * mysql_select port needs to be a contributor!) we should really implement
-	 * this in __darwintrace_is_in_sandbox().
-	 */
-	if (lstat(path, &sb) == 0) {
-		if (!__darwintrace_is_in_sandbox(path, NULL, true)) {
-			errno = ENOENT;
-			return -1;
+			bool final = writableToken[idx] == '\0';
+			writableToken[idx] = '\0';
+			if (final) {
+				break;
+			}
+			// advance token
+			writableToken += idx + 1;
 		}
 
-		int fd = open(path, O_RDONLY, 0);
-		if (fd > 0) {
-			char buffer[MAXPATHLEN + 1];
-			ssize_t bytes_read;
+		// copy path after the CWD into the buffer and normalize it
+		if (numComponents > 0) {
+			path_component_t *lastComponent = pathComponents + (numComponents - 1);
+			dst = lastComponent->start + lastComponent->len + 1;
+		} else {
+			dst = normPath + 1;
+		}
 
-			/* Read the file for the interpreter. Fortunately, on OS X:
-			 *   The system guarantees to read the number of bytes requested if
-			 *   the descriptor references a normal file that has that many
-			 *   bytes left before the end-of-file, but in no other case.
-			 * That _does_ save us another ugly loop to get things right. */
-			bytes_read = read(fd, buffer, MAXPATHLEN);
-			buffer[bytes_read] = '\0';
-			const char *buffer_end = buffer + bytes_read;
-			if (bytes_read > 2 && buffer[0] == '#' && buffer[1] == '!') {
-				char *interp = buffer + 2;
+		// continue parsing at the begin of path
+		token = path;
+	} else {
+		// skip leading '/'
+		dst = normPath + 1;
+		*dst = '\0';
+		token = path + 1;
+	}
 
-				/* skip past leading whitespace */
-				while (interp < buffer_end && isblank(*interp)) {
-					++interp;
-				}
-				/* found interpreter (or ran out of data); skip until next
-				 * whitespace, then terminate the string */
-				if (interp < buffer_end) {
-					char *interp_end = interp;
-					strsep(&interp_end, " \t");
-				}
+	/* Make sure the path is normalized. NOTE: Do _not_ use realpath(3) here.
+	 * Doing so _will_ lead to problems. This is essentially a very simple
+	 * re-implementation of realpath(3). */
+	while ((idx = strcspn(token, "/")) > 0) {
+		// found a token, process it
 
-				/* check the iterpreter against the sandbox */
-				if (!__darwintrace_is_in_sandbox(interp, NULL, true)) {
-					close(fd);
-					errno = ENOENT;
-					return -1;
+		if (token[0] == '\0' || token[0] == '/') {
+			// empty entry, ignore
+		} else if (token[0] == '.' && (token[1] == '\0' || token[1] == '/')) {
+			// reference to current directory, ignore
+		} else if (token[0] == '.' && token[1] == '.' && (token[2] == '\0' || token[2] == '/')) {
+			// walk up one directory, but not if it's the last one, because /.. -> /
+			if (numComponents > 0) {
+				numComponents--;
+				if (numComponents > 0) {
+					// move dst back to the previous entry
+					path_component_t *lastComponent = pathComponents + (numComponents - 1);
+					dst = lastComponent->start + lastComponent->len + 1;
+				} else {
+					// we're at the top, move dst back to the beginning
+					dst = normPath + 1;
 				}
 			}
+		} else {
+			// copy token to normPath buffer (and null-terminate it)
+			strlcpy(dst, token, idx + 1);
+			dst[idx] = '\0';
+			// add descriptor entry for new token
+			pathComponents[numComponents].start = dst;
+			pathComponents[numComponents].len   = idx;
+			numComponents++;
 
-			close(fd);
+			// advance destination
+			dst += idx + 1;
+		}
 
+		if (token[idx] == '\0') {
+			break;
 		}
+		token += idx + 1;
 	}
 
-	/* our variables won't survive exec, clean up */
-	__darwintrace_close();
-	__darwintrace_pid = (pid_t) - 1;
+	bool pathIsSymlink;
+	size_t loopCount = 0;
+	do {
+		pathIsSymlink = false;
 
-	/* call the original execve function, but fix the environment if required. */
-	return execve(path, argv, __darwintrace_restore_env(envp));
-#undef lstat
-#undef close
-#undef open
-#undef execve
-}
-
-/* if darwintrace has been initialized, trap attempts to close our file
- * descriptor */
-int close(int fd) {
-#define close(x) syscall(SYS_close, (x))
-	FILE *stream = __darwintrace_sock();
-	if (stream) {
-		int dtsock = fileno(stream);
-		if (fd == dtsock && dtsock != __darwintrace_close_sock) {
-			errno = EBADF;
-			return -1;
+		// Add the slashes and the terminating \0
+		for (size_t i = 0; i < numComponents; ++i) {
+			if (i == numComponents - 1) {
+				pathComponents[i].start[pathComponents[i].len] = '\0';
+			} else {
+				pathComponents[i].start[pathComponents[i].len] = '/';
+			}
 		}
-	}
 
-	return close(fd);
-#undef close
-}
-
-/* if darwintrace has been initialized, trap attempts to dup2 over our file descriptor */
-int dup2(int filedes, int filedes2) {
-#define dup2(x, y) syscall(SYS_dup2, (x), (y))
-	FILE *stream = __darwintrace_sock();
-
-	debug_printf("dup2(%d, %d)\n", filedes, filedes2);
-	if (stream && filedes2 == fileno(stream)) {
-		/* if somebody tries to close our file descriptor, just move it out of
-		 * the way. Make sure it doesn't end up as stdin/stdout/stderr, though!
-		 * */
-		int new_darwintrace_fd;
-		FILE *new_stream;
-
-		if (-1 == (new_darwintrace_fd = fcntl(fileno(stream), F_DUPFD, STDOUT_FILENO + 1))) {
-			/* if duplicating fails, do not allow overwriting either! */
-			return -1;
+		if ((flags & DT_FOLLOWSYMS) == 0) {
+			// only expand symlinks when the DT_FOLLOWSYMS flags is set;
+			// otherwise just ignore whether this path is a symlink or not to
+			// speed up readdir(3).
+			break;
 		}
 
-		debug_printf("moving __darwintrace FD from %d to %d\n", fileno(stream), new_darwintrace_fd);
-		__darwintrace_close();
-		if (NULL == (new_stream = fdopen(new_darwintrace_fd, "a+"))) {
-			perror("darwintrace: fdopen");
-			abort();
+		if (++loopCount >= 10) {
+			// assume cylce and let the OS deal with that (yes, this actually
+			// happens in software!)
+			break;
 		}
-		__darwintrace_sock_set(new_stream);
-	}
 
-	return dup2(filedes, filedes2);
-#undef dup2
-}
-
-/* Trap attempts to unlink a file outside the sandbox. */
-int unlink(const char *path) {
-#define __unlink(x) syscall(SYS_unlink, (x))
-	char newpath[MAXPATHLEN];
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		debug_printf("unlink %s was forbidden\n", path);
-		errno = ENOENT;
-		return -1;
-	}
-
-	if (*newpath) {
-		path = newpath;
-	}
-
-	debug_printf("unlink %s was allowed\n", path);
-
-	return __unlink(path);
-}
-
-/* Trap attempts to create directories outside the sandbox.
- */
-int mkdir(const char *path, mode_t mode) {
-#define __mkdir(x,y) syscall(SYS_mkdir, (x), (y))
-	char newpath[MAXPATHLEN];
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
+		// Check whether the last component is a symlink; if it is, check
+		// whether it is in the sandbox, expand it and do the same thing again.
 		struct stat st;
-		if (-1 == lstat(path, &st)) {
-			if (errno == ENOENT) {
-				/* directory doesn't exist yet */
-				debug_printf("mkdir was forbidden at %s\n", path);
-				errno = EACCES;
-				return -1;
+		//debug_printf("checking for symlink: %s\n", normPath);
+		if (lstat(normPath, &st) != -1 && S_ISLNK(st.st_mode)) {
+			if (!__darwintrace_sandbox_check(normPath, flags)) {
+				return false;
 			}
-		}
-		/* otherwise, mkdir will do nothing or fail with a hopefully meaningful
-		 * error */
-	} else {
-		if (*newpath) {
-			path = newpath;
-		}
 
-		debug_printf("mkdir was allowed at %s\n", path);
-	}
+			char link[MAXPATHLEN];
+			pathIsSymlink = true;
 
-	return __mkdir(path, mode);
-}
+			ssize_t linksize;
+			if (-1 == (linksize = readlink(normPath, link, sizeof(link)))) {
+				perror("darwintrace: readlink");
+				abort();
+			}
+			link[linksize] = '\0';
+			//debug_printf("readlink(%s) = %s\n", normPath, link);
 
-/* Trap attempts to remove directories outside the sandbox.
- */
-int rmdir(const char *path) {
-#define __rmdir(x) syscall(SYS_rmdir, (x))
-	if (!__darwintrace_is_in_sandbox(path, NULL, true)) {
-		debug_printf("removing directory %s was forbidden\n", path);
-		errno = ENOENT;
-		return -1;
-	}
+			if (*link == '/') {
+				// symlink is absolute, start fresh
+				numComponents = 0;
+				token = link + 1;
+				dst = normPath + 1;
+			} else {
+				// symlink is relative, remove last component
+				token = link;
+				if (numComponents > 0) {
+					numComponents--;
+					if (numComponents > 0) {
+						// move dst back to the previous entry
+						path_component_t *lastComponent = pathComponents + (numComponents - 1);
+						dst = lastComponent->start + lastComponent->len + 1;
+					} else {
+						// we're at the top, move dst back to the beginning
+						dst = normPath + 1;
+					}
+				}
+			}
 
-	debug_printf("rmdir %s was allowed\n", path);
+			while ((idx = strcspn(token, "/")) > 0) {
+				// found a token, process it
 
-	return __rmdir(path);
-}
+				if (token[0] == '\0' || token[0] == '/') {
+					// empty entry, ignore
+				} else if (token[0] == '.' && (token[1] == '\0' || token[1] == '/')) {
+					// reference to current directory, ignore
+				} else if (token[0] == '.' && token[1] == '.' && (token[2] == '\0' || token[2] == '/')) {
+					// walk up one directory, but not if it's the last one, because /.. -> /
+					if (numComponents > 0) {
+						numComponents--;
+						if (numComponents > 0) {
+							// move dst back to the previous entry
+							path_component_t *lastComponent = pathComponents + (numComponents - 1);
+							dst = lastComponent->start + lastComponent->len + 1;
+						} else {
+							// we're at the top, move dst back to the beginning
+							dst = normPath + 1;
+						}
+					}
+				} else {
+					// copy token to normPath buffer
+					strlcpy(dst, token, idx + 1);
+					dst[idx] = '\0';
+					// add descriptor entry for new token
+					pathComponents[numComponents].start = dst;
+					pathComponents[numComponents].len   = idx;
+					numComponents++;
 
-/* Trap attempts to rename files/directories outside the sandbox.
- */
-int rename(const char *from, const char *to) {
-#define __rename(x,y) syscall(SYS_rename, (x), (y))
-	if (!__darwintrace_is_in_sandbox(from, NULL, true)) {
-		/* outside sandbox, forbid */
-		debug_printf("renaming from %s was forbidden\n", from);
-		errno = ENOENT;
-		return -1;
-	}
-	if (!__darwintrace_is_in_sandbox(to, NULL, true)) {
-		debug_printf("renaming to %s was forbidden\n", to);
-		errno = EACCES;
-		return -1;
-	}
+					// advance destination
+					dst += idx + 1;
+				}
 
-	debug_printf("renaming from %s to %s was allowed\n", from, to);
-
-	return __rename(from, to);
-}
-
-int stat(const char *path, struct stat *sb) {
-#define stat(path, sb) syscall(SYS_stat, path, sb)
-	int result = 0;
-	char newpath[MAXPATHLEN];
-
-	debug_printf("stat(%s)\n", path);
-	if (-1 == (result = stat(path, sb))) {
-		return -1;
-	}
-
-	if (S_ISDIR(sb->st_mode)) {
-		return result;
-	}
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		errno = ENOENT;
-		return -1;
-	}
-
-	if (*newpath) {
-		result = stat(newpath, sb);
-	}
-
-	return result;
-#undef stat
-}
-
-#if defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
-
-int stat64(const char *path, struct stat64 *sb) {
-#define stat64(path, sb) syscall(SYS_stat64, path, sb)
-	int result = 0;
-	char newpath[MAXPATHLEN];
-
-	debug_printf("stat64(%s)\n", path);
-	if (-1 == (result = stat64(path, sb))) {
-		return -1;
-	}
-
-	if (S_ISDIR(sb->st_mode)) {
-		return result;
-	}
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		errno = ENOENT;
-		return -1;
-	}
-
-	if (*newpath) {
-		result = stat64(newpath, sb);
-	}
-
-	return result;
-#undef stat64
-}
-
-int stat$INODE64(const char *path, struct stat64 *sb) {
-	return stat64(path, sb);
-}
-
-#endif /* defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE) */
-
-
-int lstat(const char *path, struct stat *sb) {
-#define lstat(path, sb) syscall(SYS_lstat, path, sb)
-	int result = 0;
-	char newpath[MAXPATHLEN];
-
-	debug_printf("lstat(%s)\n", path);
-	if (-1 == (result = lstat(path, sb))) {
-		return -1;
-	}
-
-	if (S_ISDIR(sb->st_mode)) {
-		return result;
-	}
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		errno = ENOENT;
-		return -1;
-	}
-
-	if (*newpath) {
-		result = lstat(newpath, sb);
-	}
-
-	return result;
-#undef lstat
-}
-
-#if defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
-
-int lstat64(const char *path, struct stat64 *sb) {
-#define lstat64(path, sb) syscall(SYS_lstat64, path, sb)
-	int result = 0;
-	char newpath[MAXPATHLEN];
-
-	debug_printf("lstat64(%s)\n", path);
-	if (-1 == (result = lstat64(path, sb))) {
-		return -1;
-	}
-
-	if (S_ISDIR(sb->st_mode)) {
-		return result;
-	}
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		errno = ENOENT;
-		return -1;
-	}
-
-	if (*newpath) {
-		result = lstat64(newpath, sb);
-	}
-
-	return result;
-#undef lstat64
-}
-
-int lstat$INODE64(const char *path, struct stat64 *sb) {
-	return lstat64(path, sb);
-}
-
-#endif /* defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE) */
-
-/**
- * re-implementation of getdirent(2) and __getdirent64(2) preventing paths
- * outside the sandbox to show up when reading the contents of a directory.
- * Unfortunately, since we need to access the contents of the buffer, but the
- * contents differ by architecture, we can not rely on the dirent structure
- * defined by the header included by this program, because we don't know
- * whether darwintrace.dylib has been compiled for 64bit or 32bit inodes. We
- * thus copy both structs and decide at runtime.
- */
-
-#ifdef __APPLE__
-/* only do this on mac, because fcntl(fd, F_GETPATH) might not be available on
- * other systems, and because other system's syscall names are probably
- * different anyway */
-
-#if defined(__DARWIN_64_BIT_INO_T)
-
-struct dirent64  {
-	__uint64_t  d_ino;      /* file number of entry */
-	__uint64_t  d_seekoff;  /* seek offset */
-	__uint16_t  d_reclen;   /* length of this record */
-	__uint16_t  d_namlen;   /* length of string in d_name */
-	__uint8_t   d_type;     /* file type */
-	char      d_name[__DARWIN_MAXPATHLEN]; /* entry name (up to MAXPATHLEN bytes) */
-};
-
-size_t __getdirentries64(int fd, void *buf, size_t bufsize, __darwin_off_t *basep) {
-#define __getdirentries64(w,x,y,z) syscall(SYS_getdirentries64, (w), (x), (y), (z))
-	size_t sz = __getdirentries64(fd, buf, bufsize, basep);
-	char dirname[MAXPATHLEN];
-	size_t dnamelen;
-
-	if (-1 == fcntl(fd, F_GETPATH, dirname)) {
-		errno = EBADF;
-		return -1;
-	}
-
-	dnamelen = strlen(dirname);
-	if (dirname[dnamelen - 1] != '/') {
-		dirname[dnamelen] = '/';
-		dirname[dnamelen + 1] = '\0';
-		dnamelen++;
-	}
-
-	dnamelen = strlen(dirname);
-	size_t offset;
-	for (offset = 0; offset < sz;) {
-		struct dirent64 *dent = (struct dirent64 *)(((char *) buf) + offset);
-		dirname[dnamelen] = '\0';
-		strcat(dirname, dent->d_name);
-		if (!__darwintrace_is_in_sandbox(dirname, NULL, false)) {
-			debug_printf("__getdirentries64: filtered %s\n", dirname);
-			dent->d_ino = 0;
-		} else {
-			debug_printf("__getdirentries64:  allowed %s\n", dirname);
+				if (token[idx] == '\0') {
+					break;
+				}
+				token += idx + 1;
+			}
 		}
-		offset += dent->d_reclen;
-	}
+	} while (pathIsSymlink);
 
-	return sz;
-#undef __getdirentries64
-}
-
-#endif /* defined(__DARWIN_64_BIT_INO_T) */
-
-#pragma pack(4)
-struct dirent32 {
-	ino_t d_ino;            /* file number of entry */
-	__uint16_t d_reclen;    /* length of this record */
-	__uint8_t  d_type;      /* file type */
-	__uint8_t  d_namlen;    /* length of string in d_name */
-	char d_name[__DARWIN_MAXNAMLEN + 1]; /* name must be no longer than this */
-};
-#pragma pack()
-
-int getdirentries(int fd, char *buf, int nbytes, long *basep) {
-#define getdirentries(w,x,y,z) syscall(SYS_getdirentries, (w), (x), (y), (z))
-	size_t sz = getdirentries(fd, buf, nbytes, basep);
-	char dirname[MAXPATHLEN];
-	size_t dnamelen;
-
-	if (-1 == fcntl(fd, F_GETPATH, dirname)) {
-		errno = EBADF;
-		return 0;
-	}
-
-	dnamelen = strlen(dirname);
-	if (dirname[dnamelen - 1] != '/') {
-		dirname[dnamelen] = '/';
-		dirname[dnamelen + 1] = '\0';
-		dnamelen++;
-	}
-
-	size_t offset;
-	for (offset = 0; offset < sz;) {
-		struct dirent32 *dent = (struct dirent32 *)(buf + offset);
-		dirname[dnamelen] = '\0';
-		strcat(dirname, dent->d_name);
-		if (!__darwintrace_is_in_sandbox(dirname, NULL, false)) {
-			debug_printf("getdirentries: filtered %s\n", dirname);
-			dent->d_ino = 0;
-		} else {
-			debug_printf("getdirentries:  allowed %s\n", dirname);
-		}
-		offset += dent->d_reclen;
-	}
-
-	return sz;
-#undef getdirentries
-}
-
-int access(const char *path, int amode) {
-#define access(x, y) syscall(SYS_access, (x), (y))
-#define lstat(path, sb) syscall(SYS_lstat, path, sb)
-	struct stat st;
-	char newpath[MAXPATHLEN];
-
-	debug_printf("access(%s, %d)\n", path, amode);
-
-	if (-1 == lstat(path, &st)) {
-		return -1;
-	}
-
-	if (S_ISDIR(st.st_mode)) {
-		return access(path, amode);
-	}
-
-	*newpath = '\0';
-	if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
-		errno = ENOENT;
-		return -1;
-	}
-
-	if (*newpath) {
-		return access(newpath, amode);
-	}
-
-	return access(path, amode);
+	return __darwintrace_sandbox_check(normPath, flags);
+#undef readlink
 #undef lstat
-#undef access
 }
-
-#endif /* __APPLE__ */

Copied: branches/new-help-system/base/src/darwintracelib1.0/darwintrace.h (from rev 117083, trunk/base/src/darwintracelib1.0/darwintrace.h)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/darwintrace.h	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/darwintrace.h	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id$
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+/**
+ * DARWINTRACE_DEBUG: verbose output of operations to debug darwintrace
+ */
+#ifndef DARWINTRACE_DEBUG
+#define DARWINTRACE_DEBUG (0)
+#endif
+
+/**
+ * \c debug_printf() is a macro that will print a message prefixed with
+ * "darwintrace" and the calling process' PID to stderr, or to the file
+ * indicated by the environment variable \c DARWINTRACE_DEBUG, if set.
+ */
+#if DARWINTRACE_DEBUG
+#	define debug_printf(format, ...) \
+		if (__darwintrace_stderr != NULL) { \
+			fprintf(__darwintrace_stderr, "darwintrace[%d:%p]: " format, getpid(), (void *) pthread_self(), __VA_ARGS__); \
+			fflush(__darwintrace_stderr); \
+		}
+#else
+#   define debug_printf(...)
+#endif
+
+enum {
+	DT_REPORT     = 1 << 0,
+	DT_ALLOWDIR   = 1 << 1,
+	DT_FOLLOWSYMS = 1 << 2
+};
+
+/**
+ * Debug socket. Will be set by a constructor function in darwintrace.c.
+ */
+extern FILE *__darwintrace_stderr;
+
+/**
+ * Initializer function, ensures darwintrace has been properly set up and check
+ * whether this process was fork(2)'d or clone(2)'d since the last call. Call
+ * this before calling any other functions from this library.
+ */
+void __darwintrace_setup();
+
+/**
+ * Close the darwintrace socket and set it to \c NULL. Since this uses \c
+ * fclose(3), which internally calls \c close(2), which is intercepted by this
+ * library and this library prevents closing the socket to MacPorts, we use \c
+ * __darwintrace_close_sock to allow closing specific FDs.
+ */
+void __darwintrace_close();
+
+/**
+ * Check a path against the current sandbox
+ *
+ * \param[in] path the path to be checked; not necessarily absolute
+ * \param[in] flags A binary or combination of the following flags:
+ *                  - DT_REPORT: If access to this path is being denied, report
+ *                    it as sandbox violation. Set this for all operations that
+ *                    read file contents or check file attributes. Omit this
+ *                    flag for operations that might only attempt to access
+ *                    a file by chance, such as readdir(3).
+ *                  - DT_ALLOWDIR: Whether to always allow access if the given
+ *                    path references an existing directory. Set this for
+ *                    read operations such as stat(2), omit this for operations
+ *                    that modify directories like rmdir(2) and mkdir(2).
+ *                  - DT_FOLLOWSYMS: Check for and expand symlinks, while
+ *                    checking both the link name and the link target against
+ *                    the sandbox. Set this for all operations that read file
+ *                    contents or check file attributes. Omit this flag for
+ *                    operations that only list the file (or rather symlink)
+ *                    name.
+ * \return \c true if the file is within sandbox bounds, \c false if access
+ *         should be denied
+ */
+bool __darwintrace_is_in_sandbox(const char *path, int flags);
+
+#ifdef DARWINTRACE_USE_PRIVATE_API
+#include <errno.h>
+#include <stdlib.h>
+
+/**
+ * PID of the process darwintrace was last used in. This is used to detect
+ * forking and opening a new connection to the control socket in the child
+ * process. Not doing so would potentially cause two processes writing to the
+ * same socket.
+ */
+extern pid_t __darwintrace_pid;
+
+/**
+ * Copy of the DARWINTRACE_LOG environment variable to restore it in execve(2).
+ * Contains the path to the unix socket used for communication with the
+ * MacPorts-side of the sandbox.
+ */
+extern char *__env_darwintrace_log;
+
+/**
+ * Helper variable containing the number of the darwintrace socket, iff the
+ * close(2) syscall should be allowed to close it. Used by \c
+ * __darwintrace_close.
+ */
+extern volatile int __darwintrace_close_sock;
+
+/**
+ * pthread_key_t for the darwintrace socket to ensure the socket is only used
+ * from a single thread.
+ */
+extern pthread_key_t sock_key;
+
+/**
+ * Convenience getter function for the thread-local darwintrace socket. Do not
+ * consider this part of public API. It is only needed to prevent closing and
+ * duplicating over darwintrace's socket FDs.
+ */
+static inline FILE *__darwintrace_sock() {
+	return (FILE *) pthread_getspecific(sock_key);
+}
+
+/**
+ * Convenience setter function for the thread-local darwintrace socket. Do not
+ * consider this part of public API. It is only needed to prevent closing and
+ * duplicating over darwintrace's socket FDs.
+ */
+static inline void __darwintrace_sock_set(FILE *stream) {
+	if (0 != (errno = pthread_setspecific(sock_key, stream))) {
+		perror("darwintrace: pthread_setspecific");
+		abort();
+	}
+}
+#endif /* defined(DARWINTRACE_USE_PRIVATE_API) */

Copied: branches/new-help-system/base/src/darwintracelib1.0/dup2.c (from rev 117083, trunk/base/src/darwintracelib1.0/dup2.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/dup2.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/dup2.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#define DARWINTRACE_USE_PRIVATE_API 1
+#include "darwintrace.h"
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+/**
+ * Wrapper around \c dup(2) that moves darwintrace's socket FD if software
+ * attempts to overwrite it using \c dup(2). Shells tend to do that a lot when
+ * FDs are numbered in ascending order.
+ */
+int dup2(int filedes, int filedes2) {
+#define dup2(x, y) syscall(SYS_dup2, (x), (y))
+	__darwintrace_setup();
+
+	FILE *stream = __darwintrace_sock();
+	if (stream && filedes2 == fileno(stream)) {
+		// if somebody tries to close our file descriptor, just move it out of
+		// the way. Make sure it doesn't end up as stdin/stdout/stderr, though!
+		int new_darwintrace_fd;
+		FILE *new_stream;
+
+		if (-1 == (new_darwintrace_fd = fcntl(fileno(stream), F_DUPFD, STDOUT_FILENO + 1))) {
+			// if duplicating fails, do not allow overwriting either!
+			return -1;
+		}
+
+		__darwintrace_close();
+		if (NULL == (new_stream = fdopen(new_darwintrace_fd, "a+"))) {
+			perror("darwintrace: fdopen");
+			abort();
+		}
+		__darwintrace_sock_set(new_stream);
+	}
+
+	return dup2(filedes, filedes2);
+#undef dup2
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/mkdir.c (from rev 117083, trunk/base/src/darwintracelib1.0/mkdir.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/mkdir.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/mkdir.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#if __DARWIN_64_BIT_INO_T
+#define LSTATSYSNUM SYS_lstat64
+#else
+#define LSTATSYSNUM SYS_lstat
+#endif
+
+/**
+ * Wrapper around \c mkdir(2) that prevents creation of directories outside of
+ * the sandbox. Will silently do nothing and return success for directories
+ * outside the sandbox that already exist.
+ */
+int mkdir(const char *path, mode_t mode) {
+#define mkdir(x,y) syscall(SYS_mkdir, (x), (y))
+#define lstat(x,y) syscall(LSTATSYSNUM, (x), (y))
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_FOLLOWSYMS)) {
+		struct stat st;
+		if (-1 == lstat(path, &st) && errno == ENOENT) {
+			// directory doesn't exist yet */
+			errno = EACCES;
+			result = -1;
+		}
+		// otherwise, leave result at 0 and return to indicate success
+	} else {
+		result = mkdir(path, mode);
+	}
+
+	debug_printf("mkdir(%s) = %d\n", path, result);
+
+	return result;
+#undef lstat
+#undef mkdir
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/open.c (from rev 117083, trunk/base/src/darwintracelib1.0/open.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/open.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/open.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.h 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+/**
+ * Wrapper function for \c open(2). Prevents opening files outside the sandbox.
+ * Indicates the file does not exist on sandbox violation, or permission denied
+ * when attempting to create a file, i.e., when \c O_CREAT is set.
+ */
+int open(const char *path, int flags, ...) {
+#define open(x,y,z) syscall(SYS_open, (x), (y), (z))
+	__darwintrace_setup();
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+		errno = ((flags & O_CREAT) > 0) ? EACCES : ENOENT;
+		result = -1;
+	} else {
+		// Read mode and pass it to the syscall, because we cannot optionally pass
+		// parameters to syscalls
+		va_list args;
+		va_start(args, flags);
+		mode_t mode = va_arg(args, int);
+		va_end(args);
+
+		result = open(path, flags, mode);
+	}
+	debug_printf("open(%s) = %d\n", path, result);
+	return result;
+#undef open
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/proc.c (from rev 117083, trunk/base/src/darwintracelib1.0/proc.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/proc.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/proc.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,357 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.h 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#define DARWINTRACE_USE_PRIVATE_API 1
+#include "darwintrace.h"
+
+#include <ctype.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+
+#if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN)
+#include <spawn.h>
+#endif
+
+static void store_env() __attribute__((constructor));
+
+/**
+ * Copy of the DYLD_INSERT_LIBRARIES environment variable to restore it in
+ * execve(2). DYLD_INSERT_LIBRARIES is needed to preload this library into any
+ * process' address space.
+ */
+static char *__env_dyld_insert_libraries;
+static char *__env_full_dyld_insert_libraries;
+
+/**
+ * Copy of the DYLD_FORCE_FLAT_NAMESPACE environment variable to restore it in
+ * execve(2). DYLD_FORCE_FLAT_NAMESPACE=1 is needed for the preload-based
+ * sandbox to work.
+ */
+static char *__env_dyld_force_flat_namespace;
+static char *__env_full_dyld_force_flat_namespace;
+
+/**
+ * Copy of the DARWINTRACE_LOG environment variable to restore it in execve(2).
+ * Contains the path to the unix socket used for communication with the
+ * MacPorts-side of the sandbox. Since this variable is also used from
+ * darwintrace.c, is can not be static.
+ */
+char *__env_darwintrace_log;
+static char *__env_full_darwintrace_log;
+
+/**
+ * Copy the environment variables, if they're defined. This is run as
+ * a constructor at startup.
+ */
+static void store_env() {
+#define COPYENV(name, variable, valuevar) do {\
+		char *val;\
+		if (NULL != (val = getenv(#name))) {\
+			size_t lenName = strlen(#name);\
+			size_t lenVal  = strlen(val);\
+			if (NULL == (variable = malloc(lenName + lenVal + 0 + 1))) {\
+				perror("darwintrace: malloc");\
+				abort();\
+			}\
+			strcpy(variable, #name);\
+			strcat(variable, "=");\
+			strcat(variable, val);\
+			valuevar = variable + lenName + 1;\
+		} else {\
+			variable = NULL;\
+			valuevar = NULL;\
+		}\
+	} while (0)
+
+	COPYENV(DYLD_INSERT_LIBRARIES, __env_full_dyld_insert_libraries, __env_dyld_insert_libraries);
+	COPYENV(DYLD_FORCE_FLAT_NAMESPACE, __env_full_dyld_force_flat_namespace, __env_dyld_force_flat_namespace);
+	COPYENV(DARWINTRACE_LOG, __env_full_darwintrace_log, __env_darwintrace_log);
+#undef COPYENV
+
+	char *debugpath = getenv("DARWINTRACE_DEBUG");
+	if (debugpath) {
+		__darwintrace_stderr = fopen(debugpath, "a+");
+	} else {
+		__darwintrace_stderr = stderr;
+	}
+}
+
+/**
+ * Return false if str doesn't begin with prefix, true otherwise.
+ */
+static inline bool __darwintrace_strbeginswith(const char *str, const char *prefix) {
+	char s;
+	char p;
+	do {
+		s = *str++;
+		p = *prefix++;
+	} while (p && (p == s));
+	return (p == '\0');
+}
+
+/**
+ * This function checks that envp contains the global variables we had when the
+ * library was loaded and modifies it if it doesn't. Returns a malloc(3)'d copy
+ * of envp where the appropriate values have been restored. The caller should
+ * pass the returned pointer to free(3) if necessary to avoid leaks.
+ */
+static inline char **restore_env(char *const envp[]) {
+	// we can re-use pre-allocated strings from store_env
+	char *dyld_insert_libraries_ptr     = __env_full_dyld_insert_libraries;
+	char *dyld_force_flat_namespace_ptr = __env_full_dyld_force_flat_namespace;
+	char *darwintrace_log_ptr           = __env_full_darwintrace_log;
+
+	char *const *enviter = envp;
+	size_t envlen = 0;
+	char **copy;
+	char **copyiter;
+
+	while (*enviter != NULL) {
+		envlen++;
+		enviter++;
+	}
+
+	// 4 is sufficient for the three variables we copy and the terminator
+	copy = malloc(sizeof(char *) * (envlen + 4));
+
+	enviter  = envp;
+	copyiter = copy;
+
+	while (*enviter != NULL) {
+		char *val = *enviter;
+		if (__darwintrace_strbeginswith(val, "DYLD_INSERT_LIBRARIES=")) {
+			val = dyld_insert_libraries_ptr;
+			dyld_insert_libraries_ptr = NULL;
+		} else if (__darwintrace_strbeginswith(val, "DYLD_FORCE_FLAT_NAMESPACE=")) {
+			val = dyld_force_flat_namespace_ptr;
+			dyld_force_flat_namespace_ptr = NULL;
+		} else if (__darwintrace_strbeginswith(val, "DARWINTRACE_LOG=")) {
+			val = darwintrace_log_ptr;
+			darwintrace_log_ptr = NULL;
+		}
+
+		if (val) {
+			*copyiter++ = val;
+		}
+
+		enviter++;
+	}
+
+	if (dyld_insert_libraries_ptr) {
+		*copyiter++ = dyld_insert_libraries_ptr;
+	}
+	if (dyld_force_flat_namespace_ptr) {
+		*copyiter++ = dyld_force_flat_namespace_ptr;
+	}
+	if (darwintrace_log_ptr) {
+		*copyiter++ = darwintrace_log_ptr;
+	}
+
+	*copyiter = 0;
+
+	return copy;
+}
+
+/**
+ * Helper function that opens the file indicated by \a path, checks whether it
+ * is a script (i.e., contains a shebang line) and verifies the interpreter is
+ * within the sandbox bounds.
+ *
+ * \param[in] path The path of the file to be executed
+ * \return 0, if access should be granted, a non-zero error code to be stored
+ *         in \c errno otherwise
+ */
+static inline int check_interpreter(const char *restrict path) {
+#define open(x,y,z) syscall(SYS_open, (x), (y), (z))
+#define close(x) syscall(SYS_close, (x))
+	int fd = open(path, O_RDONLY, 0);
+	if (fd <= 0) {
+		return errno;
+	}
+
+	char buffer[MAXPATHLEN + 1 + 2];
+	ssize_t bytes_read;
+
+	/* Read the file for the interpreter. Fortunately, on OS X:
+	 *   The system guarantees to read the number of bytes requested if
+	 *   the descriptor references a normal file that has that many
+	 *   bytes left before the end-of-file, but in no other case.
+	 * That _does_ save us another ugly loop to get things right. */
+	bytes_read = read(fd, buffer, sizeof(buffer) - 1);
+	buffer[bytes_read] = '\0';
+	const char *buffer_end = buffer + bytes_read;
+	if (bytes_read > 2 && buffer[0] == '#' && buffer[1] == '!') {
+		char *interp = buffer + 2;
+
+		/* skip past leading whitespace */
+		while (interp < buffer_end && isblank(*interp)) {
+			++interp;
+		}
+		/* found interpreter (or ran out of data); skip until next
+		 * whitespace, then terminate the string */
+		if (interp < buffer_end) {
+			char *interp_end = interp;
+			strsep(&interp_end, " \t");
+		}
+
+		/* check the iterpreter against the sandbox */
+		if (!__darwintrace_is_in_sandbox(interp, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+			close(fd);
+			return ENOENT;
+		}
+	}
+
+	close(fd);
+	return 0;
+#undef open
+#undef close
+}
+
+/**
+ * Wrapper for \c execve(2). Denies access and simulates the file does not
+ * exist, if it's outside the sandbox. Also checks for potential interpreters
+ * using \c check_interpreter.
+ */
+int execve(const char *path, char *const argv[], char *const envp[]) {
+#define execve(x,y,z) syscall(SYS_execve, (x), (y), (z))
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		int interp_result = check_interpreter(path);
+		if (interp_result != 0) {
+			errno = interp_result;
+			result = -1;
+		} else {
+			// Since \c execve(2) will likely not return, log before calling
+			debug_printf("execve(%s) = ?\n", path);
+
+			// Our variables won't survive exec, clean up
+			__darwintrace_close();
+			__darwintrace_pid = (pid_t) -1;
+
+			// Call the original execve function, but restore environment
+			char **newenv = restore_env(envp);
+			result = execve(path, argv, newenv);
+			free(newenv);
+		}
+	}
+
+	debug_printf("execve(%s) = %d\n", path, result);
+
+	return result;
+#undef execve
+}
+
+#if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN)
+// Let's save some typing work...
+typedef int (*posix_spawn_t)(
+			pid_t *restrict,
+			const char *restrict,
+			const posix_spawn_file_actions_t *,
+			const posix_spawnattr_t *restrict,
+			char *const *restrict,
+			char *const *restrict);
+/**
+ * Wrapper for \c posix_spawn(2). Denies access and simulates the file does not
+ * exist, if it's outside the sandbox. Also checks for potential interpreters
+ * using \c check_interpreter.
+ */
+int posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions,
+		const posix_spawnattr_t *restrict attrp, char *const argv[restrict], char *const envp[restrict]) {
+	__darwintrace_setup();
+
+	static posix_spawn_t prev_posix_spawn = NULL;
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+		result = ENOENT;
+	} else {
+		int interp_result = check_interpreter(path);
+		if (interp_result != 0) {
+			result = interp_result;
+		} else {
+			short attrflags;
+			if (   attrp != NULL
+				&& posix_spawnattr_getflags(attrp, &attrflags) == 0
+				&& (attrflags & POSIX_SPAWN_SETEXEC) > 0) {
+				// Apple-specific extension: This call will not return, but
+				// behave like execve(2). Since our variables won't survive
+				// that, clean up. Also log the call, because we likely won't
+				// be able to after the call.
+				debug_printf("execve(%s) = ?\n", path);
+
+				__darwintrace_close();
+				__darwintrace_pid = (pid_t) - 1;
+			}
+
+			/* ATTN: the mac syscall you get from syscall(SYS_posix_spawn) corresponds
+			 * to __posix_spawn from /usr/lib/system/libsystem_kernel.dylib. We can not
+			 * override __posix_spawn directly, because it is called from posix_spawn
+			 * inside the same library (i.e., there is no dyld stub we can override).
+			 *
+			 * We cannot override posix_spawn and call __posix_spawn from it
+			 * either, because that will fail with an invalid argument. Thus,
+			 * we need to call the original posix_spawn from here. */
+			// retrieve the original posix_spawn function
+			if (prev_posix_spawn == NULL) {
+				prev_posix_spawn = (posix_spawn_t) dlsym(RTLD_NEXT, "posix_spawn");
+			}
+			// call the original posix_spawn function, but restore environment
+			char **newenv = restore_env(envp);
+			result = prev_posix_spawn(pid, path, file_actions, attrp, argv, newenv);
+			free(newenv);
+		}
+	}
+
+	debug_printf("posix_spawn(%s) = %d\n", path, result);
+
+	return result;
+}
+#endif

Copied: branches/new-help-system/base/src/darwintracelib1.0/readdir.c (from rev 117083, trunk/base/src/darwintracelib1.0/readdir.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/readdir.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/readdir.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <sys/dirent.h>
+#include <sys/param.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+/**
+ * re-implementation of getdirent(2) and __getdirent64(2) preventing paths
+ * outside the sandbox to show up when reading the contents of a directory.
+ * Unfortunately, since we need to access the contents of the buffer, but the
+ * contents differ by architecture, we can not rely on the dirent structure
+ * defined by the header included by this program, because we don't know
+ * whether darwintrace.dylib has been compiled for 64bit or 32bit inodes. We
+ * thus copy both structs and decide at runtime.
+ */
+
+#if defined(__DARWIN_64_BIT_INO_T)
+
+struct dirent64  {
+	__uint64_t  d_ino;      /* file number of entry */
+	__uint64_t  d_seekoff;  /* seek offset */
+	__uint16_t  d_reclen;   /* length of this record */
+	__uint16_t  d_namlen;   /* length of string in d_name */
+	__uint8_t   d_type;     /* file type */
+	char      d_name[__DARWIN_MAXPATHLEN]; /* entry name (up to MAXPATHLEN bytes) */
+};
+
+size_t __getdirentries64(int fd, void *buf, size_t bufsize, __darwin_off_t *basep) {
+#define __getdirentries64(w,x,y,z) syscall(SYS_getdirentries64, (w), (x), (y), (z))
+	__darwintrace_setup();
+
+	size_t sz = __getdirentries64(fd, buf, bufsize, basep);
+	char dirname[MAXPATHLEN];
+	size_t dnamelen;
+
+	if (-1 == fcntl(fd, F_GETPATH, dirname)) {
+		errno = EBADF;
+		return -1;
+	}
+
+	dnamelen = strlen(dirname);
+	if (dirname[dnamelen - 1] != '/') {
+		dirname[dnamelen] = '/';
+		dirname[dnamelen + 1] = '\0';
+		dnamelen++;
+	}
+
+	dnamelen = strlen(dirname);
+	size_t offset;
+	for (offset = 0; offset < sz;) {
+		struct dirent64 *dent = (struct dirent64 *)(((char *) buf) + offset);
+		dirname[dnamelen] = '\0';
+		strcat(dirname, dent->d_name);
+		if (!__darwintrace_is_in_sandbox(dirname, DT_ALLOWDIR)) {
+			debug_printf("__getdirentries64: filtered %s\n", dirname);
+			dent->d_ino = 0;
+		} else {
+			debug_printf("__getdirentries64:  allowed %s\n", dirname);
+		}
+		offset += dent->d_reclen;
+	}
+
+	return sz;
+#undef __getdirentries64
+}
+
+#endif /* defined(__DARWIN_64_BIT_INO_T) */
+
+#pragma pack(4)
+struct dirent32 {
+	ino_t d_ino;            /* file number of entry */
+	__uint16_t d_reclen;    /* length of this record */
+	__uint8_t  d_type;      /* file type */
+	__uint8_t  d_namlen;    /* length of string in d_name */
+	char d_name[__DARWIN_MAXNAMLEN + 1]; /* name must be no longer than this */
+};
+#pragma pack()
+
+int getdirentries(int fd, char *buf, int nbytes, long *basep) {
+#define getdirentries(w,x,y,z) syscall(SYS_getdirentries, (w), (x), (y), (z))
+	__darwintrace_setup();
+
+	size_t sz = getdirentries(fd, buf, nbytes, basep);
+	char dirname[MAXPATHLEN];
+	size_t dnamelen;
+
+	if (-1 == fcntl(fd, F_GETPATH, dirname)) {
+		errno = EBADF;
+		return 0;
+	}
+
+	dnamelen = strlen(dirname);
+	if (dirname[dnamelen - 1] != '/') {
+		dirname[dnamelen] = '/';
+		dirname[dnamelen + 1] = '\0';
+		dnamelen++;
+	}
+
+	size_t offset;
+	for (offset = 0; offset < sz;) {
+		struct dirent32 *dent = (struct dirent32 *)(buf + offset);
+		dirname[dnamelen] = '\0';
+		strcat(dirname, dent->d_name);
+		if (!__darwintrace_is_in_sandbox(dirname, DT_ALLOWDIR)) {
+			debug_printf("getdirentries: filtered %s\n", dirname);
+			dent->d_ino = 0;
+		} else {
+			debug_printf("getdirentries:  allowed %s\n", dirname);
+		}
+		offset += dent->d_reclen;
+	}
+
+	return sz;
+#undef getdirentries
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/readlink.c (from rev 117083, trunk/base/src/darwintracelib1.0/readlink.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/readlink.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/readlink.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.h 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <unistd.h>
+
+/**
+ * Deny \c readlink(2) if the file is not within the sandbox bounds.
+ */
+#ifdef READLINK_IS_NOT_P1003_1A
+int readlink(const char *path, char *buf, int bufsiz) {
+#else
+ssize_t readlink(const char *path, char *buf, size_t bufsiz) {
+#endif
+#define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z))
+	__darwintrace_setup();
+
+	int result = 0;
+
+	// don't follow symlinks here; whether access to the link target is allowed
+	// or not does not matter for reading the symlink
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = readlink(path, buf, bufsiz);
+	}
+
+	debug_printf("readlink(%s) = %d\n", path, result);
+
+	return result;
+#undef readlink
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/rename.c (from rev 117083, trunk/base/src/darwintracelib1.0/rename.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/rename.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/rename.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+/**
+ * Wrapper around \c rename(2) to prevent moving a file outside, or out of the
+ * sandbox.
+ */
+int rename(const char *from, const char *to) {
+#define rename(x,y) syscall(SYS_rename, (x), (y))
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(from, DT_REPORT | DT_FOLLOWSYMS)) {
+		errno = ENOENT;
+		result = -1;
+	} else if (!__darwintrace_is_in_sandbox(to, DT_REPORT | DT_FOLLOWSYMS)) {
+		errno = EACCES;
+		result = -1;
+	} else {
+		result = rename(from, to);
+	}
+
+	debug_printf("rename(%s, %s) = %d\n", from, to, result);
+
+	return result;
+#undef rename
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/rmdir.c (from rev 117083, trunk/base/src/darwintracelib1.0/rmdir.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/rmdir.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/rmdir.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <unistd.h>
+
+/**
+ * Wrapper around \c rmdir(2) to deny deleting directories outside of the
+ * sandbox.
+ */
+int rmdir(const char *path) {
+#define rmdir(x) syscall(SYS_rmdir, (x))
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_FOLLOWSYMS)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = rmdir(path);
+	}
+
+	debug_printf("rmdir(%s) = %d\n", path, result);
+
+	return result;
+#undef rmdir
+}

Copied: branches/new-help-system/base/src/darwintracelib1.0/stat.c (from rev 117083, trunk/base/src/darwintracelib1.0/stat.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/stat.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/stat.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+// Do *not* include sys/stat.h, it will rewrite the stat to a stat$INODE64 symbol
+
+/**
+ * Wrapper around \c stat(2) to hide information about files outside the
+ * sandbox.
+ */
+int stat(const char *path, void *sb) {
+#define stat(path, sb) syscall(SYS_stat, path, sb)
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = stat(path, sb);
+	}
+
+	debug_printf("stat(%s) = %d\n", path, result);
+
+	return result;
+#undef stat
+}
+
+// Don't provide stat64 on systems that have no stat64 syscall
+#ifdef SYS_stat64
+int stat64(const char *path, void *sb) {
+#define stat64(path, sb) syscall(SYS_stat64, path, sb)
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = stat64(path, sb);
+	}
+
+	debug_printf("stat64(%s) = %d\n", path, result);
+
+	return result;
+#undef stat64
+}
+
+int stat$INODE64(const char *path, void *sb) {
+	return stat64(path, sb);
+}
+#endif /* defined(SYS_stat64) */
+
+int lstat(const char *path, void *sb) {
+#define lstat(path, sb) syscall(SYS_lstat, path, sb)
+	__darwintrace_setup();
+
+	int result = 0;
+
+	// don't follow symlinks for lstat
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = lstat(path, sb);
+	}
+
+	debug_printf("lstat(%s) = %d\n", path, result);
+
+	return result;
+#undef lstat
+}
+
+// Don't provide lstat64 on systems that have no lstat64 syscall
+#ifdef SYS_lstat64
+int lstat64(const char *path, void *sb) {
+#define lstat64(path, sb) syscall(SYS_lstat64, path, sb)
+	__darwintrace_setup();
+
+	int result = 0;
+
+	// don't follow symlinks for lstat
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = lstat64(path, sb);
+	}
+
+	debug_printf("lstat64(%s) = %d\n", path, result);
+
+	return result;
+#undef lstat64
+}
+
+int lstat$INODE64(const char *path, void *sb) {
+	return lstat64(path, sb);
+}
+#endif /* defined(SYS_lstat64) */

Copied: branches/new-help-system/base/src/darwintracelib1.0/unlink.c (from rev 117083, trunk/base/src/darwintracelib1.0/unlink.c)
===================================================================
--- branches/new-help-system/base/src/darwintracelib1.0/unlink.c	                        (rev 0)
+++ branches/new-help-system/base/src/darwintracelib1.0/unlink.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
+ * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+ * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
+ *
+ * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal at macports.org $
+ *
+ * @APPLE_BSD_LICENSE_HEADER_START@
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @APPLE_BSD_LICENSE_HEADER_END@
+ */
+
+#include "darwintrace.h"
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <unistd.h>
+
+/**
+ * Wrapper around \c unlink(2) that will deny attempts to delete files outside
+ * of the sandbox and simulate non-existence of the file instead.
+ */
+int unlink(const char *path) {
+#define unlink(x) syscall(SYS_unlink, (x))
+	__darwintrace_setup();
+
+	int result = 0;
+
+	if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_ALLOWDIR | DT_FOLLOWSYMS)) {
+		errno = ENOENT;
+		result = -1;
+	} else {
+		result = unlink(path);
+	}
+
+	debug_printf("unlink(%s) = %d\n", path, result);
+
+	return result;
+#undef unlink
+}

Modified: branches/new-help-system/base/src/images_to_archives.tcl
===================================================================
--- branches/new-help-system/base/src/images_to_archives.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/images_to_archives.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -45,19 +45,19 @@
     set iepoch [lindex $installed 5]
     set iref [registry::open_entry $iname $iversion $irevision $ivariants $iepoch]
     set installtype [registry::property_retrieve $iref installtype]
-    if {$installtype == "image"} {
+    if {$installtype eq "image"} {
         set location [registry::property_retrieve $iref location]
-        if {$location == "0"} {
+        if {$location == 0} {
             set location [registry::property_retrieve $iref imagedir]
         }
     } else {
         set location ""
     }
 
-    if {$location == "" || ![file isfile $location]} {
+    if {$location eq "" || ![file isfile $location]} {
         # no image archive present, so make one
         set archs [registry::property_retrieve $iref archs]
-        if {$archs == "" || $archs == "0"} {
+        if {$archs eq "" || $archs == 0} {
             set archs ${macports::os_arch}
         }
         # look for any existing archive in the old location
@@ -88,12 +88,12 @@
         # compute new name and location of archive
         set archivename "${iname}-${iversion}_${irevision}${ivariants}.${macports::os_platform}_${macports::os_major}.[join $archs -].${archivetype}"
         ui_msg "Processing ${counter} of ${installed_len}: ${archivename}"
-        if {$installtype == "image"} {
+        if {$installtype eq "image"} {
             set targetdir [file dirname $location]
         } else {
             set targetdir [file join ${macports::registry.path} software ${iname}]
         }
-        if {$location == "" || ![file isdirectory $location]} {
+        if {$location eq "" || ![file isdirectory $location]} {
             set contents [$iref imagefiles]
         }
         file mkdir $targetdir
@@ -101,7 +101,7 @@
 
         if {$found} {
             file rename $oldarchivefullpath $newlocation
-        } elseif {$installtype == "image" && [file isdirectory $location]} {
+        } elseif {$installtype eq "image" && [file isdirectory $location]} {
             # create archive from image dir
             system -W $location "$tarcmd -cjf $newlocation * > ${targetdir}/error.log 2>&1"
             file delete -force ${targetdir}/error.log
@@ -132,7 +132,7 @@
         set iref [lindex $archived 1]
         set newlocation [lindex $archived 3]
     
-        if {$installtype == "direct"} {
+        if {$installtype eq "direct"} {
             # change receipt to image
             $iref installtype image
             $iref state imaged
@@ -150,7 +150,7 @@
     incr counter
     set location [lindex $archived 2]
     ui_msg "Deleting ${counter} of ${archived_len}: ${location}"
-    if {$location != "" && [file isdirectory $location]} {
+    if {$location ne "" && [file isdirectory $location]} {
         if {[catch {file delete -force $location} result]} {
             ui_warn "Failed to delete ${location}: $result"
         }

Modified: branches/new-help-system/base/src/machista1.0/libmachista.c
===================================================================
--- branches/new-help-system/base/src/machista1.0/libmachista.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/machista1.0/libmachista.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -30,6 +30,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <config.h>
+
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -41,6 +43,7 @@
 
 #include <err.h>
 #include <string.h>
+#include <strings.h>
 
 #ifdef __MACH__
 #include <mach-o/fat.h>
@@ -338,15 +341,21 @@
     mat->mat_arch = swap32(header->cputype);
 
     /* Parse the Mach-O load commands */
-    const struct load_command *cmd = macho_offset(input, header, header_size, sizeof(struct load_command));
-    if (cmd == NULL)
-        return MACHO_ERANGE;
     uint32_t ncmds = swap32(header->ncmds);
 
+    /* Setup to jump over the header on the first pass through instead of the previous command */
+    const struct load_command *cmd = (void *)header;
+    uint32_t cmdsize = header_size;
+
     /* Iterate over the load commands */
     for (uint32_t i = 0; i < ncmds; i++) {
+        /* Load the next command */
+        cmd = macho_offset(input, cmd, cmdsize, sizeof(struct load_command));
+        if (cmd == NULL)
+            return MACHO_ERANGE;
+
         /* Load the full command */
-        uint32_t cmdsize = swap32(cmd->cmdsize);
+        cmdsize = swap32(cmd->cmdsize);
         cmd = macho_read(input, cmd, cmdsize);
         if (cmd == NULL)
             return MACHO_ERANGE;
@@ -425,11 +434,6 @@
             default:
                 break;
         }
-
-        /* Load the next command */
-        cmd = macho_offset(input, cmd, cmdsize, sizeof(struct load_command));
-        if (cmd == NULL)
-            return MACHO_ERANGE;
     }
 
     return MACHO_SUCCESS;
@@ -530,11 +534,18 @@
 
 /* Returns string representation of the MACHO_* error code constants */
 const char *macho_strerror(int err) {
-    int num = 0;
+    int num;
+#ifdef HAVE_FLS
+    num = fls(err);
+#else
+    /* Tiger compatibility, see #42186 */
+    num = 0;
     while (err > 0) {
         err >>= 1;
         num++;
     }
+#endif
+
     static char *errors[] = {
         /* 0x00 */ "Success",
         /* 0x01 */ "Error opening or reading file",

Modified: branches/new-help-system/base/src/machista1.0/tests/test.tcl
===================================================================
--- branches/new-help-system/base/src/machista1.0/tests/test.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/machista1.0/tests/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -12,14 +12,14 @@
 	if {[lindex $rlist 0] == $machista::SUCCESS} {
 		set r [lindex $rlist 1]
 		set a [$r cget -mt_archs]
-		while {$a != "NULL"} {
+		while {$a ne "NULL"} {
 			puts "	Architecture: [$a cget -mat_arch]"
 			puts "		         install name: [$a cget -mat_install_name]"
 			puts "		      current version: [machista::format_dylib_version [$a cget -mat_version]]"
 			puts "		compatibility version: [machista::format_dylib_version [$a cget -mat_comp_version]]"
 	
 			set l [$a cget -mat_loadcmds]
-			while {$l != "NULL"} {
+			while {$l ne "NULL"} {
 				puts "			[$l cget -mlt_install_name] (current version [machista::format_dylib_version [$l cget -mlt_version]], compatibility version [machista::format_dylib_version [$l cget -mlt_comp_version]])"
 				set l [$l cget -next]
 			}


Property changes on: branches/new-help-system/base/src/macports1.0
___________________________________________________________________
Modified: svn:ignore
   - *.dylib
macports_autoconf.tcl
macports_fastload.tcl
pkgIndex.tcl

   + *.dylib
macports_autoconf.tcl
macports_test_autoconf.tcl
macports_fastload.tcl
pkgIndex.tcl


Modified: branches/new-help-system/base/src/macports1.0/Makefile
===================================================================
--- branches/new-help-system/base/src/macports1.0/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -16,11 +16,10 @@
 pkgIndex.tcl: $(SRCS)
 
 test::
-	${TCLSH} tests/macports_dlist.tcl
-	${TCLSH} tests/macports_util.tcl
+	$(TCLSH) ./tests/test.tcl -nocolor
 
 distclean:: clean
-	rm -f macports_autoconf.tcl macports_fastload.tcl ${SHLIB_NAME}
+	rm -f macports_autoconf.tcl macports_fastload.tcl macports_test_autoconf.tcl ${SHLIB_NAME}
 
 install:: all
 	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} ${INSTALLDIR}

Modified: branches/new-help-system/base/src/macports1.0/get_systemconfiguration_proxies.c
===================================================================
--- branches/new-help-system/base/src/macports1.0/get_systemconfiguration_proxies.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/get_systemconfiguration_proxies.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -132,7 +132,7 @@
                  * We are adding :<port>\0 to the end, which is up to 7
                  * bytes additional (up to 5 for the port)
                  */
-                int newLength = strlen( hostname ) + 7;
+                size_t newLength = strlen( hostname ) + 7;
                 char *hostnameAndPort = calloc( 1, newLength );
                 if( hostnameAndPort != NULL )
                 {
@@ -165,8 +165,8 @@
  */
 char *cfStringToCStringASCII( CFStringRef cfString )
 {
-    int strLen = CFStringGetMaximumSizeForEncoding( CFStringGetLength( cfString ), kCFStringEncodingASCII ) + 1;
-    char *cString = calloc( 1, strLen );
+    CFIndex strLen = CFStringGetMaximumSizeForEncoding( CFStringGetLength( cfString ), kCFStringEncodingASCII ) + 1;
+    char *cString = calloc( 1, (size_t)strLen );
     if( cString != NULL )
         CFStringGetCString( cfString, cString, strLen, kCFStringEncodingASCII );
 

Modified: branches/new-help-system/base/src/macports1.0/macports.tcl
===================================================================
--- branches/new-help-system/base/src/macports1.0/macports.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/macports.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -45,7 +45,7 @@
         porttrace portverbose keeplogs destroot_umask variants_conf rsync_server rsync_options \
         rsync_dir startupitem_type startupitem_install place_worksymlink xcodeversion xcodebuildcmd \
         configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
-        applications_dir frameworks_dir developer_dir universal_archs build_arch macosx_deployment_target \
+        applications_dir frameworks_dir developer_dir universal_archs build_arch macosx_sdk_version macosx_deployment_target \
         macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip \
         master_site_local patch_site_local archive_site_local buildfromsource \
         revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds \
@@ -59,7 +59,7 @@
         rsync_server rsync_options rsync_dir startupitem_type startupitem_install place_worksymlink macportsuser \
         configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
         applications_dir current_phase frameworks_dir developer_dir universal_archs build_arch \
-        os_arch os_endian os_version os_major os_platform macosx_version macosx_deployment_target \
+        os_arch os_endian os_version os_major os_platform macosx_version macosx_sdk_version macosx_deployment_target \
         packagemaker_path default_compilers sandbox_enable delete_la_files cxx_stdlib \
         pkg_post_unarchive_deletions $user_options"
 
@@ -575,6 +575,7 @@
         macports::os_major \
         macports::os_platform \
         macports::macosx_version \
+        macports::macosx_sdk_version \
         macports::macosx_deployment_target \
         macports::archivefetch_pubkeys \
         macports::ping_cache \
@@ -596,11 +597,21 @@
     # Remove trailing "Endian"
     set os_endian [string range $tcl_platform(byteOrder) 0 end-6]
     set macosx_version {}
-    if {$os_platform eq {darwin}} {
-        # This will probably break when Apple changes versioning
-        set macosx_version [expr {10.0 + ($os_major - 4) / 10.0}]
+    if {$os_platform eq "darwin" && [file executable /usr/bin/sw_vers]} {
+        if {![catch {exec /usr/bin/sw_vers -productVersion | cut -f1,2 -d.} result]} {
+            set macosx_version $result
+        } else {
+            ui_debug "sw_vers exists but running it failed: $result"
+        }
     }
 
+    # Check that the current platform is the one we were configured for, otherwise need to do migration
+    if {($os_platform != $macports::autoconf::os_platform) || ($os_major != $macports::autoconf::os_major)} {
+        ui_error "Current platform \"$os_platform $os_major\" does not match expected platform \"$macports::autoconf::os_platform $macports::autoconf::os_major\""
+        ui_error "If you upgraded your OS, please follow the migration instructions: https://trac.macports.org/wiki/Migration"
+        return -code error "OS platform mismatch"
+    }
+
     # Ensure that the macports user directory (i.e. ~/.macports) exists if HOME is defined.
     # Also save $HOME for later use before replacing it with our own.
     if {[info exists env(HOME)]} {
@@ -950,6 +961,9 @@
     if {![info exists macports::macosx_deployment_target]} {
         set macports::macosx_deployment_target $macosx_version
     }
+    if {![info exists macports::macosx_sdk_version]} {
+        set macports::macosx_sdk_version $macosx_version
+    }
 
     if {![info exists macports::revupgrade_autorun]} {
         set macports::revupgrade_autorun yes
@@ -965,7 +979,9 @@
         }
     }
     if {![info exists macports::cxx_stdlib]} {
-        if {$os_platform eq "darwin" && $os_major < 13} {
+        if {$os_platform eq "darwin" && $os_major >= 13} {
+            set macports::cxx_stdlib libc++
+        } elseif {$os_platform eq "darwin"} {
             set macports::cxx_stdlib libstdc++
         } else {
             set macports::cxx_stdlib {}
@@ -1014,6 +1030,15 @@
         return -code error "Library directory '$libpath' must exist"
     }
 
+    # set the hidden flag on $portdbpath to avoid spotlight indexing, which
+    # might slow builds down considerably. You can avoid this by touching
+    # $portdbpath/.nohide.
+    if {$os_platform eq "darwin" && [vercmp [info tclversion] 8.5] >= 0 && ![file exists [file join $portdbpath .nohide]] && [file writable $portdbpath] && [file attributes $portdbpath -hidden] == 0} {
+        if {[catch {file attributes $portdbpath -hidden yes} result]} {
+            ui_debug "error setting hidden flag for $portdbpath: $result"
+        }
+    }
+
     # don't keep unusable TMPDIR/TMP values
     foreach var {TMP TMPDIR} {
         if {[info exists env($var)] && [file writable $env($var)] &&
@@ -1255,8 +1280,11 @@
         foreach phase $macports::port_phases {
             $workername alias ui_${priority}_$phase ui_${priority}_$phase
         }
-
     }
+    # add the UI progress call-back
+    if {[info exists macports::ui_options(progress_download)]} {
+        $workername alias ui_progress_download $macports::ui_options(progress_download)
+    }
 
     $workername alias ui_prefix ui_prefix
     $workername alias ui_channels ui_channels
@@ -1414,7 +1442,7 @@
 # @param local one, if the URL is local, zero otherwise
 # @return a path to a directory containing the Portfile, or an error code
 proc macports::fetch_port {url {local 0}} {
-    global macports::portdbpath macports::ui_prefix macports::portverbose
+    global macports::portdbpath macports::ui_prefix macports::portverbose macports::ui_options
 
     set fetchdir [file join $portdbpath portdirs]
     file mkdir $fetchdir
@@ -1427,11 +1455,13 @@
     } else {
         ui_msg "$macports::ui_prefix Fetching port $url"
         set fetchfile [file tail $url]
-        set verboseflag {}
+        set progressflag {}
         if {$macports::portverbose eq {yes}} {
-            set verboseflag -v
+            set progressflag "--progress builtin"
+        } elseif {[info exists macports::ui_options(progress_download)]} {
+            set progressflag "--progress ${macports::ui_options(progress_download)}"
         }
-        if {[catch {eval curl fetch $verboseflag {$url} {[file join $fetchdir $fetchfile]}} result]} {
+        if {[catch {eval curl fetch $progressflag {$url} {[file join $fetchdir $fetchfile]}} result]} {
             return -code error "Port remote fetch failed: $result"
         }
     }
@@ -1903,7 +1933,7 @@
             if {![macports::ui_isset ports_debug]} {
                 ui_msg {}
             }
-            return -code error "Can't install $portinfo(name) because conflicting ports are installed: $conflictlist"
+            return -code error "Can't install $portinfo(name) because conflicting ports are active: $conflictlist"
         }
     }
 }
@@ -2222,7 +2252,7 @@
 }
 
 proc macports::getportworkpath_from_buildpath {portbuildpath} {
-    return [file join $portbuildpath work]
+    return [file normalize [file join $portbuildpath work]]
 }
 
 proc macports::getportworkpath_from_portdir {portpath {portname {}}} {
@@ -2241,7 +2271,8 @@
 proc mportsync {{optionslist {}}} {
     global macports::sources macports::portdbpath macports::rsync_options \
            tcl_platform macports::portverbose macports::autoconf::rsync_path \
-           macports::autoconf::tar_path macports::autoconf::openssl_path
+           macports::autoconf::tar_path macports::autoconf::openssl_path \
+           macports::ui_options
     array set options $optionslist
     if {[info exists options(no_reindex)]} {
         upvar $options(needed_portindex_var) any_needed_portindex
@@ -2290,14 +2321,14 @@
                         incr numfailed
                         continue
                     }
-                } elseif {$git_cmd ne {} && [file exists ${portdir}/.git]} {
+                } elseif {$git_cmd ne {} && ![catch {exec sh -c "cd ${portdir} && $git_cmd rev-parse --is-inside-work-tree"} result]} {
                     # determine what type of git repository this is
-                    if {![catch {exec sh -c "$git_cmd --git-dir=${portdir}/.git config --local --get svn-remote.svn.url"} result]} {
+                    if {![catch {exec sh -c "cd ${portdir} && $git_cmd config --local --get svn-remote.svn.url"} result]} {
                         set git_action "svn rebase"
                     } else {
                         set git_action "pull --rebase"
                     }
-                    set git_commandline "$git_cmd --git-dir=${portdir}/.git --work-tree=${portdir} $git_action"
+                    set git_commandline "pushd $portdir ; $git_cmd $git_action ; popd"
                     ui_debug $git_commandline
                     if {
                         [catch {
@@ -2484,12 +2515,14 @@
 
                 file mkdir $destdir
 
-                set verboseflag {}
+                set progressflag {}
                 if {$macports::portverbose eq {yes}} {
-                    set verboseflag -v
+                    set progressflag "--progress builtin"
+                } elseif {[info exists macports::ui_options(progress_download)]} {
+                    set progressflag "--progress ${macports::ui_options(progress_download)}"
                 }
 
-                if {[catch {eval curl fetch $verboseflag {$source} {$tarpath}} error]} {
+                if {[catch {eval curl fetch $progressflag {$source} {$tarpath}} error]} {
                     ui_error "Fetching $source failed ($error)"
                     incr numfailed
                     continue
@@ -2632,7 +2665,7 @@
                             } else {
                                 set compres [string compare -nocase $pattern $target]
                             }
-                            set matchres [expr 0 == $compres]
+                            set matchres [expr {0 == $compres}]
                         }
                         glob {
                             if {$case_sensitive eq yes} {
@@ -3104,17 +3137,23 @@
                     return 1
                 } elseif {[info exists dep_portinfo(installs_libs)] && !$dep_portinfo(installs_libs)} {
                     set check_archs 0
+                    if {$skipSatisfied && $present} {
+                        set parse 0
+                    }
                 }
-                set dep_options $options
-                lappend dep_options subport $dep_portinfo(name)
-                # Figure out the depport. Check the open_mports list first, since
-                # we potentially leak mport references if we mportopen each time,
-                # because mportexec only closes each open mport once.
-                set depport [dlist_match_multi $macports::open_mports [list porturl $dep_portinfo(porturl) options $dep_options]]
 
-                if {$depport eq {}} {
-                    # We haven't opened this one yet.
-                    set depport [mportopen $dep_portinfo(porturl) $dep_options $variations]
+                if {$parse} {
+                    set dep_options $options
+                    lappend dep_options subport $dep_portinfo(name)
+                    # Figure out the depport. Check the open_mports list first, since
+                    # we potentially leak mport references if we mportopen each time,
+                    # because mportexec only closes each open mport once.
+                    set depport [dlist_match_multi $macports::open_mports [list porturl $dep_portinfo(porturl) options $dep_options]]
+
+                    if {$depport eq {}} {
+                        # We haven't opened this one yet.
+                        set depport [mportopen $dep_portinfo(porturl) $dep_options $variations]
+                    }
                 }
             }
 
@@ -3166,11 +3205,15 @@
 
     # Loop on the depports.
     if {$recurseDeps} {
+        # Dep ports should be installed (all dependencies must be satisfied).
         foreach depport $depPorts {
-            # Sub ports should be installed (all dependencies must be satisfied).
-            set res [mportdepends $depport {} $recurseDeps $skipSatisfied 1]
-            if {$res != 0} {
-                return $res
+            # Any of these may have been closed by a previous recursive call
+            # and replaced by a universal version. This is fine, just skip.
+            if {[ditem_key $depport] ne {}} {
+                set res [mportdepends $depport {} $recurseDeps $skipSatisfied 1]
+                if {$res != 0} {
+                    return $res
+                }
             }
         }
     }
@@ -3816,6 +3859,11 @@
     array set interp_options [array get options]
     set interp_options(ports_requested) $requestedflag
     set interp_options(subport) $newname
+    # Mark this port to be rebuilt from source if this isn't the first time it
+    # was flagged as broken by rev-upgrade
+    if {$is_revupgrade_second_run} {
+        set interp_options(ports_source_only) yes
+    }
 
     if {[catch {set mport [mportopen $porturl [array get interp_options] [array get variations]]} result]} {
         global errorInfo
@@ -3885,7 +3933,7 @@
     # first upgrade dependencies
     if {![info exists options(ports_nodeps)]} {
         # the last arg is because we might have to build from source if a rebuild is being forced
-        set status [_upgrade_dependencies portinfo depscache variationslist options [expr {$will_build && $already_installed && !$is_revupgrade}]]
+        set status [_upgrade_dependencies portinfo depscache variationslist options [expr {$will_build && $already_installed}]]
         if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
             catch {mportclose $mport}
             return $status
@@ -3976,7 +4024,7 @@
         # we have to force the uninstall in case of dependents
         set force_cur [info exists options(ports_force)]
         set options(ports_force) yes
-        set existing_epoch [lindex [lindex [registry::installed $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants)] 0] 5]
+        set existing_epoch [lindex [registry::installed $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants)] 0 5]
         set newregref [registry::open_entry $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants) $existing_epoch]
         if {$is_dryrun eq {yes}} {
             ui_msg "Skipping uninstall $newname @${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) (dry run)"
@@ -4307,17 +4355,22 @@
 
     set files [registry::file search active 1 binary -null]
     set files_count [llength $files]
-    set fancy_output [expr {![macports::ui_isset ports_debug] && [isatty stdout]}]
+    set fancy_output [expr {![macports::ui_isset ports_debug] && [info exists macports::ui_options(progress_generic)]}]
+    if {$fancy_output} {
+        set revupgrade_progress $macports::ui_options(progress_generic)
+    }
     if {$files_count > 0} {
         registry::write {
             try {
-                ui_msg -nonewline "$macports::ui_prefix Updating database of binaries"
+                ui_msg "$macports::ui_prefix Updating database of binaries"
                 set i 1
+                if {$fancy_output} {
+                    $revupgrade_progress start
+                }
                 foreach f $files {
                     if {$fancy_output} {
-                        if {$files_count < 10000 || $i % 10 == 1 || $i == $files_count} {
-                            ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr {($i * 1000 / $files_count) / 10.0}]%"
-                            flush stdout
+                        if {$files_count < 10000 || $i % 10 == 1} {
+                            $revupgrade_progress update $i $files_count
                         }
                     }
                     set fpath [$f actual_path]
@@ -4327,7 +4380,7 @@
                     if {0 != [catch {$f binary [fileIsBinary $fpath]} fileIsBinaryError]} {
                         # handle errors (e.g. file not found, permission denied) gracefully
                         if {$fancy_output} {
-                            ui_msg {}
+                            $revupgrade_progress intermission
                         }
                         ui_warn "Error determining file type of `$fpath': $fileIsBinaryError"
                         ui_warn "A file belonging to the `[[registry::entry owner $fpath] name]' port is missing or unreadable. Consider reinstalling it."
@@ -4338,14 +4391,16 @@
                 throw
             }
         }
-        ui_msg {}
+        if {$fancy_output} {
+            $revupgrade_progress finish
+        }
     }
 
     set broken_files {};
     set binaries [registry::file search active 1 binary 1]
     set binary_count [llength $binaries]
     if {$binary_count > 0} {
-        ui_msg -nonewline "$macports::ui_prefix Scanning binaries for linking errors"
+        ui_msg "$macports::ui_prefix Scanning binaries for linking errors"
         set handle [machista::create_handle]
         if {$handle eq {NULL}} {
             error "Error creating libmachista handle"
@@ -4353,12 +4408,15 @@
         array unset files_warned_about
         array set files_warned_about [list]
 
+        if {$fancy_output} {
+            $revupgrade_progress start
+        }
+
         set i 1
         foreach b $binaries {
             if {$fancy_output} {
-                if {$binary_count < 10000 || $i % 10 == 1 || $i == $binary_count} {
-                    ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr {($i * 1000 / $binary_count) / 10.0}]%"
-                    flush stdout
+                if {$binary_count < 10000 || $i % 10 == 1} {
+                    $revupgrade_progress update $i $binary_count
                 }
             }
             set bpath [$b actual_path]
@@ -4376,7 +4434,7 @@
                     #ui_debug "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 } else {
                     if {$fancy_output} {
-                        ui_msg {}
+                        $revupgrade_progress intermission
                     }
                     ui_warn "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 }
@@ -4398,7 +4456,7 @@
                                     set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg {}
+                                    $revupgrade_progress intermission
                                 }
                                 ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path"
                             } elseif {![file exists $idloadcmdpath]} {
@@ -4409,7 +4467,7 @@
                                     set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg {}
+                                    $revupgrade_progress intermission
                                 }
                                 ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath"
                                 ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
@@ -4426,7 +4484,7 @@
                                         set portname <unknown-port>
                                     }
                                     if {$fancy_output} {
-                                        ui_msg {}
+                                        $revupgrade_progress intermission
                                     }
                                     ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file ${idloadcmdpath}, which is a different file"
                                     ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
@@ -4451,14 +4509,23 @@
                         continue;
                     }
 
+                    if {(${filepath} == "/usr/lib/libstdc++.6.dylib" && ${macports::cxx_stdlib} == "libc++") ||
+                        (${filepath} == "/usr/lib/libc++.1.dylib" && ${macports::cxx_stdlib} == "libstdc++")} {
+
+                        if {$fancy_output} {
+                            $revupgrade_progress intermission
+                        }
+                        ui_warn "${bpath} uses ${filepath} as C++ standard library although macports::cxx_stdlib is set to ${macports::cxx_stdlib}."
+                    }
+
                     set libresultlist [machista::parse_file $handle $filepath]
                     set libreturncode [lindex $libresultlist 0]
                     set libresult     [lindex $libresultlist 1]
 
                     if {$libreturncode != $machista::SUCCESS} {
                         if {![info exists files_warned_about($filepath)]} {
-                            if {[macports::ui_isset ports_verbose]} {
-                                ui_msg {}
+                            if {$fancy_output} {
+                                $revupgrade_progress intermission
                             }
                             ui_info "Could not open ${filepath}: [machista::strerror $libreturncode] (referenced from $bpath)"
                             set files_warned_about($filepath) yes
@@ -4480,8 +4547,8 @@
                         }
 
                         if {[$loadcommand cget -mlt_version] ne [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
-                            if {[macports::ui_isset ports_verbose]} {
-                                ui_msg {}
+                            if {$fancy_output} {
+                                $revupgrade_progress intermission
                             }
                             ui_info "Incompatible library version: $bpath requires version [machista::format_dylib_version [$loadcommand cget -mlt_comp_version]] or later, but $filepath provides version [machista::format_dylib_version [$libarchitecture cget -mat_comp_version]]"
                             ui_debug "Marking $bpath as broken"
@@ -4508,7 +4575,9 @@
                 set architecture [$architecture cget -next]
             }
         }
-        ui_msg {}
+        if {$fancy_output} {
+            $revupgrade_progress finish
+        }
 
         machista::destroy_handle $handle
 
@@ -4664,16 +4733,20 @@
         array set depscache {}
         set status 0
         array set my_options [array get macports::global_options]
+        set my_options(ports_revupgrade) yes
         foreach port $topsort_ports {
             set portname [$port name]
             if {![info exists depscache(port:$portname)]} {
-                # set rev-upgrade options and nodeps if this is not the first run
-                set my_options(ports_revupgrade) yes
-                unset -nocomplain my_options(ports_revupgrade_second_run)
+                unset -nocomplain my_options(ports_revupgrade_second_run) \
+                                  my_options(ports_nodeps)
                 if {$broken_port_counts($portname) > 1} {
                     set my_options(ports_revupgrade_second_run) yes
-                    # build from source only until the buildbot has some method of rev-upgrade, too
-                    set my_options(ports_source_only) yes
+
+                    if {$broken_port_counts($portname) > 2} {
+                        # runtime deps are upgraded the first time, build deps 
+                        # the second, so none left to do the third time
+                        set my_options(ports_nodeps) yes
+                    }
                 }
 
                 # call macports::upgrade with ports_revupgrade option to rebuild the port

Modified: branches/new-help-system/base/src/macports1.0/macports_autoconf.tcl.in
===================================================================
--- branches/new-help-system/base/src/macports1.0/macports_autoconf.tcl.in	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/macports_autoconf.tcl.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -54,4 +54,6 @@
     variable xar_path "@XAR@"
     variable xcode_select_path "@XCODE_SELECT@"
     variable xcodebuild_path "@XCODEBUILD@"
+    variable os_platform "@OS_PLATFORM@"
+    variable os_major "@OS_MAJOR@"
 }

Modified: branches/new-help-system/base/src/macports1.0/macports_dlist.tcl
===================================================================
--- branches/new-help-system/base/src/macports1.0/macports_dlist.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/macports_dlist.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -292,7 +292,7 @@
 	
 	# Do a pre-run seeing if any items automagically
 	# can evaluate to true.
-	if {$testcond != ""} {
+	if {$testcond ne ""} {
 		foreach ditem $dlist {
 			if {[eval "expr \[\$testcond \$ditem\] == 1"]} {
 				foreach token [ditem_key $ditem provides] {
@@ -323,7 +323,7 @@
 			if {$result == {}} { set result 0 }
 			
 			foreach token [ditem_key $ditem provides] {
-				set statusdict($token) [expr $result == 0]
+				set statusdict($token) [expr {$result == 0}]
 			}
 			
 			# Abort if we're not allowed to fail

Copied: branches/new-help-system/base/src/macports1.0/macports_test_autoconf.tcl.in (from rev 117083, trunk/base/src/macports1.0/macports_test_autoconf.tcl.in)
===================================================================
--- branches/new-help-system/base/src/macports1.0/macports_test_autoconf.tcl.in	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/macports_test_autoconf.tcl.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,37 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
+# macports-autoconf.tcl.in
+# $Id: macports_autoconf.tcl.in 90070 2012-02-20 21:54:35Z jberry at macports.org $
+#
+# Copyright (c) 2006 - 2009, 2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Apple Inc. nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+namespace eval macports::autoconf {
+    variable macports_tcl_dir "@macports_tcl_dir@"
+    variable prefix "@prefix@"
+}

Modified: branches/new-help-system/base/src/macports1.0/macports_util.tcl
===================================================================
--- branches/new-help-system/base/src/macports1.0/macports_util.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/macports_util.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -98,8 +98,8 @@
             if {$size == 0} {
                 set badrange? 1
             }
-        } elseif {[string match end-* $idx] && [string is integer -strict [string range $idx 4 end]]} {
-            set i [expr $size - 1 - [string range $idx 4 end]]
+        } elseif {[string match "end-*" $idx] && [string is integer -strict [string range $idx 4 end]]} {
+            set i [expr {$size - 1 - [string range $idx 4 end]}]
             if {$i < 0 || $i >= $size} {
                 set badrange? 1
             }
@@ -270,8 +270,8 @@
         foreach {elem catchBody} $catchList {
             set typeList [lshift elem]
             set match? 1
-            set typeList [lrange $typeList 0 [expr [llength $savedErrorCode] - 1]]
-            set codeList [lrange $savedErrorCode 0 [expr [llength $typeList] - 1]]
+            set typeList [lrange $typeList 0 [expr {[llength $savedErrorCode] - 1}]]
+            set codeList [lrange $savedErrorCode 0 [expr {[llength $typeList] - 1}]]
             foreach type $typeList code $codeList {
                 if {![string match $type $code]} {
                     set match? 0

Copied: branches/new-help-system/base/src/macports1.0/tests/Portfile (from rev 117083, trunk/base/src/macports1.0/tests/Portfile)
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/Portfile	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/tests/Portfile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,40 @@
+# $Id: Portfile 85472 2011-10-14 01:52:18Z dports at macports.org $
+
+PortSystem              1.0
+
+name                    fondu
+version                 060102
+revision                1
+platforms               darwin
+categories              print
+license                 BSD
+maintainers             nomaintainer
+homepage                http://fondu.sourceforge.net/
+master_sites            http://fondu.sourceforge.net/
+
+description             A set of programs to interconvert between Mac font \
+                        formats and pfb, ttf, otf and bdf files on UNIX.
+
+long_description        Dealing with Mac fonts is hard on other operating \
+                        systems because Mac fonts are stored in the resource \
+                        fork, and other operating systems do not support \
+                        this concept. Fondu will extract the resource fork \
+                        from either a MacBinary file or a BinHex file. Ufond \
+                        will create a resource fork inside a MacBinary file.
+
+checksums               md5 e20861beacddc1ab392bef7813641bf8
+extract.suffix          .tgz
+distfiles               ${name}_src-${version}${extract.suffix}
+
+post-patch {
+    reinplace "s|^CFLAGS = -g \$(WFLAGS)|CFLAGS = -g \$(WFLAGS) ${configure.cppflags} ${configure.cflags} ${configure.ldflags} [get_canonical_archflags]|g" ${worksrcpath}/Makefile.in
+}
+
+configure.args          --bindir=${prefix}/bin \
+                        --mandir=${prefix}/share/man
+
+post-destroot {
+    eval xinstall -m 644 [glob ${worksrcpath}/*.1] ${destroot}${prefix}/share/man/man1/
+}
+
+test.run		yes

Copied: branches/new-help-system/base/src/macports1.0/tests/library.tcl (from rev 117083, trunk/base/src/macports1.0/tests/library.tcl)
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/library.tcl	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/tests/library.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,65 @@
+##
+# This is basically a copy of macports::worker_init, but without using
+# sub-interpreters
+proc macports_worker_init {} {
+    interp alias {} _cd {} cd
+    proc PortSystem {version} {
+        package require port $version
+    }
+    # Clearly separate slave interpreters and the master interpreter.
+    interp alias {} mport_exec      {} mportexec
+    interp alias {} mport_open      {} mportopen
+    interp alias {} mport_close     {} mportclose
+    interp alias {} mport_lookup    {} mportlookup
+    interp alias {} mport_info      {} mportinfo
+    # Export some utility functions defined here.
+    interp alias {} macports_create_thread          {} macports::create_thread
+    interp alias {} getportworkpath_from_buildpath  {} macports::getportworkpath_from_buildpath
+    interp alias {} getportresourcepath             {} macports::getportresourcepath
+    interp alias {} getportlogpath                  {} macports::getportlogpath
+    interp alias {} getdefaultportresourcepath      {} macports::getdefaultportresourcepath
+    interp alias {} getprotocol                     {} macports::getprotocol
+    interp alias {} getportdir                      {} macports::getportdir
+    interp alias {} findBinary                      {} macports::findBinary
+    interp alias {} binaryInPath                    {} macports::binaryInPath
+    # New Registry/Receipts stuff
+    interp alias {} registry_new                    {} registry::new_entry
+    interp alias {} registry_open                   {} registry::open_entry
+    interp alias {} registry_write                  {} registry::write_entry
+    interp alias {} registry_prop_store             {} registry::property_store
+    interp alias {} registry_prop_retr              {} registry::property_retrieve
+    interp alias {} registry_exists                 {} registry::entry_exists
+    interp alias {} registry_exists_for_name        {} registry::entry_exists_for_name
+    interp alias {} registry_activate               {} portimage::activate
+    interp alias {} registry_deactivate             {} portimage::deactivate
+    interp alias {} registry_deactivate_composite   {} portimage::deactivate_composite
+    interp alias {} registry_uninstall              {} registry_uninstall::uninstall
+    interp alias {} registry_register_deps          {} registry::register_dependencies
+    interp alias {} registry_fileinfo_for_index     {} registry::fileinfo_for_index
+    interp alias {} registry_fileinfo_for_file      {} registry::fileinfo_for_file
+    interp alias {} registry_bulk_register_files    {} registry::register_bulk_files
+    interp alias {} registry_active                 {} registry::active
+    interp alias {} registry_file_registered        {} registry::file_registered
+    interp alias {} registry_port_registered        {} registry::port_registered
+    interp alias {} registry_list_depends           {} registry::list_depends
+    # deferred options processing.
+    interp alias {} getoption {} macports::getoption
+    # ping cache
+    interp alias {} get_pingtime {} macports::get_pingtime
+    interp alias {} set_pingtime {} macports::set_pingtime
+    # archive_sites.conf handling
+    interp alias {} get_archive_sites_conf_values {} macports::get_archive_sites_conf_values
+    foreach opt $macports::portinterp_options {
+        if {![info exists $opt]} {
+            global macports::$opt
+            set ::$opt macports::$opt
+        }
+        if {[info exists $opt]} {
+            set system_options($opt) $opt
+            set ::$opt $opt
+        }
+    }
+
+    # We don't need to handle portinterp_deferred_options, they're
+    # automatically handled correctly.
+}

Copied: branches/new-help-system/base/src/macports1.0/tests/macports.test (from rev 117083, trunk/base/src/macports1.0/tests/macports.test)
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/macports.test	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/tests/macports.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,966 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+eval ::tcltest::configure $::argv
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../macports_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+# clean leftovers from interrupted tests
+file delete -force $pwd/tmpdir
+
+# use custom macports.conf and sources.conf
+makeDirectory $pwd/tmpdir
+makeDirectory $pwd/tmpdir/share
+makeDirectory $pwd/tmpdir/var/macports/registry
+set fd [open $pwd/tmpdir/macports.conf w+]
+puts $fd "portdbpath $pwd/tmpdir/var/macports"
+puts $fd "prefix $pwd/tmpdir"
+puts $fd "variants_conf $pwd/tmpdir/variants.conf"
+puts $fd "sources_conf $pwd/sources.conf"
+puts $fd "applications_dir $pwd/tmpdir/Applications"
+puts $fd "frameworks_dir $pwd/tmpdir/Library/Frameworks"
+close $fd
+set env(PORTSRC) $pwd/tmpdir/macports.conf
+file link -symbolic $pwd/tmpdir/share/macports $macports::autoconf::prefix/share/macports
+close [open $pwd/tmpdir/variants.conf w+]
+
+# Debug options
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portutil 1.0
+package require portinstall 1.0
+package require portuninstall 1.0
+package require Thread
+source ../../registry2.0/portuninstall.tcl
+source ../../port1.0/port_autoconf.tcl
+source ./library.tcl
+macports_worker_init
+
+
+test mportclose {
+    Mport close unit test.
+} -setup {
+    set mport [mportopen file://.]
+} -body {
+    if {[catch {mportclose $mport}] != 0} {
+       return "FAIL: cannot run mportclose"
+    }
+    if {[ditem_key $mport workername] != ""} {
+       return "FAIL: port not closed"
+    }
+    return "Mport close successful."
+} -cleanup {
+    catch {mportclose $mport}
+} -result "Mport close successful."
+
+
+test mportinfo {
+    Mport info uni test.
+} -setup {
+    set mport [mportopen file://.]
+} -body {
+    set res [mportinfo $mport]
+    if {[lindex $res 2] != "canonical_active_variants"} {
+        return "FAIL: cannot get ::PortInfo"
+    }
+    return "Mport info successful."
+} -cleanup {
+    mportclose $mport
+} -result "Mport info successful."
+
+
+test mportopen_installed {
+    Mport installed unit test.
+} -constraints {
+    root
+} -setup {
+    set os.platform darwin
+    set macosx_version 10.8
+    set os.major 10
+    set os_version 11
+    set os_arch i386
+
+    set supported_archs {}
+    set configure.build_arch build_arch
+    set portarchivetype tgz
+
+    set destpath $pwd/work/destroot
+    set portdbpath $pwd/portdbpath
+    set workpath $pwd/fondu/work
+    set portpath $pwd
+
+    set subport fondu
+    set version 3.0
+    set revision 1
+    set epoch i386
+
+    file copy -force $pwd/Portfile /tmp/
+    set mport [mportopen file://.]
+
+    proc getportbuildpath {id {portname ""}} {
+        global portdbpath
+        regsub {://} $id {.} port_path
+        regsub -all {/} $port_path {_} port_path
+        return [file join $portdbpath build $port_path $portname]
+    }
+
+    proc getportworkpath_from_buildpath {portbuildpath} {
+        return [file join $portbuildpath work]
+    }
+
+    proc getportworkpath_from_portdir {portpath {portname ""}} {
+        return [getportworkpath_from_buildpath [getportbuildpath $portpath $portname]]
+    }
+
+    source $pwd/../../port1.0/portmain.tcl
+
+    # sets up PortInfo array
+    if {[eval_variants variations] != 0} {
+        mportclose $mport
+        error "Error evaluating variants"
+    }
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # run destroot
+    $workername eval eval_targets destroot
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+    set macosx_deployment_target $pwd/deploy_target
+    file mkdir $pwd/$subport
+    file link -symbolic $pwd/$subport/work $pwd/work
+
+    if {[catch {portinstall::install_main}] != 0} {
+        return "FAIL: cannot install port"
+    }
+
+    set variants {}
+    set options {}
+
+} -body {
+    set res [mportopen_installed $subport $version $revision $variants $options]
+    if {![string match "ditem_*" $res]} {
+       return "FAIL: installed port not opened"
+    }
+
+    if {[catch {mportclose_installed $res}] != 0} {
+       return "FAIL: cannot close port"
+    }
+    if {[catch {mportclose_installed $res}] != 1} {
+       return "FAIL: installed port not closed"
+    }
+    return "Installed port open successful."
+
+} -cleanup {
+    if {[catch {portuninstall::uninstall_main}] != 0} {
+        return "FAIL: cannot install port"
+    }
+    mportclose $mport
+
+    file delete -force $pwd/work
+    file delete -force $pwd/$subport
+} -result "Installed port open successful."
+
+
+test ui_isset {
+    Ui is set unit test.
+} -body {
+    namespace eval macports {
+    array set ui_options { test yes }
+    }
+    if {[macports::ui_isset test] != 1} {
+       return "FAIL: set option not detected"
+    }
+    if {[macports::ui_isset port] != 0} {
+       return "FAIL: unset option detected"
+    }
+    return "ui_isset successful."
+} -result "ui_isset successful."
+
+
+test global_option_isset {
+    Global option is set unit test.
+} -body {
+    namespace eval macports {
+    array set global_options { test yes }
+    }
+    if {[macports::global_option_isset test] != 1} {
+       return "FAIL: set option not detected"
+    }
+    if {[macports::global_option_isset port] != 0} {
+       return "FAIL: unset option detected"
+    }
+    return "Global option isset successful."
+} -result "Global option isset successful."
+
+
+test init_logging {
+    Init logging unit test.
+} -constraints {
+    root
+} -setup {
+    set mport [mportopen file://.]
+} -body {
+    if {[macports::init_logging $mport] != 0} {
+       return "FAIL: incorrect channels"
+    }
+    if {$macports::channels(any) != "stdout debuglog"} {
+       return "FAIL: incorrect channels(any)"
+    }
+    if {$macports::channels(debug) != "debuglog"} {
+       return "FAIL: incorrect channels(debug)"
+    }
+    return "Init logging successful."
+} -cleanup {
+    mportclose $mport
+} -result "Init logging successful."
+
+
+test ch_logging {
+    Channel logging unit test. Assumes main.log filename.
+} -constraints {
+    root
+} -setup {
+    set mport [mportopen file://.]
+
+    set portname [_mportkey $mport subport]
+    set portpath [_mportkey $mport portpath]
+    set logname [macports::getportlogpath $portpath $portname]
+    file delete -force $logname
+
+} -body {
+    if {[macports::ch_logging $mport] != 0} {
+       return "FAIL: channels not set"
+    }
+    if {![file exists $logname]} {
+       return "FAIL: logname dir missing"
+    }
+    if {![file exists $logname/main.log]} {
+       return "FAIL: main.log missing"
+    }
+    return "Channel logging successful."
+
+} -cleanup {
+    mportclose $mport
+} -result "Channel logging successful."
+
+
+test push_log {
+    Push log unit test.
+} -constraints {
+    root
+} -setup {
+    set mport [mportopen file://.]
+    set ::logenabled 1
+} -body {
+    if {[catch {macports::push_log $mport}] != 0} {
+       return "FAIL: cannot push log"
+    }
+    if {[lindex $::logstack 0] != [list $::debuglog $::debuglogname]} {
+       return "FAIL: incorrect logstack"
+    }
+    return "Push log successful."
+} -cleanup {
+    mportclose $mport
+} -result "Push log successful."
+
+
+test pop_log {
+    Pop log unit test.
+} -setup {
+    set ::logenabled 1
+    set ::logstack [open $pwd/logstack w+]
+    set ::debuglog [open $pwd/log w+]
+    set mport [mportopen file://.]
+    if {[catch {macports::push_log $mport}] != 0} {
+       return "FAIL: cannot push log"
+    }
+} -body {
+    macports::pop_log
+    if {$::debuglog != $::logstack} {
+	return "FAIL: cannot pop log"
+    }
+    return "Pop log successful."
+} -cleanup {
+    unset ::logenabled
+    unset ::logstack
+    unset ::debuglog
+    mportclose $mport
+    file delete -force $pwd/log
+    file delete -force $pwd/logstack
+} -result "Pop log successful."
+
+
+test set_phase {
+    Set phase unit test.
+} -body {
+    set res [set_phase test]
+    if {$macports::current_phase != "test"} {
+	return "FAIL: phase not set"
+    }
+    return "Set phase successful."
+} -result "Set phase successful."
+
+
+test ui_message {
+    UI message unit test.
+} -setup {
+    set fd [open $pwd/message w+]
+    set fd2 [open $pwd/log w+]
+    set macports::channels(0) $fd
+    set macports::channels(debuglog) $fd2
+    set macports::current_phase test
+    set ::debuglog $fd2
+} -body {
+    set res [ui_message 0 prefix phase args]
+    close $fd
+    close $fd2
+    set fd2 [open $pwd/message r]
+    set line [read $fd2]
+    if {$line != "prefixargs\n"} {
+	return "FAIL: wrong message"
+    }
+    close $fd2
+
+    set fd [open $pwd/message w+]
+    set fd2 [open $pwd/log w+]
+    set res [ui_message debuglog prefix phase -nonewline arg]
+    close $fd
+    close $fd2
+    set fd2 [open $pwd/log r]
+    set line [read $fd2]
+    if {$line != "prefixarg"} {
+	return "FAIL: wrong message"
+    }
+    close $fd2
+
+    return "UI message successful."
+} -cleanup {
+    file delete -force $pwd/log
+    file delete -force $pwd/message
+} -result "UI message successful."
+
+
+# test ui_init
+
+
+test ui_prefix_default {
+    UI prefix default unit test.
+} -body {
+    if {[macports::ui_prefix_default debug] ne {DEBUG: }} {
+	return "FAIL: wrong prefix"
+    }
+    if {[macports::ui_prefix_default error] ne {Error: }} {
+	return "FAIL: wrong prefix"
+    }
+    if {[macports::ui_prefix_default warn] ne {Warning: }} {
+	return "FAIL: wrong prefix"
+    }
+    if {[macports::ui_prefix_default default] ne {}} {
+	return "FAIL: wrong prefix"
+    }
+    return "UI prefix default successful."
+} -result "UI prefix default successful."
+
+
+test ui_channels_default {
+    UI channels default unit test.
+} -setup {
+    set macports::ui_options(ports_debug) yes
+    set macports::ui_options(ports_verbose) yes
+    set macports::ui_options(ports_quiet) yes
+} -body {
+    if {[macports::ui_channels_default debug] ne {stderr}} {
+	return "FAIL: stderr not set"
+    }
+    if {[macports::ui_channels_default info] ne {stdout}} {
+	return "FAIL: stdout not set"
+    }
+    if {[macports::ui_channels_default notice] ne {}} {
+	return "FAIL: channel not set"
+    }
+    if {[macports::ui_channels_default msg] ne {stdout}} {
+	return "FAIL: channel not set"
+    }
+    if {[macports::ui_channels_default warn] ne {stderr}} {
+	return "FAIL: channel not set"
+    }
+    if {[macports::ui_channels_default error] ne {stderr}} {
+	return "FAIL: channel not set"
+    }
+    if {[macports::ui_channels_default default] ne {stdout}} {
+	return "FAIL: channel not set"
+    }
+    return "UI channels default successful."
+} -result "UI channels default successful."
+
+
+test ui_warn_once {
+    UI warn once unit test.
+} -body {
+    set res [ui_warn_once 0 test]
+    if {$macports::warning_done(0) != 1} {
+	return "FAIL: warning flag not set"
+    }
+    return "UI warn once successful."
+} -result "UI warn once successful."
+
+
+# Replace puts to catch errors 
+# test puts
+
+
+test findBinary {
+    Find binary unit test.
+} -body {
+    if {[macports::findBinary pwd ls] != "/bin/pwd"} {
+       return "FAIL: wrong binary"
+    }
+    if {[macports::findBinary pwd /bin/ls] != "/bin/ls"} {
+       return "FAIL: wrong binary"
+    }
+    return "Find binary successful."
+} -result "Find binary successful."
+
+
+test binaryInPath {
+    Binary in path unit test.
+} -body {
+    if {[catch {macports::binaryInPath zz}] != 1} {
+       return "FAIL: invalid binary found"
+    }
+    if {[macports::binaryInPath ls] != "/bin/ls"} {
+       return "FAIL: wrong binary found"
+    }
+    return "Binary in path successful."
+} -result "Binary in path successful."
+
+
+test getoption {
+    Get option unit test.
+} -body {
+    set macports::test macports
+    if {[macports::getoption test] != "macports"} {
+	return "FAIL: cannot get option"
+    }
+    return "Get option successful."
+} -result "Get option successful."
+
+
+test setxcodeinfo {
+    Set XCode info unit test.
+} -constraints {
+    root
+} -setup {
+    unset macports::xcodeversion
+} -body {
+    if {[macports::setxcodeinfo a b c] != ""} {
+       return "FAIL: xcode binary not found"
+    }
+    if {![info exists macports::xcodeversion]} {
+       return "FAIL: xcodeversion unset"
+    }
+    return "Set XCode version successful."
+} -result "Set XCode version successful."
+
+
+test set_developer_dir {
+    Set developer dir unit test. Tests only for correct xcode-select dir.
+} -constraints {
+    root
+} -body {
+    unset macports::developer_dir
+
+    if {[macports::set_developer_dir a b c] != ""} {
+       return "FAIL: cannot set dev dir"
+    }
+    if {![info exists macports::developer_dir]} {
+       return "FAIL: developer_dir var no set"
+    }
+    return "Set developer dir successful."
+} -result "Set developer dir successful."
+
+
+test _is_valid_developer_dir {
+    Check valid dev dir unit test.
+} -body {
+    set macports::set_developer /Applications/Xcode.app/Contents/Developer
+    if {[macports::_is_valid_developer_dir $macports::developer_dir] != 1} {
+       return "FAIL: valid dir not detected"
+    }
+    return "Valid dev dir successful."
+} -result "Valid dev dir successful."
+
+
+# test mportinit
+
+
+test mportshutdown {
+    Mport shutdown unit test.
+} -setup {
+    unset macports::ping_cache
+
+    set time [expr [clock seconds] - 86100]
+    set time_exp [expr [clock seconds] - 87000]
+    set macports::portdbpath $pwd/portdbpath
+    set macports::ping_cache(host1) [list test $time]
+    set macports::ping_cache(host2) [list test $time_exp]
+
+    file mkdir $macports::portdbpath
+    close [open $macports::portdbpath/pingtimes w+]
+
+} -body {
+    if {[mportshutdown] != ""} {
+       return "FAIL: errors occured"
+    }
+
+    set res ""
+    append res "host1 \{test " $time "\}"
+    set fd [open $macports::portdbpath/pingtimes r]
+
+    if {[gets $fd] != $res} {
+       return "FAIL: wrong value saved"
+    }
+    close $fd
+    return "Mportshutdown successful."
+
+} -cleanup {
+    file delete -force $macports::portdbpath
+} -result "Mportshutdown successful."
+
+
+test copy_xcode_plist {
+    Copy xcode plist unit test.
+} -constraints {
+    root
+} -body {
+    set target $pwd/target
+
+    if {[macports::copy_xcode_plist $target] != ""} {
+       return "FAIL: cannot copy xcode plist"
+    }
+    if {![file exists $target/Library/Preferences/com.apple.dt.Xcode.plist]} {
+       return "FAIL: missing plist file"
+    }
+    return "Copy xcode plist successful."
+} -cleanup {
+    file delete -force $target
+} -result "Copy xcode plist successful."
+
+
+test worker_init {
+    Worker init unit test.
+} -setup {
+    set name [interp create]
+    set portpath $pwd/portpath
+    set porturl http://www.macports.org
+    set portbuildpath $pwd/build
+    set options {a b}
+    set variations {1 2}
+} -body {
+    macports::worker_init $name $portpath $porturl $portbuildpath $options $variations
+    if {$name != "interp0"} {
+       return "FAIL: wrong workername"
+    }
+    if {[$name eval source Portfile] != "yes"} {
+       return "FAIL: cannot load Portfile"
+    }
+    if {[$name eval findBinary ls] != "/bin/ls"} {
+       return "FAIL: alias not created"
+    }
+    if {[$name eval return \$os_arch] != "i386"} {
+       return "FAIL: var not set"
+    }
+    return "Worker init successful."
+} -result "Worker init successful."
+
+
+test create_thread {
+    Create thread unit test.
+} -body {
+    unset macports::portinterp_options
+    set macports::portinterp_options {a b}
+
+    set res [macports::create_thread]
+    if {![string match "tid0x*" $res]} {
+       return "FAIL: cannot create thread"
+    }
+    return "Create thread successful."
+} -result "Create thread successful."
+
+
+test get_tar_flags {
+    Get tar flags unit test.
+} -body {
+    if {[macports::get_tar_flags .tbz2] != "-j"} {
+	return "FAIL: wrong flaga (-j)"
+    }
+    if {[macports::get_tar_flags .tgz] != "-z"} {
+	return "FAIL: wrong flaga (-z)"
+    }
+    return "Get tar flags successful."
+} -result "Get tar flags successful."
+
+
+test fetch_port {
+    Fetch port unit test.
+} -body {
+    set url http://packages.macports.org/fondu/fondu-060102_1.darwin_10.x86_64.tbz2
+    set res [macports::fetch_port $url]
+    if {$res != "${pwd}/portdbpath/portdirs/fondu-060102_1"} {
+	return "FAIL: cannot fetch port"
+    }
+    return "Fetch port successful."
+} -cleanup {
+    file delete -force $pwd/portdbpath
+} -result "Fetch port successful."
+
+
+test getprotocol {
+    Get protocol unit test.
+} -body {
+    if {[macports::getprotocol http://www.macports.org] != "http"} {
+       return "FAIL: wrong protocol"
+    }
+    return "Get protocol successful."
+} -result "Get protocol successful."
+
+
+test getportdir {
+    Get port directory unit test.
+} -setup {
+    close [open $pwd/local_file w+]
+} -body {
+    set url http://fondu.sourceforge.net/fondu_src-060102.tgz
+    set res [macports::getportdir $url]
+    if {$res != "${pwd}/portdbpath/portdirs/fondu_src-060102"} {
+	return "FAIL: invalid port directory"
+    }
+
+    set url file://${pwd}/local_file
+    if {[macports::getportdir $url] != "${pwd}/local_file"} {
+	return "FAIL: invalid local port directory"
+    }
+    return "Get port dir successful."
+} -cleanup {
+    file delete -force $pwd/portdbpath
+    file delete -force $pwd/local_file
+} -result "Get port dir successful."
+
+
+test getportresourcepath {
+    Get port resource path. Doesn't check for 'file' protocol.
+} -body {
+    set macports::portdbpath $pwd/portdbpath
+    set url "http://packages.macports.org/fondu/fondu-060102_1.darwin_12.x86_64.tbz2"
+    set default_path $pwd/portdbpath/sources/rsync.macports.org/release/tarballs/ports/_resources
+    set fallback_path $pwd/portdbpath/sources/packages.macports.org/fondu/fondu-060102_1.darwin_12.x86_64.tbz2/_resources
+
+    if {[macports::getportresourcepath $url "" yes] != $default_path} {
+       return "FAIL: wrong resource path"
+    }
+    if {[macports::getportresourcepath $url "" no] != $fallback_path} {
+       return "FAIL: wrong fallback path"
+    }
+    if {[macports::getportresourcepath $url "test" no] != "${fallback_path}/test"} {
+       return "FAIL: wrong fallback path with subdir"
+    }
+
+    return "Get resource path successful."
+} -result "Get resource path successful."
+
+
+test getdefaultportresourcepath {
+    Get default port resource path unit test.
+} -body {
+    set path test/path
+    set macports::sources_default file://$pwd
+    if {[macports::getdefaultportresourcepath $path] != "${pwd}/_resources/${path}"} {
+       return "FAIL: wrong file res path"
+    }
+
+    set macports::sources_default http://$pwd
+    set default_source_url [lindex ${macports::sources_default} 0]
+    set right_path [macports::getsourcepath $default_source_url]/_resources/test/path
+    if {[macports::getdefaultportresourcepath $path] != $right_path} {
+       return "FAIL: wrong http res path"
+    }
+    return "Default res path successful."
+} -result "Default res path successful."
+
+
+# test mportopen
+
+
+# Covered by mportopen_installed
+# test mportclose_installed
+
+
+test mporttraverse {
+    Mport traverse unit test. Uses 3rd column of the Portfile.
+} -setup {
+    file mkdir $pwd/porttree
+    file mkdir $pwd/porttree/cat1/fondu
+    file mkdir $pwd/porttree/cat2/fondu
+
+    file copy -force $pwd/Portfile $pwd/porttree/cat1/fondu/Portfile
+    file copy -force $pwd/Portfile $pwd/porttree/cat2/fondu/Portfile
+
+    proc test_proc {file} {
+       global pwd res
+       set fd [open ${pwd}/porttree/${file}/Portfile r]
+       gets $fd line
+       append res [lindex [split $line " "] 3]
+    }
+
+    global res
+    set res ""
+} -body {
+    mporttraverse test_proc $pwd/porttree
+    if {$res != "8547285472"} {
+       return "FAIL: porttree not traversed"
+    }
+    return "Mport traverse successful."
+} -cleanup {
+    file delete -force $pwd/porttree
+} -result "Mport traverse successful."
+
+
+# test _mportsearchpath
+# test _mportinstalled
+# test _mportactive
+# test _portnameactive
+# test _mportispresent
+# test _mporterrorifconflictsinstalled
+# test _mportexec
+# test mportexec
+# test _upgrade_mport_deps
+# test _get_registry_archs
+# test getsourcepath
+# test _source_is_snapshot
+# test getportbuildpath
+# test getportlogpath
+# test getportworkpath_from_buildpath
+# test getportworkpath_from_portdir
+# test getindex
+# test mportsync
+# test mportsearch
+# test mportlookup
+# test mportlistall
+# test _mports_load_quickindex
+# test mports_generate_quickindex
+
+
+# test _mportkey
+# test mportdepends
+# test _mport_supports_archs
+# test _mport_archs
+# test _active_supports_archs
+# test _active_archs
+# test _explain_arch_mismatch
+# test _mport_has_deptypes
+# test _target_needs_deps
+# test _deptypes_for_target
+# test selfupdate
+# test upgrade
+# test _upgrade
+# test _upgrade_dependencies
+
+
+test mportselect {
+    Mport select unit test.
+} -setup {
+    set macports::prefix $pwd/prefix
+
+    file mkdir $macports::prefix/etc/select/group
+    set f1 [open $macports::prefix/etc/select/group/file1 w+]
+    set f2 [open $macports::prefix/etc/select/group/file2 w+]
+    set f3 [open $macports::prefix/srcs w+]
+    puts $f1 "srcs\n"
+    close $f1
+    close $f2
+    close $f3
+
+    set fd [open $macports::prefix/etc/select/group/base w+]
+    puts $fd "a\nb"
+    close $fd
+} -body {
+    if {[mportselect list group] != {file1 file2}} {
+       return "FAIL: files not listed"
+    }
+    if {[mportselect set group file1] != ""} {
+       reutrn "FAIL: cannot set links"
+    }
+    if {![file exists $macports::prefix/a]} {
+       return "FAIL: link not created"
+    }
+    if {[mportselect show group] != "file1"} {
+       return "FAIL: file not selected"
+    }
+    return "Mport select successful."
+
+} -cleanup {
+    file delete -force $macports::prefix
+} -result "Mport select successful."
+
+
+test gettmpdir {
+    Get tmp dir unit test.
+} -body {
+    global env
+    set env(TMPDIR) temporal
+    if {[macports::gettmpdir] != "temporal"} {
+       return "FAIL: set temp dir not detected"
+    }
+    unset env(TMPDIR)
+    if {[macports::gettmpdir] != "/tmp"} {
+       return "FAIL: default value not set"
+    }
+    return "Get tmp dir successful."
+} -result "Get tmp dir successful."
+
+
+test arch_runnable {
+    Arch runnable unit test.
+} -body {
+    set macports::os_major 12
+    set macports::os_arch i386
+    set macports::os_platform darwin
+    if {[macports::arch_runnable ppc1] != no} {
+       return "FAIL: major:12 arch:i386 arch:ppc* not detected"
+    }
+    if {[macports::arch_runnable ppc64] != no} {
+       return "FAIL: major:12 arch:i386 arch:ppc64 not detected"
+    }
+    set macports::os_major 7
+    set macports::os_arch i386
+    set macports::os_platform darwin
+    if {[macports::arch_runnable x86_64] != no} {
+       return "FAIL: major:7 arch:i386 arch:x86_64 not detected"
+    }
+    set macports::os_major 12
+    set macports::os_arch i386
+    set macports::os_platform darwin
+    if {[macports::arch_runnable x86_64] != yes} {
+       return "FAIL: major:12 arch:i386 arch:x86_64 not detected"
+    }
+    return "Arch runnable successful."
+} -result "Arch runnable successful."
+
+
+# test revupgrade
+# test revupgrade_scanandrebuild
+
+
+test path_is_in_prefix {
+    Path is in prefix unit test.
+} -body {
+    set macports::applications_dir appdir
+    if {[macports::path_is_in_prefix appdir/test/port] != yes} {
+       return "FAIL: application dir not detected"
+    }
+    set macports::prefix prefix
+    if {[macports::path_is_in_prefix prefix/test/port] != yes} {
+       return "FAIL: prefix not detected"
+    }
+    if {[macports::path_is_in_prefix test/port] != no} {
+       return "FAIL: no prefix detected"
+    }
+    return "Path prefix successful."
+} -result "Path prefix successful."
+
+
+test revupgrade_handle_special_paths {
+    Revupgrade handle special paths unit test.
+} -body {
+    set res [macports::revupgrade_handle_special_paths fname test_path]
+    if {$res != "test_path"} {
+       return "FAIL: wrong path"
+    }
+    set res [macports::revupgrade_handle_special_paths fname @loader_path/test_load]
+    if {$res != "./test_load"} {
+       return "FAIL: wrong load path"
+    }
+    return "Revupgrade handle special path successful."
+} -result "Revupgrade handle special path successful."
+
+
+# test revupgrade_buildgraph
+
+
+test get_pingtime {
+    Get ping time unit test.
+} -setup {
+    set time [expr [clock seconds] - 86300]
+    set macports::ping_cache(macports.org) [list MacPorts $time]
+    set macports::host_blacklisted(macports_blacklist) [list black $time]
+    set macports::host_preferred(macports_pref) [list pref $time]
+
+} -body {
+    if {[macports::get_pingtime macports.org] != "MacPorts"} {
+       return "FAIL: wrong ping time"
+    }
+    if {[macports::get_pingtime macports_blacklist] != -1} {
+       return "FAIL: wrong time for blacklisted host"
+    }
+    if {[macports::get_pingtime macports_pref] != 1} {
+       return "FAIL: wrong time for preferred host"
+    }
+    return "Get ping time successful."
+} -result "Get ping time successful."
+
+
+test set_pingtime {
+    Set ping time unit test.
+} -body {
+    set macports::ping_cache(macports) {}
+    if {[lindex [macports::set_pingtime macports 007] 0] != 007} {
+       return "FAIL: ping time not set"
+    }
+    return "Set ping time successful."
+} -result "Set ping time successful."
+
+
+test get_archive_sites_conf_values {
+    Get archive sites conf values unit test.
+} -setup {
+    file mkdir $pwd/archive_sites
+    set fd [open $pwd/archive_sites/archive_sites.conf w+]
+    puts $fd "name fondu"
+    puts $fd "urls macports.org"
+    puts $fd "type tgz"
+    close $fd
+
+    set macports::autoconf::macports_conf_path $pwd/archive_sites
+
+} -body {
+    set res [macports::get_archive_sites_conf_values]
+    if {[lindex [split $res " "] 1] != "macports.org:nosubdir"} {
+       return "FAIL: name not set"
+    }
+    if {[lindex [split $res " "] 3] != "tgz"} {
+       return "FAIL: wrong type set"
+    }
+
+    set macports::archive_sites_conf_values {a b c}
+    if {[macports::get_archive_sites_conf_values] != {a b c}} {
+       return "FAIL: wrong  result for bad conf file"
+    }
+    return "Get archive sites conf values successful."
+
+} -cleanup {
+    file delete -force $pwd/archive_sites
+} -result "Get archive sites conf values successful."
+
+
+cleanupTests

Deleted: branches/new-help-system/base/src/macports1.0/tests/macports_dlist.tcl
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/macports_dlist.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/tests/macports_dlist.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,114 +0,0 @@
-#!/usr/bin/env tclsh
-# macports1.0/test_dlist.tcl
-# $Id$
-#
-# Copyright (c) 2007 The MacPorts Project
-# Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
-
-# Test suite for macports_dlist package.
-
-#lappend auto_path .
-#package require macports_dlist 1.0
-source macports_dlist.tcl
-
-puts ""
-puts "Testing ditem"
-
-puts -nonewline "Checking ditem_create... "
-if {[catch {ditem_create} ditem] || $ditem == ""} {
-	puts "failed: $ditem"
-} else {
-	puts "ok"
-}
-
-puts -nonewline "Checking ditem_key... "
-if {[catch {ditem_key $ditem provides "foo"} value] || $value != "foo"} {
-	puts "failed: $value"
-} else {
-	puts "ok"
-}
-
-puts -nonewline "Checking ditem_append... "
-if {[catch {ditem_append $ditem provides "bar"} value] || $value != {foo bar}} {
-	puts "failed: $value"
-} else {
-	puts "ok"
-}
-
-puts -nonewline "Checking ditem_contains... "
-set value2 ""
-if {[catch {ditem_contains $ditem provides "foo"} value] || $value != 1 ||
-	[catch {ditem_contains $ditem provides "zzz"} value2] || $value2 != 0} {
-	puts "failed: ${value}\n${value2}"
-} else {
-	puts "ok"
-}
-
-puts ""
-puts "Testing dlist"
-
-puts -nonewline "Checking dlist_search... "
-if {[catch {dlist_search [list $ditem] provides "bar"} value] || $value != $ditem} {
-	puts "failed: $value"
-} else {
-	puts "ok"
-}
-
-puts -nonewline "Checking dlist_has_pending... "
-if {[catch {dlist_has_pending [list $ditem] "foo"} value] || $value != 1} {
-	puts "failed: $value"
-} else {
-	puts "ok"
-}
-
-puts -nonewline "Checking dlist_count_unmet... "
-array set status [list foo 1 bar 0]
-if {[catch {dlist_count_unmet [list] status "foo"} value] || $value != 0 ||
-	[catch {dlist_count_unmet [list] status "bar"} value2] || $value2 != 1} {
-	puts "failed: ${value}\n${value2}"
-} else {
-	puts "ok"
-}
-
-# Replicate Shantonu's Bug #354 to test dlist functionality.
-# https://trac.macports.org/ticket/354
-# A depends on B, C.
-# B depends on C.
-# C has no dependencies.
-
-set A [ditem_create]
-ditem_key $A provides A
-ditem_append $A requires B
-ditem_append $A requires C
-
-set B [ditem_create]
-ditem_key $B provides B
-ditem_append $B requires C
-
-set C [ditem_create]
-ditem_key $C provides C
-
-array set status [list]
-puts -nonewline "Checking dlist_get_next... "
-if {[catch {dlist_get_next [list $A $B $C] status} value] || $value != $C} {
-	puts "failed: ${value}"
-} else {
-	puts "ok"
-}
-
-puts -nonewline "Checking dlist_eval... "
-proc handler {ditem} { puts -nonewline "[ditem_key $ditem provides] " }
-if {[catch {dlist_eval [list $A $B $C] {} handler} value] || $value != {}} {
-	puts "failed: ${value}"
-} else {
-	puts "ok"
-}
-
-puts -nonewline "Checking dlist_append_dependents... "
-if {[catch {dlist_append_dependents [list $A $B $C] $B {}} value] || $value != [list $B $C]} {
-	puts "failed: ${value}"
-} else {
-	puts "ok"
-}
-
-

Copied: branches/new-help-system/base/src/macports1.0/tests/macports_dlist.test (from rev 117083, trunk/base/src/macports1.0/tests/macports_dlist.test)
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/macports_dlist.test	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/tests/macports_dlist.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,266 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+source ../macports_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+# Debug options
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+source ../macports_dlist.tcl
+
+
+test dlist_match_multi {
+    Dlist match multi unit test.
+} -setup {
+    set mport [mportopen file://.]
+    set crit {
+       provides fondu
+       porturl file://.
+    }
+    set crit2 { provides fondu2 }
+
+} -body {
+    if {[dlist_match_multi $mport $crit] != $mport} {
+       return "FAIL: correct dlist not matched"
+    }
+    if {[dlist_match_multi $mport $crit2] != ""} {
+       return "FAIL: incorrect dlist matched"
+    }
+    return "dlist match successful."
+} -cleanup {
+    mportclose $mport
+} -result "dlist match successful."
+
+
+test dlist_search {
+    Dlist search unit test.
+} -setup {
+    set mport [mportopen file://.]
+} -body {
+    if {[dlist_search $mport provides fondu] != $mport} {
+       return "FAIL: matching item not found"
+    }
+    if {[dlist_search $mport provides fondu2] != ""} {
+       return "FAIL: wrong item detected"
+    }
+    return "dlist successful."
+} -cleanup {
+    mportclose $mport
+} -result "dlist successful."
+
+
+test dlist_delete {
+    Dlist delete unit test.
+} -setup {
+    set mport [mportopen file://.]
+    set dlist [list]
+    lappend dlist $mport
+} -body {
+    if {[dlist_delete dlist $mport] != ""} {
+       return "FAIL: cannot run dlist_delete"
+    }
+    if {$dlist != ""} {
+       return "FAIL: port not removed from list"
+    }
+    return "Dlist delete successful."
+} -cleanup {
+    mportclose $mport
+} -result "Dlist delete successful."
+
+
+test dlist_has_pending {
+    Dlist has pending unit test.
+} -setup {
+    set mport [mportopen file://.]
+} -body {
+    if {[dlist_has_pending $mport fondu] != 1} {
+       return "FAIL: not detected"
+    }
+    if {[dlist_has_pending $mport provides] != 0} {
+       return "FAIL: incorrect detected"
+    }
+    return "dlist pending successful."
+} -cleanup {
+    mportclose $mport
+} -result "dlist pending successful."
+
+
+test dlist_count_unmet {
+    Dlist count unmet unit test.
+} -setup {
+    set mport [mportopen file://.]
+    array set statusdict {
+       vara 0
+       varb 0
+       varc 1
+    }
+    set tokens {vara varb vard}
+} -body {
+    if {[dlist_count_unmet $mport statusdict $tokens] != 3} {
+       return "FAIL: wrong unmet number"
+    }
+    return "count unmet successful."
+} -cleanup {
+    mportclose $mport
+} -result "count unmet successful."
+
+
+# These just call the procs in macports_dlist namespace
+# test ditem_create
+# test ditem_delete
+# test ditem_key
+# test ditem_append
+# test ditem_append_unique
+# test ditem_contains
+
+
+test dlist_append_dependents {
+    Dlist append dependents unit test.
+} -setup {
+    set mport [mportopen file://.]
+    set result {fondu2}
+} -body {
+    if {[dlist_append_dependents $mport provides $result] != {fondu2 provides}} {
+       return "FAIL: wrong depends"
+    }
+    return "Append depends successful."
+} -cleanup {
+    mportclose $mport
+} -result "Append depends successful."
+
+
+test dlist_get_next {
+    Dlist get next unit test.
+} -setup {
+    set mport [mportopen file://.]
+    set dict {fondu}
+} -body {
+    if {[dlist_get_next $mport $dict] != $mport} {
+       return "FAIL: wrong dlist"
+    }
+    return "dlist get next successful."
+} -cleanup {
+    mportclose $mport
+} -result "dlist get next successful."
+
+
+test dlist_eval {
+    Dlist eval unit test.
+} -setup {
+    set mport [mportopen file://.]
+    proc cond {arg} {
+       if {[string match "ditem_*" $arg] != 0} {
+            return 0
+       } else {
+            return 1
+       }
+    }
+    proc handler {arg} {}
+} -body {
+    if {[dlist_eval $mport cond handler] != ""} {
+       return "FAIL: wrong value returned"
+    }
+    return "dlist eval successful."
+} -cleanup {
+    mportclose $mport
+} -result "dlist eval successful."
+
+
+test ditem_create {
+    Ditem create unit test.
+} -body {
+    set res [macports_dlist::ditem_create]
+    if {[string match "ditem_*" $res] == 0} {
+	return "FAIL: ditem not created"
+    }
+    if {[info exists macports_dlist::$res] != 1} {
+	return "FAIL: array not set"
+    }
+    return "Create ditem successful."
+} -result "Create ditem successful."
+
+
+test ditem_delete {
+    Ditem delete unit test.
+} -body {
+    set res [macports_dlist::ditem_create]
+    set res [macports_dlist::ditem_delete $res]
+    if {[info exists macports_dlist::$res] != 0} {
+	return "FAIL: array not deleted"
+    }
+    return "Ditem delete successful."
+} -result "Ditem delete successful."
+
+
+test ditem_key {
+    Ditem key unit test.
+} -setup {
+    set res [macports_dlist::ditem_create]
+    macports_dlist::ditem_key $res macports test
+} -body {
+    if {[array get macports_dlist::$res macports] != "macports test"} {
+	return "FAIL ditem key not set"
+    }
+    return "Ditem key successful."
+} -cleanup {
+    macports_dlist::ditem_delete $res
+} -result "Ditem key successful."
+
+
+test ditem_append {
+    Ditem append unit test.
+} -setup {
+    set res [macports_dlist::ditem_create]
+    macports_dlist::ditem_key $res macports test
+    macports_dlist::ditem_append $res macports test2
+} -body {
+    if {[array get macports_dlist::$res macports] != "macports {test test2}"} {
+	return "FAIL: ditem key not appended"
+    }
+    return "Ditem key append successful."
+} -cleanup {
+    macports_dlist::ditem_delete $res
+} -result "Ditem key append successful."
+
+
+test ditem_append_unique {
+    Ditem append unique unit test.
+} -setup {
+    set res [macports_dlist::ditem_create]
+    macports_dlist::ditem_key $res macports test
+    macports_dlist::ditem_append_unique $res macports test
+} -body {
+    if {[array get macports_dlist::$res macports] != "macports test"} {
+	return "FAIL: ditem key not unique"
+    }
+    return "Ditem append unique successful."
+} -cleanup {
+    macports_dlist::ditem_delete $res
+} -result "Ditem append unique successful."
+
+
+test ditem_contains {
+    Ditem contains unit test.
+} -setup {
+    set mport [mportopen file://.]
+} -body {
+    if {[ditem_contains $mport provides] != 1} {
+       return "FAIL: valid key not detected"
+    }
+    if {[ditem_contains $mport wants] != 0} {
+       return "FAIL: invalid key detected"
+    }
+    return "ditem contains successful."
+} -cleanup {
+    mportclose $mport
+} -result "ditem contains successful."
+
+
+cleanupTests

Deleted: branches/new-help-system/base/src/macports1.0/tests/macports_util.tcl
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/macports_util.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/macports1.0/tests/macports_util.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,476 +0,0 @@
-# test_util.tcl
-# $Id$
-#
-# Comprehensive test file for macports_util.tcl
-# Written by Kevin Ballard <eridius at macports.org>
-
-source ./macports_util.tcl
-
-array set options {t 0 w 0}
-
-set ::traceNest ""
-set ::traceSquelch 0
-set ::traceSquelchNest ""
-proc dotrace {args} {
-    global traceNest options
-    flush stdout
-    set command [lindex $args 0]
-    if {$options(w) > 0} {
-        # trim command to 1 line
-        if {[llength [set lines [split $command "\n"]]] > 1} {
-            set command "[lindex $lines 0] [ansi fg-blue]...[ansi reset]"
-        }
-    }
-    set op [lindex $args end]
-    switch $op {
-        enter { append traceNest "#" }
-        enterstep { append traceNest "+" }
-    }
-    switch $op {
-        enter {
-            puts stderr "[ansi fg-yellow inverse]$traceNest>[ansi reset] $command"
-            set ::traceSquelch 0
-        }
-        enterstep {
-            if {!$::traceSquelch} {
-                puts stderr "[ansi fg-yellow]$traceNest>[ansi reset] $command"
-                if {[llength [info procs [lindex [split $command] 0]]] > 0} {
-                    # it's a proc, lets start squelching
-                    set ::traceSquelch 1
-                    set ::traceSquelchNest $::traceNest
-                }
-            }
-        }
-        leave -
-        leavestep {
-            if {$op eq "leavestep" && $::traceSquelch && $::traceNest eq $::traceSquelchNest} {
-                set ::traceSquelch 0
-            }
-            if {$op eq "leave" || !$::traceSquelch} {
-                set code [lindex $args 1]
-                set result [lindex $args 2]
-                if {$options(w) > 0} {
-                    # trim result just like command
-                    if {[llength [set lines [split $result "\n"]]] > 1} {
-                        set result "[lindex $lines 0] [ansi fg-blue]...[ansi reset]"
-                    }
-                }
-                if {$op eq "leave"} {
-                    set prefix "[ansi fg-blue inverse]$traceNest"
-                } else {
-                    set prefix "[ansi fg-blue]$traceNest"
-                }
-                if {$code != 0} {
-                    puts stderr "$prefix =\[$code\]>[ansi reset] $result"
-                } else {
-                    puts stderr "$prefix =>[ansi reset] $result"
-                }
-            }
-        }
-    }
-    switch $op {
-        leave -
-        leavestep {
-            set traceNest [string range $traceNest 0 end-1]
-        }
-    }
-}
-while {[llength $argv] > 0} {
-    set arg [lshift argv]
-    if {$arg eq "--"} {
-        break
-    } elseif {[string match -* $arg]} {
-        set arg [string range $arg 1 end]
-        while {[string length $arg] > 0} {
-            set opt [string index $arg 0]
-            set arg [string range $arg 1 end]
-            switch $opt {
-                t { incr options(t) }
-                w { incr options(w) }
-                default {
-                    error "Unknown option: -$opt"
-                }
-            }
-        }
-    } else {
-        lunshift argv $arg
-        break
-    }
-}
-if {$options(t) > 0} {
-    set ops {enter leave}
-    if {$options(t) > 1} {
-        lappend ops enterstep leavestep
-    }
-    set util_list {ldindex lpop lpush lshift lunshift try throw}
-    if {[llength $argv] > 0} {
-        set list $argv
-        if {[set idx [lsearch -exact $list *]] != -1} {
-            set list [eval lreplace [list $list] $idx $idx $util_list]
-        }
-    } else {
-        set list $util_list
-    }
-    foreach arg $list {
-        trace add execution $arg $ops dotrace
-    }
-}
-
-proc init {name value} {
-    set name [list $name]
-    set value [list $value]
-    uplevel 1 [subst -nocommands {
-        set $name $value
-        set $name-bak [set $name]
-    }]
-}
-
-proc restore {name} {
-    set name [list $name]
-    uplevel 1 [subst -nocommands {
-        if {[info exists $name-bak]} {
-            set $name [set $name-bak]
-        } else {
-            unset $name
-        }
-    }]
-}
-
-array set kStateToAnsiTable {
-    error fg-magenta
-    expected fg-cyan
-    correct fg-green
-    wrong fg-red
-}
-
-array set kAnsiTable {
-    reset           0
-    
-    bold            1
-    dim             2
-    underline       4
-    blink           5
-    inverse         7
-    hidden          8
-    
-    fg-black        30
-    fg-red          31
-    fg-green        32
-    fg-yellow       33
-    fg-blue         34
-    fg-magenta      35
-    fg-cyan         36
-    fg-white        37
-    fg-default      39
-    
-    bg-black        40
-    bg-red          41
-    bg-green        42
-    bg-yellow       43
-    bg-blue         44
-    bg-magenta      45
-    bg-cyan         46
-    bg-white        47
-    bg-default      49
-}
-
-proc ansi {args} {
-    global kAnsiTable
-    if {[llength $args] == 0} {
-        error "wrong # args: should be \"ansi code ...\""
-    }
-    set colors {}
-    foreach code $args {
-        lappend colors $kAnsiTable($code)
-    }
-    return "\033\[[join $colors ";"]m"
-}
-
-proc state {code} {
-    global kStateToAnsiTable
-    return [ansi $kStateToAnsiTable($code)]
-}
-
-proc line {cmd expected args} {
-    uplevel 1 [list block $cmd $cmd $expected] $args
-}
-
-proc block {name cmd expected args} {
-    if {[set err [catch {uplevel 1 $cmd} value]]} {
-        set savedErrorInfo $::errorInfo
-        set savedErrorCode $::errorCode
-        if {$expected eq "-error" && $err == 1} {
-            if {[llength $args] > 0} {
-                set errCode [lindex $args 0]
-                if {$errCode == $savedErrorCode} {
-                    if {[llength $args] > 1} {
-                        set errMsg [lindex $args 1]
-                        if {$errMsg == $value} {
-                            set code expected
-                        } else {
-                            set code error
-                        }
-                    } else {
-                        set code expected
-                    }
-                } else {
-                    set code error
-                }
-            } else {
-                set code expected
-            }
-        } elseif {$expected eq "-return" && $err == 2} {
-            if {[llength $args] > 0} {
-                set errMsg [lindex $args 0]
-                if {$errMsg == $value} {
-                    set code expected
-                } else {
-                    set code error
-                }
-            } else {
-                set code expected
-            }
-        } elseif {$expected eq "-break" && $err == 3} {
-            set code expected
-        } else {
-            set code error
-        }
-    } elseif {$value == $expected} {
-        set code correct
-    } else {
-        set code wrong
-    }
-    if {$code eq "error"} {
-        append value "\n$savedErrorInfo"
-    }
-    puts "[state $code]$name =[if {$err != 0} {format \[$err\]}]> $value[ansi reset]"
-}
-
-proc var {name expected} {
-    set exists [uplevel 1 info exists [list $name]]
-    if {!$exists} {
-        set value "does not exist"
-        if {$expected eq "-unset"} {
-            set code expected
-        } else {
-            set code error
-        }
-    } else {
-        set value [uplevel 1 set [list $name]]
-        if {$value == $expected} {
-            set code correct
-        } else {
-            set code wrong
-        }
-    }
-    puts "[state $code]$name: $value[ansi reset]"
-}
-
-if {[set err [catch {
-    namespace eval test {
-        namespace eval vars {}
-        init vars::ary(one) {1 2 {3 4}}
-        init vars::ary(zero) {1 {2 3 {"4 5" 6} 7} 8 9}
-        
-        var vars::ary(zero) {1 {2 3 {"4 5" 6} 7} 8 9}
-        line {ldindex vars::ary(zero) 1 2 0} {4 5}
-        var vars::ary(zero) {1 {2 3 6 7} 8 9}
-        line {ldindex vars::ary(zero) 1 1 0} 3
-        var vars::ary(zero) {1 {2 {} 6 7} 8 9}
-        line {ldindex vars::ary(zero) 1 2} 6
-        var vars::ary(zero) {1 {2 {} 7} 8 9}
-        line {ldindex vars::ary(zero) 1} {2 {} 7}
-        var vars::ary(zero) {1 8 9}
-        line {ldindex vars::ary(zero)} {1 8 9}
-        var vars::ary(zero) {}
-        
-        var vars::ary(one) {1 2 {3 4}}
-        line {lpop vars::ary(one)} {3 4}
-        var vars::ary(one) {1 2}
-        line {lpop vars::ary(one)} 2
-        var vars::ary(one) 1
-        line {lpop vars::ary(one)} 1
-        var vars::ary(one) {}
-        line {lpop vars::ary(one)} {}
-        var vars::ary(one) {}
-        
-        line {lpop vars::foo} -error NONE {can't read "vars::foo": no such variable}
-        
-        restore vars::ary(one)
-        var vars::ary(one) {1 2 {3 4}}
-        line {lshift vars::ary(one)} 1
-        var vars::ary(one) {2 {3 4}}
-        line {lshift vars::ary(one)} 2
-        var vars::ary(one) {{3 4}}
-        line {lshift vars::ary(one)} {3 4}
-        var vars::ary(one) {}
-        line {lshift vars::ary(one)} {}
-        var vars::ary(one) {}
-        
-        line {lshift vars::foo} -error NONE {can't read "vars::foo": no such variable}
-        
-        var vars::ary(two) -unset
-        line {lpush vars::ary(two) 1} 1
-        var vars::ary(two) 1
-        line {lpush vars::ary(two) 2 3 4 5} {1 2 3 4 5}
-        var vars::ary(two) {1 2 3 4 5}
-        line {lpush vars::ary(two) "this is a test"} {1 2 3 4 5 {this is a test}}
-        var vars::ary(two) {1 2 3 4 5 {this is a test}}
-        line {lpop vars::ary(two)} {this is a test}
-        var vars::ary(two) {1 2 3 4 5}
-        
-        line {lpush "foo bar" 3} {3}
-        var {foo bar} 3
-        
-        restore vars::ary(two)
-        var vars::ary(two) -unset
-        line {lunshift vars::ary(two) 5} 5
-        var vars::ary(two) 5
-        line {lunshift vars::ary(two) 4} {4 5}
-        var vars::ary(two) {4 5}
-        line {lunshift vars::ary(two) 1 2 3} {1 2 3 4 5}
-        var vars::ary(two) {1 2 3 4 5}
-        line {lunshift vars::ary(two) "this is a test"} {{this is a test} 1 2 3 4 5}
-        var vars::ary(two) {{this is a test} 1 2 3 4 5}
-        line {lshift vars::ary(two)} {this is a test}
-        var vars::ary(two) {1 2 3 4 5}
-        
-        # now test the try/throw stuff
-        line {throw} -error NONE {error: throw with no parameters outside of a catch}
-        line {throw 1 2 3 4} -error NONE {wrong # args: should be "throw ?type? ?message? ?info?"}
-        line {try {format 3} catch {} {}} -error NONE {invalid syntax in catch clause: type-list must contain at least one type}
-        line {try {format 3} finally {format 4} test} -error NONE {trailing args after finally clause}
-        block {basic try} {
-            try {
-                error "random error"
-            }
-        } -error NONE "random error"
-        block {try-finally} {
-            try {
-                error "try-finally error"
-            } finally {
-                set myVar "finally clause worked"
-            }
-        } -error NONE "try-finally error"
-        var myVar "finally clause worked"
-        block {try-finally-error} {
-            try {
-                error "try-finally error"
-            } finally {
-                error "finally error"
-            }
-        } -error NONE "finally error"
-        block {try-catch} {
-            try {
-                error "try-catch error"
-            } catch NONE {
-                format "catch clause worked"
-            }
-        } "catch clause worked"
-        block {try-catch-throw} {
-            try {
-                error "try-catch error"
-            } catch NONE {
-                set myVar "thrown"
-                throw
-            }
-        } -error NONE "try-catch error" ;# really should test errorInfo but that's messy
-        var myVar "thrown"
-        unset myVar
-        block {try-catch-finally} {
-            try {
-                error "try-catch-finally error"
-            } catch NONE {
-                set myVar "thrown"
-                throw
-            } finally {
-                lappend myVar "finally"
-            }
-        } -error NONE "try-catch-finally error"
-        var myVar "thrown finally"
-        block {try-catch-all} {
-            try {
-                error "this is a test"
-            } catch * {
-                format "catch-all worked"
-            }
-        } "catch-all worked"
-        block {try-catch-return} {
-            try {
-                error "this is a test"
-            } catch * {
-                return "catch-return worked"
-            }
-        } -return "catch-return worked"
-        block {try-catch-break} {
-            try {
-                error "this is a test"
-            } catch * {
-                break
-            }
-        } -break
-        block {try-catch-multiple} {
-            try {
-                error "this is a test"
-            } catch POSIX {
-                error "POSIX catch"
-            } catch * {
-                format "catch-all"
-            }
-        } "catch-all"
-        unset myVar
-        block {try-catch-multiple-finally} {
-            try {
-                error "this is a test"
-            } catch * {
-                lappend myVar "catch-all 1"
-            } catch * {
-                lappend myVar "catch-all 2"
-            } finally {
-                lappend myVar "finally"
-            }
-        } [list {catch-all 1}]
-        var myVar [list "catch-all 1" "finally"]
-        block {try-catch-types} {
-            try {
-                error "try-catch-types error" {} {MYERR arg1 arg2}
-            } catch POSIX {
-                error "POSIX catch"
-            } catch {{MY* arg*} code} {
-                format "caught code $code"
-            }
-        } "caught code MYERR arg1 arg2"
-        block {try-catch-vars} {
-            try {
-                error "random error"
-            } catch {* code msg info} {
-                set list {}
-                if {$code eq "NONE"} {
-                    lappend list "code: correct"
-                }
-                if {$msg eq "random error"} {
-                    lappend list "msg: correct"
-                }
-                if {[string match "random error\n*" $info]} {
-                    lappend list "info: probably correct"
-                }
-                join $list ", "
-            }
-        } "code: correct, msg: correct, info: probably correct"
-        block {try-break-catch} {
-            try {
-                break
-            } catch {*} {
-                error "catch triggered"
-            }
-        } -break
-        
-        # ensure the stack is sound
-        var ::_trycatch::catchStack {}
-    }
-} result]]} {
-    puts ""
-    puts "error: $result"
-    puts "code: $err"
-    puts $::errorInfo
-}

Copied: branches/new-help-system/base/src/macports1.0/tests/macports_util.test (from rev 117083, trunk/base/src/macports1.0/tests/macports_util.test)
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/macports_util.test	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/tests/macports_util.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,163 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+source ../macports_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+
+test method_wrap {
+    Method wrap unit test.
+} -setup {
+    proc test_proc {a} {
+       if { $a == 1} {
+           return -code error $a -errorcode 7
+       } else {
+            return $a
+       }
+    }
+
+} -body {
+    macports_util::method_wrap test_proc
+    if {[test_proc 1] != 7} {
+       return "FAIL: no wrap around method"
+    }
+    if {[test_proc arg] != "arg"} {
+       return "FAIL: no wrap around method"
+    }
+    return "Method wrap successful."
+} -result "Method wrap successful."
+
+
+test ldindex {
+    Ldindex unit test.
+} -body {
+    set list {0 1 2 3}
+    if {[ldindex list 1] != 1} {
+       return "FAIL: element not poped"
+    }
+    if {$list != {0 2 3}} {
+       return "FAIL: wrong list remaining"
+    }
+    if {[catch {ldindex list 4}] != 1} {
+       return "FAIL: error not detected"
+    }
+    if {[ldindex list] != {0 2 3}} {
+       return "FAIL: not all elements poped"
+    }
+    if {$list != ""} {
+       return "FAIL: list not emptied"
+    }
+    return "ldindex successful."
+} -result "ldindex successful."
+
+
+test lpop {
+    Lpop unit test.
+} -body {
+    set list {0 1 2}
+    if {[lpop list] != 2} {
+       return "FAIL: element not poped"
+    }
+    if {$list != {0 1}} {
+       return "FAIL: wrong element poped"
+    }
+    return "lpop successful."
+} -result "lpop successful."
+
+
+test lpush {
+    Lpush unit test.
+} -body {
+    set list {0 1}
+    if {[lpush list 2] != {0 1 2}} {
+       return "FAIL: element not appended"
+    }
+    if {[lpush list 3 4] != {0 1 2 3 4}} {
+       return "FAIL: multiple elements not appended"
+    }
+    if {[lpush list1 0] != 0} {
+       return "FAIL: list not created"
+    }
+    return "lpop successful."
+} -result "lpop successful."
+
+
+test lshift {
+    Lshift unit test.
+} -body {
+    set list {0 1 2}
+    set list1 {}
+
+    if {[lshift list] != 0} {
+       return "FAIL: wrong element poped"
+    }
+    if {$list != {1 2}} {
+       return "FAIL: wrong list remaining"
+    }
+    if {[lshift list1] != ""} {
+       return "FAIL: empty list not detected"
+    }
+    return "lshift successful."
+} -result "lshift successful."
+
+
+test lunshift {
+    Lunshift unit test.
+} -body {
+    set list {3 4}
+
+    if {[lunshift list 2] != {2 3 4}} {
+       return "FAIL: element not inserted"
+    }
+    if {[lunshift list 0 1] != {0 1 2 3 4}} {
+       return "FAIL: multiple elements not inserted"
+    }
+    if {[lunshift list2 0] != 0} {
+       return "FAIL: list not created"
+    }
+    return "lunshift successful."
+} -result "lunshift successful."
+
+
+
+test throw {
+    Throw unit test.
+} -setup {
+    proc test_proc {arg} {
+       catch {throw $arg} res
+       return $res
+    }
+} -body {
+    if {[test_proc {7 msg info}] != "error: 7 msg info"} {
+       return "FAIL: wrong error returneed"
+    }
+    if {[catch {test_proc ""}] != 0} {
+       return "FAIL: wrong value returned"
+    }
+    return "throw successful."
+} -result "throw successful."
+
+
+test try {
+    Try unit test.
+} -setup {
+    proc test_proc {} {try {return 7} catch * {return 6}}
+    proc test_proc2 {} {try {error "msg" "info" 3} catch * {return 6}}
+} -body {
+    if {[test_proc] != 7} {
+       return "FAIL: try clause not working"
+    }
+    if {[test_proc2] != 6} {
+       reutrn "FAIL: catch clause not working"
+    }
+    if {[catch {try}] != 1} {
+       return "FAIL: no args err not detected"
+    }
+    return "try successful."
+} -result "try successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/macports1.0/tests/sources.conf (from rev 117083, trunk/base/src/macports1.0/tests/sources.conf)
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/sources.conf	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/tests/sources.conf	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,28 @@
+# $Id$
+# MacPorts system-wide configuration file for ports tree sources.
+#
+# To change how MacPorts fetches base, see rsync_server and rsync_dir in
+# macports.conf.
+# To add a local source, add a "file://" entry.
+#
+#   Example: file:///Users/landonf/misc/MacPorts/ports
+#
+# To prevent a source from synchronizing when `port sync` is used,
+# append "[nosync]" at the end.
+#
+#   Example: file:///Users/landonf/misc/MacPorts/ports [nosync]
+#
+# Note that MacPorts parses source URLs in order; when a port appears in
+# multiple sources, it installs the first occurrence. For local sources
+# to shadow remote ones, "file://" URLs must come before other URLs.
+# A list of rsync mirrors is available at
+# https://trac.macports.org/wiki/Mirrors#Portfiles.
+#
+# If an "rsync://" URL points to a .tar file, a signed .rmd160 file must
+# exist in the same directory on the server and will be used to verify
+# its integrity.
+#
+# For proper functionality of various resources (port groups, mirror
+# sites, etc.), the primary MacPorts source must always be tagged
+# "[default]", even if switched from the default "rsync://" URL.
+rsync://rsync.macports.org/release/tarballs/ports.tar [default]

Copied: branches/new-help-system/base/src/macports1.0/tests/test.tcl (from rev 117083, trunk/base/src/macports1.0/tests/test.tcl)
===================================================================
--- branches/new-help-system/base/src/macports1.0/tests/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/src/macports1.0/tests/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,131 @@
+# Global vars
+set arguments ""
+set test_name ""
+set color_out ""
+set tcl ""
+set err ""
+
+# Get tclsh path.
+set autoconf ../../Mk/macports.autoconf.mk
+set fp [open $autoconf r]
+while {[gets $fp line] != -1} {
+    if {[string match "TCLSH*" $line] != 0} {
+        set tcl [lrange [split $line " "] 1 1]
+    }
+}
+
+proc print_help {arg} {
+    if { $arg eq "tests" } {
+        puts "The list of available tests is:"
+	cd tests
+	set test_suite [glob *.test]
+        foreach test $test_suite {
+            puts [puts -nonewline "  "]$test
+        }
+    } else {
+        puts "Usage: tclsh test.tcl \[-debug level\] \[-t test\] \[-l\]\n"
+        puts "  -debug LVL : sets the level of printed debug info \[0-3\]"
+        puts "  -t TEST    : run a specific test"
+        puts "  -nocolor   : disable color output (for automatic testing)"
+        puts "  -l         : print the list of available tests"
+        puts "  -h, -help  : print this message\n"
+    }
+}
+
+# Process args
+foreach arg $argv {
+    if { $arg eq "-h" || $arg eq "-help" } {
+        print_help ""
+        exit 0
+    } elseif { $arg eq "-debug" } {
+        set index [expr {[lsearch $argv $arg] + 1}]
+        set level [lindex $argv $index]
+        if { $level >= 0 && $level <= 3 } {
+            append arguments "-debug " $level
+        } else {
+            puts "Invalid debug level."
+            exit 1
+        }
+    } elseif { $arg eq "-t" } {
+        set index [expr {[lsearch $argv $arg] + 1}]
+        set test_name [lindex $argv $index]
+        set no 0
+	cd tests
+	set test_suite [glob *.test]
+        foreach test $test_suite {
+            if { $test_name != $test } {
+                set no [expr {$no + 1}]
+            }
+        }
+        if { $no == [llength $test_suite] } {
+            print_help tests
+            exit 1
+        }
+    } elseif { $arg eq "-l" } {
+        print_help tests
+        exit 0
+    } elseif { $arg eq "-nocolor" } {
+        set color_out "no"
+    }
+}
+
+
+# Run tests
+if { $test_name ne ""} {
+    set result [eval exec $tcl $test_name $arguments 2>@stderr]
+    puts $result
+
+} else {
+    cd tests
+    set test_suite [glob *.test]
+
+    foreach test $test_suite {
+        set result [eval exec $tcl $test $arguments 2>@stderr]
+	set lastline [lindex [split $result "\n"] end]
+
+	if {[lrange [split $lastline "\t"] 1 1] != "Total"} {
+	    set lastline [lindex [split $result "\n"] end-2]
+	    set errmsg [lindex [split $result "\n"] end]
+	}
+
+	set splitresult [split $lastline "\t"]
+        set total [lindex $splitresult 2]
+        set pass [lindex $splitresult 4]
+        set skip [lindex $splitresult 6]
+        set fail [lindex $splitresult 8]
+
+	# Format output
+	if {$total < 10} { set total "0${total}"}
+	if {$pass < 10} { set pass "0${pass}"}
+	if {$skip < 10} { set skip "0${skip}"}
+	if {$fail < 10} { set fail "0${fail}"}
+
+        # Check for errors.
+        if { $fail != 0 } { set err "yes" }
+
+        set out ""
+        if { ($fail != 0 || $skip != 0) && $color_out eq "" } {
+            # Color failed tests.
+            append out "\x1b\[1;31mTotal:" $total " Passed:" $pass " Failed:" $fail " Skipped:" $skip "  \x1b\[0m" $test
+        } else {
+            append out "Total:" $total " Passed:" $pass " Failed:" $fail " Skipped:" $skip "  " $test
+        }
+
+        # Print results and constrints for auto-skipped tests.
+        puts $out
+        if { $skip != 0 } {
+            set out "    Constraint: "
+            append out [string trim $errmsg "\t {}"]
+            puts $out
+        }
+	if { $fail != 0 } {
+	    set end [expr {[string first $test $result 0] - 1}]
+	    puts [string range $result 0 $end]
+	}
+    }
+}
+
+# Return 1 if errors were found.
+if {$err ne ""} { exit 1 }
+
+return 0


Property changes on: branches/new-help-system/base/src/package1.0
___________________________________________________________________
Modified: svn:ignore
   - pkgIndex.tcl

   + pkgIndex.tcl
package_test_autoconf.tcl


Modified: branches/new-help-system/base/src/package1.0/Makefile
===================================================================
--- branches/new-help-system/base/src/package1.0/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -15,8 +15,11 @@
 	rm -f pkgIndex.tcl
 
 distclean:: clean
+	rm -f package_test_autoconf.tcl
 
 test::
+	-$(prefix)/bin/port sync
+	$(TCLSH) ./tests/test.tcl -nocolor
 
 install:: all
 	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} ${INSTALLDIR}

Copied: branches/new-help-system/base/src/package1.0/package_test_autoconf.tcl.in (from rev 117083, trunk/base/src/package1.0/package_test_autoconf.tcl.in)
===================================================================
--- branches/new-help-system/base/src/package1.0/package_test_autoconf.tcl.in	                        (rev 0)
+++ branches/new-help-system/base/src/package1.0/package_test_autoconf.tcl.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,41 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
+# macports-autoconf.tcl.in
+# $Id: macports_autoconf.tcl.in 90070 2012-02-20 21:54:35Z jberry at macports.org $
+#
+# Copyright (c) 2006 - 2009, 2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Apple Inc. nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+namespace eval macports::autoconf {
+    variable macports_tcl_dir "@macports_tcl_dir@"
+    variable prefix "@prefix@"
+}
+
+namespace eval portutil::autoconf {
+    variable hdiutil_path "@HDIUTIL@"
+}

Modified: branches/new-help-system/base/src/package1.0/portarchivefetch.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portarchivefetch.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portarchivefetch.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -104,7 +104,7 @@
     }
 
     # check if porturl itself points to an archive
-    if {[file rootname [file tail $porturl]] == [file rootname [get_portimage_name]] && [file extension $porturl] != ""} {
+    if {[file rootname [file tail $porturl]] eq [file rootname [get_portimage_name]] && [file extension $porturl] ne ""} {
         lappend ret [string range $porturl 0 end-[string length [file tail $porturl]]]:[string range [file extension $porturl] 1 end]
         archive.subdir
     }
@@ -186,15 +186,19 @@
     if {${archivefetch.ignore_sslcert} != "no"} {
         lappend fetch_options "--ignore-ssl-cert"
     }
-    if {$portverbose == "yes"} {
-        lappend fetch_options "-v"
+    if {$portverbose eq "yes"} {
+        lappend fetch_options "--progress"
+        lappend fetch_options "builtin"
+    } elseif {[llength [info commands ui_progress_download]] > 0} {
+        lappend fetch_options "--progress"
+        lappend fetch_options "ui_progress_download"
     }
     set sorted no
 
     set existing_archive [find_portarchive_path]
 
     foreach {url_var archive} $archivefetch_urls {
-        if {![file isfile ${archivefetch.fulldestpath}/${archive}] && $existing_archive == ""} {
+        if {![file isfile ${archivefetch.fulldestpath}/${archive}] && $existing_archive eq ""} {
             ui_info "$UI_PREFIX [format [msgcat::mc "%s doesn't seem to exist in %s"] $archive ${archivefetch.fulldestpath}]"
             if {![file writable ${archivefetch.fulldestpath}]} {
                 return -code error [format [msgcat::mc "%s must be writable"] ${archivefetch.fulldestpath}]
@@ -213,7 +217,7 @@
             set failed_sites 0
             unset -nocomplain fetched
             foreach site $urlmap($url_var) {
-                if {[string index $site end] != "/"} {
+                if {[string index $site end] ne "/"} {
                     append site "/[option archive.subdir]"
                 } else {
                     append site [option archive.subdir]
@@ -280,7 +284,7 @@
         }
         return 0
     }
-    if {[info exists ports_binary_only] && $ports_binary_only == "yes"} {
+    if {[info exists ports_binary_only] && $ports_binary_only eq "yes"} {
         return -code error "archivefetch failed for [option subport] @[option version]_[option revision][option portvariants]"
     } else {
         return 0

Modified: branches/new-help-system/base/src/package1.0/portdmg.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portdmg.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portdmg.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -91,13 +91,13 @@
     }
 
     set hdiutil [findBinary hdiutil $portutil::autoconf::hdiutil_path]
-    if {[system "$hdiutil create -quiet -fs HFS+ -volname ${imagename} -srcfolder ${pkgpath} ${tmp_image}"] != ""} {
+    if {[system "$hdiutil create -quiet -fs HFS+ -volname ${imagename} -srcfolder ${pkgpath} ${tmp_image}"] ne ""} {
         return -code error [format [msgcat::mc "Failed to create temporary image: %s"] ${imagename}]
     }
-    if {[system "$hdiutil convert ${tmp_image} -format UDCO -o ${final_image} -quiet"] != ""} {
+    if {[system "$hdiutil convert ${tmp_image} -format UDCO -o ${final_image} -quiet"] ne ""} {
         return -code error [format [msgcat::mc "Failed to convert to final image: %s"] ${final_image}]
     }
-    if {[system "$hdiutil internet-enable -quiet -yes ${final_image}"] != ""} {
+    if {[system "$hdiutil internet-enable -quiet -yes ${final_image}"] ne ""} {
         return -code error [format [msgcat::mc "Failed to internet-enable: %s"] ${final_image}]
     }
     file delete -force "${tmp_image}"

Modified: branches/new-help-system/base/src/package1.0/portdpkg.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portdpkg.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portdpkg.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -87,7 +87,7 @@
 	set controlfd [open [file join ${controlpath} control] w+]
 
 	# Size, in kilobytes, of ${destpath}
-   	set pkg_installed-size [expr [dirSize ${destpath}] / 1024]
+   	set pkg_installed-size [expr {[dirSize ${destpath}] / 1024}]
 
 	# Create debian dependency list
 	if {[info exists dependencies]} {
@@ -97,12 +97,12 @@
 	}
 
 	# Create dpkg version number
-	if {[expr [option epoch] != 0]} {
+	if {[option epoch] != 0} {
 		set pkg_version "[option epoch]:[option version]"
 	} else {
 		set pkg_version "[option version]"
 	}
-	if {[expr [option revision] != 0]} {
+	if {[option revision] != 0} {
 		append pkg_version "-[option revision]"
 	}
 
@@ -146,7 +146,7 @@
 	}
 
 	# An architecture-independent package
-	if {$supported_archs == "noarch"} {
+	if {$supported_archs eq "noarch"} {
 		set pkg_arch "all"
 	}
 

Modified: branches/new-help-system/base/src/package1.0/portmdmg.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portmdmg.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portmdmg.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -91,13 +91,13 @@
     }
 
     set hdiutil [findBinary hdiutil $portutil::autoconf::hdiutil_path]
-    if {[system "$hdiutil create -quiet -fs HFS+ -volname ${imagename} -srcfolder ${mpkgpath} ${tmp_image}"] != ""} {
+    if {[system "$hdiutil create -quiet -fs HFS+ -volname ${imagename} -srcfolder ${mpkgpath} ${tmp_image}"] ne ""} {
         return -code error [format [msgcat::mc "Failed to create temporary image: %s"] ${imagename}]
     }
-    if {[system "$hdiutil convert ${tmp_image} -format UDCO -o ${final_image} -quiet"] != ""} {
+    if {[system "$hdiutil convert ${tmp_image} -format UDCO -o ${final_image} -quiet"] ne ""} {
         return -code error [format [msgcat::mc "Failed to convert to final image: %s"] ${final_image}]
     }
-    if {[system "$hdiutil internet-enable -quiet -yes ${final_image}"] != ""} {
+    if {[system "$hdiutil internet-enable -quiet -yes ${final_image}"] ne ""} {
         return -code error [format [msgcat::mc "Failed to internet-enable: %s"] ${final_image}]
     }
     file delete -force "${tmp_image}"

Modified: branches/new-help-system/base/src/package1.0/portmpkg.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portmpkg.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portmpkg.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -91,7 +91,7 @@
 
     foreach depspec $depends {
         set dep [_get_dep_port $depspec]
-        if {$dep != ""} {
+        if {$dep ne ""} {
             eval "lappend result [make_dependency_list $dep $destination]"
         }
     }
@@ -122,7 +122,7 @@
 
 proc portmpkg::epoch_namestr {portepoch} {
     set portepoch_namestr ""
-    if {${portepoch} != "0"} {
+    if {${portepoch} != 0} {
         set portepoch_namestr "${portepoch}_"
     }
     return ${portepoch_namestr}
@@ -130,7 +130,7 @@
 
 proc portmpkg::revision_namestr {portrevision} {
     set portrevision_namestr ""
-    if {${portrevision} != "0"} {
+    if {${portrevision} != 0} {
         set portrevision_namestr "_${portrevision}"
     }
     return ${portrevision_namestr}
@@ -171,13 +171,13 @@
         set name [lindex $dep 0]
         set epoch [lindex $dep 1]
         set epoch_namestr ""
-        if {$epoch != "0"} {
+        if {$epoch != 0} {
             set epoch_namestr "${epoch}_"
         }
         set vers [lindex $dep 2]
         set rev [lindex $dep 3]
         set rev_namestr ""
-        if {$rev != "0"} {
+        if {$rev != 0} {
             set rev_namestr "_${rev}"
         }
         set mport [lindex $dep 4]
@@ -272,7 +272,7 @@
 proc portmpkg::mpkg_write_info_plist {infofile portname portversion portrevision destination dependencies} {
     set vers [split $portversion "."]
 
-    if {[string index $destination end] != "/"} {
+    if {[string index $destination end] ne "/"} {
         append destination /
     }
 

Modified: branches/new-help-system/base/src/package1.0/portpkg.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portpkg.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portpkg.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -51,7 +51,7 @@
 default package.resources {${workpath}/pkg_resources}
 default package.scripts  {${workpath}/pkg_scripts}
 # Need productbuild to make flat packages really work
-default package.flat     {[expr [vercmp $macosx_deployment_target 10.6] >= 0]}
+default package.flat     {[expr {[vercmp $macosx_deployment_target 10.6] >= 0}]}
 
 set_ui_prefix
 
@@ -113,11 +113,11 @@
     pkg_post_unarchive_deletions portpkg::language
 
     set portepoch_namestr ""
-    if {${portepoch} != "0"} {
+    if {${portepoch} != 0} {
         set portepoch_namestr "${portepoch}_"
     }
     set portrevision_namestr ""
-    if {${portrevision} != "0"} {
+    if {${portrevision} != 0} {
         set portrevision_namestr "_${portrevision}"
     }
 
@@ -314,12 +314,12 @@
 
 proc portpkg::write_welcome_html {filename portname portepoch portversion portrevision long_description description homepage} {
     set fd [open ${filename} w+]
-    if {$long_description == ""} {
+    if {$long_description eq ""} {
         set long_description $description
     }
 
     set portname [xml_escape $portname]
-    if {$portepoch != "0"} {
+    if {$portepoch != 0} {
         set portepoch [xml_escape $portepoch]
         set portepoch_str "${portepoch}_"
     } else {
@@ -327,7 +327,7 @@
         set portepoch_str ""
     }
     set portversion [xml_escape $portversion]
-    if {$portrevision != "0"} {
+    if {$portrevision != 0} {
         set portrevision [xml_escape $portrevision]
         set portrevision_str "_${portrevision}"
     } else {
@@ -350,7 +350,7 @@
 <font face=\"Helvetica\">${long_description}</font>
 <p>"
 
-    if {$homepage != ""} {
+    if {$homepage ne ""} {
         puts $fd "<font face=\"Helvetica\"><a href=\"${homepage}\">${homepage}</a></font><p>"
     }
 
@@ -366,10 +366,10 @@
     if {[catch {set numFiles [llength [split [exec [findBinary lsbom $portutil::autoconf::lsbom_path] -s ${pkgpath}/Contents/Archive.bom] "\n"]]} result]} {
         return -code error [format [msgcat::mc "Reading package bom failed: %s"] $result]
     }
-    if {[catch {set compressedSize [expr [dirSize ${pkgpath}] / 1024]} result]} {
+    if {[catch {set compressedSize [expr {[dirSize ${pkgpath}] / 1024}]} result]} {
         return -code error [format [msgcat::mc "Error determining compressed size: %s"] $result]
     }
-    if {[catch {set installedSize [expr [dirSize ${destpath}] / 1024]} result]} {
+    if {[catch {set installedSize [expr {[dirSize ${destpath}] / 1024}]} result]} {
         return -code error [format [msgcat::mc "Error determining installed size: %s"] $result]
     }
     if {[catch {set infoSize [file size ${pkgpath}/Contents/Info.plist]} result]} {
@@ -399,7 +399,7 @@
 proc portpkg::write_distribution {dfile portname portepoch portversion portrevision} {
     global macosx_deployment_target
     set portname [xml_escape $portname]
-    if {$portepoch != "0"} {
+    if {$portepoch != 0} {
         set portepoch [xml_escape $portepoch]
         set portepoch_str "${portepoch}_"
     } else {
@@ -407,7 +407,7 @@
         set portepoch_str ""
     }
     set portversion [xml_escape $portversion]
-    if {$portrevision != "0"} {
+    if {$portrevision != 0} {
         set portrevision [xml_escape $portrevision]
         set portrevision_str "_${portrevision}"
     } else {
@@ -503,11 +503,11 @@
             # subtracted, otherwise subtract 'a'.  Add 1 to the value
             # so that 'a' and 'A' are mapped to 1, not 0.
             if {$ord < $ord_a} {
-                set j [expr $ord - $ord_A + 1]
+                set j [expr {$ord - $ord_A + 1}]
             } else {
-                set j [expr $ord - $ord_a + 1]
+                set j [expr {$ord - $ord_a + 1}]
             }
-            set i [expr 26*$i + $j]
+            set i [expr {26*$i + $j}]
         }
         lappend vs $i
     }

Modified: branches/new-help-system/base/src/package1.0/portrpm.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portrpm.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portrpm.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -81,7 +81,7 @@
     }
 
     set rpmbuildarch ""
-    if {$supported_archs == "noarch"} {
+    if {$supported_archs eq "noarch"} {
         set rpmbuildarch "--target noarch"
     } elseif {[variant_exists universal] && [variant_isset universal]} {
         set rpmbuildarch "--target fat"
@@ -227,7 +227,7 @@
 URL: ${homepage}
 BuildRoot: ${destroot}
 AutoReq: no"
-    if {[expr ${epoch} != 0]} {
+    if {$epoch != 0} {
 	    puts $specfd "Epoch: ${epoch}"
     }
     if {[llength ${dependencies}] != 0} {

Modified: branches/new-help-system/base/src/package1.0/portsrpm.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portsrpm.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portsrpm.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -224,10 +224,10 @@
 URL: ${homepage}
 BuildRoot: %{_tmppath}/%{name}-%{version}-root
 Source0: ${portname}-Portfile"
-    if {$zip != ""} {
+    if {$zip ne ""} {
         puts $specfd "Source1: $zip"
     }
-    if {[expr ${epoch} != 0]} {
+    if {$epoch != 0} {
 	    puts $specfd "Epoch: ${epoch}"
     }
     set first 2
@@ -238,7 +238,7 @@
         puts -nonewline $specfd "Source${count}: "
         if {![info exists $fetch_urls]} {
         foreach {url_var distfile}  ${fetch_urls} {
-            if {[string equal $distfile $file]} {
+            if {$distfile eq $file} {
                  global portfetch::$url_var master_sites
                  set site [lindex [set $url_var] 0]
                  set file [portfetch::assemble_url $site $distfile]
@@ -259,7 +259,7 @@
 	}
     }
     set wrap_description [word_wrap ${long_description} 72]
-    if {$zip != ""} {
+    if {$zip ne ""} {
         set and "-a 1"
     } else {
         set and ""

Modified: branches/new-help-system/base/src/package1.0/portunarchive.tcl
===================================================================
--- branches/new-help-system/base/src/package1.0/portunarchive.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/package1.0/portunarchive.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -71,14 +71,14 @@
     set skipped 0
     if {[check_statefile target org.macports.unarchive $target_state_fd]} {
         return 0
-    } elseif {[info exists ports_source_only] && $ports_source_only == "yes"} {
+    } elseif {[info exists ports_source_only] && $ports_source_only eq "yes"} {
         ui_debug "Skipping unarchive ($subport) since source-only is set"
         set skipped 1
     } elseif {[check_statefile target org.macports.destroot $target_state_fd]
               && [file isdirectory $destroot]} {
         ui_debug "Skipping unarchive ($subport) since destroot completed"
         set skipped 1
-    } elseif {[info exists ports_force] && $ports_force == "yes"} {
+    } elseif {[info exists ports_force] && $ports_force eq "yes"} {
         ui_debug "Skipping unarchive ($subport) since force is set"
         set skipped 1
     } else {
@@ -88,7 +88,7 @@
         if {${unarchive.path} != ""} {
             ui_debug "Found [string toupper ${unarchive.type}] archive: ${unarchive.path}"
         } else {
-            if {[info exists ports_binary_only] && $ports_binary_only == "yes"} {
+            if {[info exists ports_binary_only] && $ports_binary_only eq "yes"} {
                 return -code error "Archive for ${subport} ${version}_${revision}${portvariants} not found, required when binary-only is set!"
             } else {
                 ui_debug "Skipping unarchive ($subport) since no suitable archive found"

Modified: branches/new-help-system/base/src/pextlib1.0/Makefile.in
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/Makefile.in	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/Makefile.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -32,3 +32,6 @@
 	${TCLSH} tests/symlink.tcl ./${SHLIB_NAME}
 	${TCLSH} tests/unsetenv.tcl ./${SHLIB_NAME}
 	${TCLSH} tests/vercomp.tcl ./${SHLIB_NAME}
+
+distclean::
+	rm -f Makefile


Property changes on: branches/new-help-system/base/src/pextlib1.0/Makefile.in
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/Makefile:37343-46937
/branches/gsoc08-privileges/base/src/pextlib1.0/Makefile.in:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/Makefile:51231-60371
/branches/gsoc09-logging/base/src/pextlib1.0/Makefile.in:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/Makefile:78828-88375
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/Makefile.in:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/Makefile:51872-52323
/branches/universal-sanity/base/src/pextlib1.0/Makefile.in:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/Makefile:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/branches/variant-descs-14482/base/src/pextlib1.0/Makefile.in:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/Makefile.in:49341-104698,108155-110831
/users/perry/base-bugs_and_notes/src/pextlib1.0/Makefile:45682-46060
/users/perry/base-bugs_and_notes/src/pextlib1.0/Makefile.in:45682-46060
/users/perry/base-select/src/pextlib1.0/Makefile:44044-44692
/users/perry/base-select/src/pextlib1.0/Makefile.in:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/Makefile:37343-46937
/branches/gsoc08-privileges/base/src/pextlib1.0/Makefile.in:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/Makefile:51231-60371
/branches/gsoc09-logging/base/src/pextlib1.0/Makefile.in:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/Makefile:78828-88375
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/Makefile.in:78828-88375
/branches/gsoc13-tests/src/pextlib1.0/Makefile.in:106692-111324
/branches/universal-sanity/base/src/pextlib1.0/Makefile:51872-52323
/branches/universal-sanity/base/src/pextlib1.0/Makefile.in:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/Makefile:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/branches/variant-descs-14482/base/src/pextlib1.0/Makefile.in:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/Makefile.in:49341-104698,108155-117083
/users/perry/base-bugs_and_notes/src/pextlib1.0/Makefile:45682-46060
/users/perry/base-bugs_and_notes/src/pextlib1.0/Makefile.in:45682-46060
/users/perry/base-select/src/pextlib1.0/Makefile:44044-44692
/users/perry/base-select/src/pextlib1.0/Makefile.in:44044-44692

Modified: branches/new-help-system/base/src/pextlib1.0/Pextlib.c
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/Pextlib.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/Pextlib.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -203,7 +203,7 @@
 
     user = strdup(Tcl_GetString(objv[1]));
     if (isdigit(*(user)))
-        pwent = getpwuid(strtol(user, 0, 0));
+        pwent = getpwuid((uid_t)strtol(user, 0, 0));
     else
         pwent = getpwnam(user);
     free(user);
@@ -230,7 +230,7 @@
 
     group = strdup(Tcl_GetString(objv[1]));
     if (isdigit(*(group)))
-        grent = getgrgid(strtol(group, 0, 0));
+        grent = getgrgid((gid_t)strtol(group, 0, 0));
     else
         grent = getgrnam(group);
     free(group);
@@ -254,7 +254,7 @@
 
     cur = MIN_USABLE_UID;
 
-    while (getpwuid(cur) != NULL) {
+    while (getpwuid((uid_t)cur) != NULL) {
         cur++;
     }
 
@@ -271,7 +271,7 @@
 
     cur = MIN_USABLE_GID;
 
-    while (getgrgid(cur) != NULL) {
+    while (getgrgid((gid_t)cur) != NULL) {
         cur++;
     }
 
@@ -280,7 +280,7 @@
     return TCL_OK;
 }
 
-int UmaskCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED)
+int UmaskCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
     Tcl_Obj *tcl_result;
     char *tcl_mask, *p;
@@ -392,7 +392,7 @@
         for (envp = environ; *envp != NULL; envp++) {
             equals = strchr(*envp, '=');
             if (equals != NULL) {
-                len = equals - *envp;
+                len = (size_t)(equals - *envp);
                 Tcl_ListObjAppendElement(interp, tclList, Tcl_NewStringObj(*envp, len));
             }
         }

Modified: branches/new-help-system/base/src/pextlib1.0/curl.c
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/curl.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/curl.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -51,11 +51,12 @@
 
 /*
  * Some compiled-in constants that we may wish to change later, given more
- * empirical data.  These represent "best guess" values for now.
+ * empirical data. These represent "best guess" values for now.
  */
 #define _CURL_CONNECTION_TIMEOUT	((long)(30))		/* 30 seconds */
-#define _CURL_MINIMUM_XFER_SPEED	((long)1024)		/* 1Kb/sec */
+#define _CURL_MINIMUM_XFER_SPEED	((long)1024)		/* 1KB/sec */
 #define _CURL_MINIMUM_XFER_TIMEOUT	((long)(60))		/* 1 minute */
+#define _CURL_MINIMUM_PROGRESS_INTERVAL ((double)(0.2)) /* 0.2 seconds */
 
 /* ========================================================================= **
  * Definitions
@@ -63,13 +64,30 @@
 #pragma mark Definitions
 
 /* ------------------------------------------------------------------------- **
+ * Global cURL handle
+ * ------------------------------------------------------------------------- */
+/* we use a single global handle rather than creating and destroying handles to
+ * take advantage of HTTP pipelining, especially to the packages servers. */
+static CURL* theHandle = NULL;
+
+/* ------------------------------------------------------------------------- **
  * Prototypes
  * ------------------------------------------------------------------------- */
 int SetResultFromCurlErrorCode(Tcl_Interp* interp, CURLcode inErrorCode);
 int CurlFetchCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
 int CurlIsNewerCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
 int CurlGetSizeCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
+int CurlPostCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
 
+typedef struct {
+	Tcl_Interp *interp;
+	const char *proc;
+	double prevcalltime;
+} tcl_callback_t;
+
+static int CurlProgressHandler(tcl_callback_t *callback, double dltotal, double dlnow, double ultotal, double ulnow);
+static void CurlProgressCleanup(tcl_callback_t *callback);
+
 void CurlInit(void);
 
 /* ========================================================================= **
@@ -104,7 +122,7 @@
 /**
  * curl fetch subcommand entry point.
  *
- * syntax: curl fetch [-v] [--disable-epsv] [--ignore-ssl-cert] [--remote-time] [-u userpass] [--effective-url lasturlvar] url filename
+ * syntax: curl fetch [--disable-epsv] [--ignore-ssl-cert] [--remote-time] [-u userpass] [--effective-url lasturlvar] [--progress "builtin"|callback] url filename
  *
  * @param interp		current interpreter
  * @param objc			number of parameters
@@ -114,7 +132,6 @@
 CurlFetchCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[])
 {
 	int theResult = TCL_OK;
-	CURL* theHandle = NULL;
 	FILE* theFile = NULL;
 	bool performFailed = false;
 	char theErrorString[CURL_ERROR_SIZE];
@@ -126,6 +143,11 @@
 		int remotetime = 0;
 		const char* theUserPassString = NULL;
 		const char* effectiveURLVarName = NULL;
+		tcl_callback_t progressCallback = {
+			.interp = interp,
+			.proc = NULL,
+			.prevcalltime = 0.0
+		};
 		char* effectiveURL = NULL;
 		char* userAgent = PACKAGE_NAME "/" PACKAGE_VERSION " libcurl/" LIBCURL_VERSION;
 		int optioncrsr;
@@ -145,9 +167,7 @@
 			/* get the option */
 			const char* theOption = Tcl_GetString(objv[optioncrsr]);
 
-			if (strcmp(theOption, "-v") == 0) {
-				noprogress = 0;
-			} else if (strcmp(theOption, "--disable-epsv") == 0) {
+			if (strcmp(theOption, "--disable-epsv") == 0) {
 				useepsv = 0;
 			} else if (strcmp(theOption, "--ignore-ssl-cert") == 0) {
 				ignoresslcert = 1;
@@ -189,6 +209,19 @@
 					theResult = TCL_ERROR;
 					break;
 				}
+			} else if (strcmp(theOption, "--progress") == 0) {
+				/* check we also have the parameter */
+				if (optioncrsr < lastoption) {
+					optioncrsr++;
+					noprogress = 0;
+					progressCallback.proc = Tcl_GetString(objv[optioncrsr]);
+				} else {
+					Tcl_SetResult(interp,
+						"curl fetch: --progress option requires a parameter",
+						TCL_STATIC);
+					theResult = TCL_ERROR;
+					break;
+				}
 			} else {
 				Tcl_ResetResult(interp);
 				Tcl_AppendResult(interp, "curl fetch: unknown option ", theOption, NULL);
@@ -220,7 +253,7 @@
 		}
 
 		/* Open the file */
-		theFile = fopen( theFilePath, "w" );
+		theFile = fopen(theFilePath, "w");
 		if (theFile == NULL) {
 			Tcl_SetResult(interp, strerror(errno), TCL_VOLATILE);
 			theResult = TCL_ERROR;
@@ -228,7 +261,12 @@
 		}
 
 		/* Create the CURL handle */
-		theHandle = curl_easy_init();
+		if (theHandle == NULL) {
+			/* Re-use existing handle if theHandle isn't NULL */
+			theHandle = curl_easy_init();
+		}
+		/* If we're re-using a handle, the previous call did ensure to reset it
+		 * to the default state using curl_easy_reset(3) */
 
 		/* Setup the handle */
 		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_URL, theURL);
@@ -238,17 +276,17 @@
 		}
 
 #if LIBCURL_VERSION_NUM >= 0x071304 && LIBCURL_VERSION_NUM <= 0x071307
-        /* FTP_PROXY workaround for Snow Leopard */
-        if (strncmp(theURL, "ftp:", 4) == 0) {
-            char *ftp_proxy = getenv("FTP_PROXY");
-            if (ftp_proxy) {
-                theCurlCode = curl_easy_setopt(theHandle, CURLOPT_PROXY, ftp_proxy);
-                if (theCurlCode != CURLE_OK) {
-                    theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
-                    break;
-                }
-            }
-        }
+		/* FTP_PROXY workaround for Snow Leopard */
+		if (strncmp(theURL, "ftp:", 4) == 0) {
+			char *ftp_proxy = getenv("FTP_PROXY");
+			if (ftp_proxy) {
+				theCurlCode = curl_easy_setopt(theHandle, CURLOPT_PROXY, ftp_proxy);
+				if (theCurlCode != CURLE_OK) {
+					theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+					break;
+				}
+			}
+		}
 #endif
 
 		/* -L option */
@@ -328,6 +366,21 @@
 			break;
 		}
 
+		/* we want/don't want a custom progress function */
+		if (noprogress == 0 && strcmp(progressCallback.proc, "builtin") != 0) {
+			theCurlCode = curl_easy_setopt(theHandle, CURLOPT_PROGRESSDATA, &progressCallback);
+			if (theCurlCode != CURLE_OK) {
+				theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+				break;
+			}
+
+			theCurlCode = curl_easy_setopt(theHandle, CURLOPT_PROGRESSFUNCTION, CurlProgressHandler);
+			if (theCurlCode != CURLE_OK) {
+				theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+				break;
+			}
+		}
+
 		/* we want/don't want to use epsv */
 		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FTP_USE_EPSV, useepsv);
 		if (theCurlCode != CURLE_OK) {
@@ -386,8 +439,13 @@
 			break;
 		}
 
+		/* signal cleanup to the progress callback */
+		if (noprogress == 0 && strcmp(progressCallback.proc, "builtin") != 0) {
+			CurlProgressCleanup(&progressCallback);
+		}
+
 		/* close the file */
-		(void) fclose( theFile );
+		(void) fclose(theFile);
 		theFile = NULL;
 
 #if LIBCURL_VERSION_NUM == 0x070d01 /* work around broken Tiger version of cURL */
@@ -404,21 +462,21 @@
 				theResult = TCL_ERROR;
 				break;
 			}
-			theFile = fopen( theFilePath, "r");
+			theFile = fopen(theFilePath, "r");
 			if (theFile == NULL) {
 				Tcl_SetResult(interp, strerror(errno), TCL_VOLATILE);
 				theResult = TCL_ERROR;
 				break;
 			}
-			if ( (p = fgets(buf, BUFSIZ, theFile)) != NULL) {
+			if ((p = fgets(buf, BUFSIZ, theFile)) != NULL) {
 				/* skip stray header escaping into output */
 				if (strncmp(p, "Last-Modified:", 14) != 0)
 					rewind(theFile);
 			}
-			while ( (size = fread(buf, 1, BUFSIZ, theFile)) > 0) {
+			while ((size = fread(buf, 1, BUFSIZ, theFile)) > 0) {
 				fwrite(buf, 1, size, fp);
 			}
-			(void) fclose( theFile );
+			(void) fclose(theFile);
 			theFile = NULL;
 			fclose(fp);
 			if (rename(tmp, theFilePath) != 0) {
@@ -449,10 +507,6 @@
 				(effectiveURL == NULL || theCurlCode != CURLE_OK) ? "" : effectiveURL,
 				0);
 		}
-
-		/* clean up */
-		curl_easy_cleanup( theHandle );
-		theHandle = NULL;
 	} while (0);
 
 	if (performFailed) {
@@ -460,11 +514,12 @@
 		theResult = TCL_ERROR;
 	}
 
+	/* reset the connection */
 	if (theHandle != NULL) {
-		curl_easy_cleanup( theHandle );
+		curl_easy_reset(theHandle);
 	}
 	if (theFile != NULL) {
-		fclose( theFile );
+		fclose(theFile);
 	}
 
 	return theResult;
@@ -510,7 +565,7 @@
 			}
 
 			optioncrsr++;
-                }
+		}
 
 		if (optioncrsr <= lastoption) {
 			/* something went wrong */
@@ -534,7 +589,7 @@
 		}
 
 		/* Open the file (dev/null) */
-		theFile = fopen( "/dev/null", "a" );
+		theFile = fopen("/dev/null", "a");
 		if (theFile == NULL) {
 			Tcl_SetResult(interp, strerror(errno), TCL_VOLATILE);
 			theResult = TCL_ERROR;
@@ -542,7 +597,12 @@
 		}
 
 		/* Create the CURL handle */
-		theHandle = curl_easy_init();
+		if (theHandle == NULL) {
+			/* Re-use existing handle if theHandle isn't NULL */
+			theHandle = curl_easy_init();
+		}
+		/* If we're re-using a handle, the previous call did ensure to reset it
+		 * to the default state using curl_easy_reset(3) */
 
 		/* Setup the handle */
 		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_URL, theURL);
@@ -655,7 +715,7 @@
 		}
 
 		/* close the file */
-		(void) fclose( theFile );
+		(void) fclose(theFile);
 		theFile = NULL;
 
 		/* check everything went fine */
@@ -675,10 +735,6 @@
 				break;
 			}
 
-			/* clean up */
-			curl_easy_cleanup( theHandle );
-			theHandle = NULL;
-
 			/* compare this with the date provided by user */
 			if (theModDate < -1) {
 				Tcl_SetResult(interp, "Couldn't get resource modification date", TCL_STATIC);
@@ -694,8 +750,9 @@
 		}
 	} while (0);
 
+	/* reset the connection */
 	if (theHandle != NULL) {
-		curl_easy_cleanup(theHandle);
+		curl_easy_reset(theHandle);
 	}
 
 	if (theFile != NULL) {
@@ -744,7 +801,7 @@
 			}
 
 			optioncrsr++;
-                }
+		}
 
 		if (optioncrsr <= lastoption) {
 			/* something went wrong */
@@ -762,7 +819,7 @@
 		theURL = Tcl_GetString(objv[objc - 1]);
 
 		/* Open the file (dev/null) */
-		theFile = fopen( "/dev/null", "a" );
+		theFile = fopen("/dev/null", "a");
 		if (theFile == NULL) {
 			Tcl_SetResult(interp, strerror(errno), TCL_VOLATILE);
 			theResult = TCL_ERROR;
@@ -770,7 +827,12 @@
 		}
 
 		/* Create the CURL handle */
-		theHandle = curl_easy_init();
+		if (theHandle == NULL) {
+			/* Re-use existing handle if theHandle isn't NULL */
+			theHandle = curl_easy_init();
+		}
+		/* If we're re-using a handle, the previous call did ensure to reset it
+		 * to the default state using curl_easy_reset(3) */
 
 		/* Setup the handle */
 		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_URL, theURL);
@@ -878,7 +940,7 @@
 		}
 
 		/* close the file */
-		(void) fclose( theFile );
+		(void) fclose(theFile);
 		theFile = NULL;
 
 		theFileSize = 0.0;
@@ -890,17 +952,14 @@
 			break;
 		}
 
-		/* clean up */
-		curl_easy_cleanup( theHandle );
-		theHandle = NULL;
-
 		(void) snprintf(theSizeString, sizeof(theSizeString),
 			"%.0f", theFileSize);
 		Tcl_SetResult(interp, theSizeString, TCL_VOLATILE);
 	} while (0);
 
+	/* reset the connection */
 	if (theHandle != NULL) {
-		curl_easy_cleanup(theHandle);
+		curl_easy_reset(theHandle);
 	}
 
 	if (theFile != NULL) {
@@ -911,6 +970,251 @@
 }
 
 /**
+ * curl post postdata url
+ *
+ * syntax: curl post [--user-agent useragentstring] [--progress "builtin"|callback] postdata url
+ *
+ * @param interp		current interpreter
+ * @param objc			number of parameters
+ * @param objv			parameters
+ */
+int
+CurlPostCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[])
+{
+	int theResult = TCL_OK;
+	CURL* theHandle = NULL;
+	FILE* theFile = NULL;
+
+	do {
+		const char* theURL;
+		const char* thePostData;
+		CURLcode theCurlCode;
+		int noprogress = 1;
+		tcl_callback_t progressCallback = {
+			.interp = interp,
+			.proc = NULL,
+			.prevcalltime = 0.0
+		};
+		char* userAgent = PACKAGE_NAME "/" PACKAGE_VERSION " libcurl/" LIBCURL_VERSION;
+		int optioncrsr;
+		int lastoption;
+
+		/* we might have options and then postdata and the url */
+		/* let's process the options first */
+
+		optioncrsr = 2;
+		lastoption = objc - 3;
+		while (optioncrsr <= lastoption) {
+			/* get the option */
+			const char* theOption = Tcl_GetString(objv[optioncrsr]);
+
+			if (strcmp(theOption, "--user-agent") == 0) {
+				/* check we also have the parameter */
+				if (optioncrsr < lastoption) {
+					optioncrsr++;
+					userAgent = Tcl_GetString(objv[optioncrsr]);
+				} else {
+					Tcl_SetResult(interp,
+						"curl post: --user-agent option requires a parameter",
+						TCL_STATIC);
+					theResult = TCL_ERROR;
+					break;
+				}
+			} else if (strcmp(theOption, "--progress") == 0) {
+				/* check we also have the parameter */
+				if (optioncrsr < lastoption) {
+					optioncrsr++;
+					noprogress = 0;
+					progressCallback.proc = Tcl_GetString(objv[optioncrsr]);
+				} else {
+					Tcl_SetResult(interp,
+						"curl post: --progress option requires a parameter",
+						TCL_STATIC);
+					theResult = TCL_ERROR;
+					break;
+				}
+			} else {
+				Tcl_ResetResult(interp);
+				Tcl_AppendResult(interp, "curl post: unknown option ", theOption, NULL);
+				theResult = TCL_ERROR;
+				break;
+			}
+
+			optioncrsr++;
+		}
+
+		if (optioncrsr <= lastoption) {
+			/* something went wrong */
+			break;
+		}
+
+		/*	first (second) parameter is -v or the url,
+			second (third) parameter is the file */
+
+		if (objc >= 4) {
+			/* Retrieve the url - it is the last parameter */
+			theURL = Tcl_GetString(objv[objc - 1]);
+
+			/* Retrieve the post data - it's before the url */
+			thePostData = Tcl_GetString(objv[objc - 2]);
+		} else {
+			Tcl_WrongNumArgs(interp, 1, objv, "post [options] postdata file");
+			theResult = TCL_ERROR;
+			break;
+		}
+
+		/* Open the file (dev/null) */
+		theFile = fopen("/dev/null", "a");
+		if (theFile == NULL) {
+			Tcl_SetResult(interp, strerror(errno), TCL_VOLATILE);
+			theResult = TCL_ERROR;
+			break;
+		}
+
+		/* Create the CURL handle */
+		if (theHandle == NULL) {
+			/* Re-use existing handle if theHandle isn't NULL */
+			theHandle = curl_easy_init();
+		}
+		/* If we're re-using a handle, the previous call did ensure to reset it
+		 * to the default state using curl_easy_reset(3) */
+
+		/* Setup the handle */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_URL, theURL);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* Specify the POST data */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_POSTFIELDS, thePostData);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* -L option */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FOLLOWLOCATION, 1);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* --max-redirs option, same default as curl command line */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_MAXREDIRS, 50);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* echo any cookies received on a redirect */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_COOKIEJAR, "/dev/null");
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* -f option */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FAILONERROR, 1);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* -A option */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_USERAGENT, userAgent);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* set timeout on connections */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_CONNECTTIMEOUT, _CURL_CONNECTION_TIMEOUT);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* set minimum connection speed */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_LOW_SPEED_LIMIT, _CURL_MINIMUM_XFER_SPEED);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* set timeout interval for connections < min xfer speed */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_LOW_SPEED_TIME, _CURL_MINIMUM_XFER_TIMEOUT);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* write to the file */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_WRITEDATA, theFile);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* skip the header data */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_HEADER, 0);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* we want/don't want progress */
+		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_NOPROGRESS, noprogress);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* we want/don't want a custom progress function */
+		if (noprogress == 0 && strcmp(progressCallback.proc, "builtin") != 0) {
+			theCurlCode = curl_easy_setopt(theHandle, CURLOPT_PROGRESSDATA, &progressCallback);
+			if (theCurlCode != CURLE_OK) {
+				theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+				break;
+			}
+
+			theCurlCode = curl_easy_setopt(theHandle, CURLOPT_PROGRESSFUNCTION, CurlProgressHandler);
+			if (theCurlCode != CURLE_OK) {
+				theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+				break;
+			}
+		}
+
+		/* actually perform the POST */
+		theCurlCode = curl_easy_perform(theHandle);
+		if (theCurlCode != CURLE_OK) {
+			theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+			break;
+		}
+
+		/* signal cleanup to the progress callback */
+		if (noprogress == 0 && strcmp(progressCallback.proc, "builtin") != 0) {
+			CurlProgressCleanup(&progressCallback);
+		}
+
+		/* close the file */
+		(void) fclose(theFile);
+		theFile = NULL;
+	} while (0);
+
+	/* reset the connection */
+	if (theHandle != NULL) {
+		curl_easy_reset(theHandle);
+	}
+
+	if (theFile != NULL) {
+		fclose(theFile);
+	}
+
+	return theResult;
+}
+
+/**
  * curl command entry point.
  *
  * @param clientData	custom data (ignored)
@@ -928,11 +1232,12 @@
 	typedef enum {
 		kCurlFetch,
 		kCurlIsNewer,
-		kCurlGetSize
+		kCurlGetSize,
+		kCurlPost
 	} EOption;
 
 	static const char *options[] = {
-		"fetch", "isnewer", "getsize", NULL
+		"fetch", "isnewer", "getsize", "post", NULL
 	};
 	int theResult = TCL_OK;
 	EOption theOptionIndex;
@@ -964,6 +1269,9 @@
 		case kCurlGetSize:
 			theResult = CurlGetSizeCmd(interp, objc, objv);
 			break;
+		case kCurlPost:
+			theResult = CurlPostCmd(interp, objc, objv);
+			break;
 		}
 	}
 
@@ -979,3 +1287,141 @@
 {
 	curl_global_init(CURL_GLOBAL_ALL);
 }
+
+/* ========================================================================= **
+ * Callback function
+ * ========================================================================= */
+#pragma mark -
+#pragma mark Callback function
+static int CurlProgressHandler(
+		tcl_callback_t *callback,
+		double dltotal,
+		double dlnow,
+		double ultotal,
+		double ulnow)
+{
+	if (dltotal == 0.0 && ultotal == 0.0 && dlnow == 0.0 && ulnow == 0.0) {
+		/*
+		 * We have no idea whether this is an up- or download. Do nothing for now.
+		 */
+		return 0;
+	}
+
+	enum {
+		UPLOAD,
+		DOWNLOAD
+	} transferType;
+
+	double total, now, speed, curtime;
+
+	if (dltotal != 0.0 || dlnow != 0.0) {
+		/* This is a download */
+		transferType = DOWNLOAD;
+		total = dltotal;
+		now = dlnow;
+	} else {
+		/* This is an upload */
+		transferType = UPLOAD;
+		total = ultotal;
+		now = ulnow;
+	}
+
+	/* Only send updates once a second */
+	curl_easy_getinfo(theHandle, CURLINFO_TOTAL_TIME, &curtime);
+	if ((curtime - callback->prevcalltime) < _CURL_MINIMUM_PROGRESS_INTERVAL) {
+		return 0;
+	}
+
+	if (callback->prevcalltime == 0.0) {
+		/* this is the first time we're calling the callback, call start
+		 * subcommand first */
+
+		/*
+		 * Command string, a space followed "start", another space and "dl" or
+		 * "ul" plus the trailing \0.
+		 */
+		char startCommandBuffer[strlen(callback->proc) + (1 + 5) + (1 + 2) + 1];
+		int startLen = 0;
+
+		startLen = snprintf(startCommandBuffer, sizeof(startCommandBuffer), "%s start %s",
+				callback->proc, (transferType == DOWNLOAD) ? "dl" : "ul");
+		if (startLen < 0 || (size_t) startLen >= sizeof(startCommandBuffer)) {
+			/* overflow */
+			fprintf(stderr, "pextlib1.0: buffer overflow in " __FILE__ ":%d. Buffer is: %s\n", __LINE__, startCommandBuffer);
+			abort();
+		}
+
+		if (TCL_ERROR == Tcl_EvalEx(callback->interp, startCommandBuffer, startLen, TCL_EVAL_GLOBAL)) {
+			fprintf(stderr, "curl progress callback failed: %s\n", Tcl_GetStringResult(callback->interp));
+			return 1;
+		}
+	}
+
+	callback->prevcalltime = curtime;
+
+	/* Get the average speed from curl */
+	if (transferType == DOWNLOAD) {
+		curl_easy_getinfo(theHandle, CURLINFO_SPEED_DOWNLOAD, &speed);
+	} else {
+		curl_easy_getinfo(theHandle, CURLINFO_SPEED_UPLOAD, &speed);
+	}
+
+	/*
+	 * We need the command string, a space and "update", another space and "dl"
+	 * or "ul", three doubles converted to string (see comment below), plus
+	 * a space character for separation per argument, so 3 * (1 + LEN_DOUBLE)
+	 * plus one character for the null-byte.
+	 */
+	char commandBuffer[strlen(callback->proc) + (1 + 6) + (1 + 2) + 3 * (1 + 12) + 1];
+	int len = 0;
+
+	/*
+	 * Format numbers using % .6g format specifier so we can always be sure
+	 * what the total length will be: .6g tells us we're using at most
+	 * 6 significant digits; that means 6 characters, another one for
+	 * a possible decimal point, another 4 for e+XX where 00 <= XX <= 99 for
+	 * exponents, and another one for a possible sign (or " " for positive
+	 * numbers). In total, the maximum length will be 12 per double formatted.
+	 */
+	len = snprintf(commandBuffer, sizeof(commandBuffer), "%s update %s % .6g % .6g % .6g",
+			callback->proc, (transferType == DOWNLOAD) ? "dl" : "ul", total, now, speed);
+	if (len < 0 || (size_t) len >= sizeof(commandBuffer)) {
+		/* overflow */
+		fprintf(stderr, "pextlib1.0: buffer overflow in " __FILE__ ":%d. Buffer is: %s\n", __LINE__, commandBuffer);
+		abort();
+	}
+
+	/*
+	 * Execute directly rather than compiling to bytecode first - the script is
+	 * likely to change in the next call anyway.
+	 */
+	if (TCL_ERROR == Tcl_EvalEx(callback->interp, commandBuffer, len, TCL_EVAL_GLOBAL)) {
+		fprintf(stderr, "curl progress callback failed: %s\n", Tcl_GetStringResult(callback->interp));
+		return 1;
+	}
+
+	return 0;
+}
+
+static void CurlProgressCleanup(
+		tcl_callback_t *callback)
+{
+	/*
+	 * Transfer complete, signal the progress callback
+	 */
+
+	/*
+	 * Command string, a space followed "finish" plus the trailing \0.
+	 */
+	char commandBuffer[strlen(callback->proc) + (1 + 6) + 1];
+	int len = 0;
+
+	len = snprintf(commandBuffer, sizeof(commandBuffer), "%s finish", callback->proc);
+	if (len < 0 || (size_t) len >= sizeof(commandBuffer)) {
+		/* overflow */
+		fprintf(stderr, "pextlib1.0: buffer overflow in " __FILE__ ":%d. Buffer is: %s\n", __LINE__, commandBuffer);
+		abort();
+	}
+
+	Tcl_EvalEx(callback->interp, commandBuffer, len, TCL_EVAL_GLOBAL);
+}

Modified: branches/new-help-system/base/src/pextlib1.0/filemap.c
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/filemap.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/filemap.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -312,7 +312,7 @@
  *
  * @param ioDatabaseBuffer	pointer to the buffer (where the node starts),
  *							updated by this function.
- * @param outTree			on output, a tree in memory.
+ * @param outNode			on output, a tree in memory.
  * @param ioBytesLeft		number of bytes remaining in the buffer (updated
  *							by this function).
  */
@@ -467,8 +467,8 @@
  * Save the database to the file.
  * This function saves the header and then calls SaveNode.
  *
- * @param inDatabaseFd	file descriptor of the open file (the cursor is reset)
- * @param inTree		tree of the database.
+ * @param inDatabasePath	file descriptor of the open file (the cursor is reset)
+ * @param inTree			tree of the database.
  */
 int
 Save(
@@ -930,7 +930,6 @@
  * @param outList		the list to populate with paths.
  * @param inSubpath		the path of the current root.
  * @param inSubpathLen	the length, without the terminator, of the path.
- * @return the list of paths which has value for their value.
  */
 void
 ListSubtree(


Property changes on: branches/new-help-system/base/src/pextlib1.0/sha2.c
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.c:37343-46937
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha2.c:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/sha2.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha2.c:57888-90355
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.c:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.c:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.c:37343-46937
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha2.c:78828-88375
/branches/gsoc13-tests/src/pextlib1.0/sha2.c:106692-111324
/branches/universal-sanity/base/src/pextlib1.0/sha2.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha2.c:57888-117083
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.c:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.c:44044-44692


Property changes on: branches/new-help-system/base/src/pextlib1.0/sha2.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.h:37343-46937
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha2.h:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/sha2.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha2.h:57888-90355
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.h:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.h:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.h:37343-46937
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha2.h:78828-88375
/branches/gsoc13-tests/src/pextlib1.0/sha2.h:106692-111324
/branches/universal-sanity/base/src/pextlib1.0/sha2.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha2.h:57888-117083
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.h:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.h:44044-44692


Property changes on: branches/new-help-system/base/src/pextlib1.0/sha256cmd.c
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.c:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.c:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha256cmd.c:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha256cmd.c:57888-90355
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.c:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.c:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.c:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.c:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha256cmd.c:78828-88375
/branches/gsoc13-tests/src/pextlib1.0/sha256cmd.c:106692-111324
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha256cmd.c:57888-117083
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.c:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.c:44044-44692


Property changes on: branches/new-help-system/base/src/pextlib1.0/sha256cmd.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.h:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.h:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha256cmd.h:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha256cmd.h:57888-90355
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.h:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.h:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.h:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.h:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha256cmd.h:78828-88375
/branches/gsoc13-tests/src/pextlib1.0/sha256cmd.h:106692-111324
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha256cmd.h:57888-117083
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.h:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.h:44044-44692

Modified: branches/new-help-system/base/src/pextlib1.0/strsed.c
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/strsed.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/strsed.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -662,7 +662,7 @@
 
 	    if (need > 0){
 		more_space(need);
-		strncpy(new_str + new_pos, str, need);
+		memmove(new_str + new_pos, str, need);
 		new_pos += need;
 	    }
 
@@ -756,7 +756,7 @@
      *
      */
     more_space(str_len);
-    (void) strcpy(new_str + new_pos, str);
+    (void) memmove(new_str + new_pos, str, strlen(str) + 1);
     RETURN(new_str);
 }
 

Modified: branches/new-help-system/base/src/pextlib1.0/system.c
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/system.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/system.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -178,7 +178,7 @@
     case -1: /* error */
         Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
         return TCL_ERROR;
-        break;
+        /*NOTREACHED*/
     case 0: /* child */
         if (odup) {
             close(fdset[0]);
@@ -196,7 +196,7 @@
         }
         /* change scheduling priority if requested */
         if (oniceval != INT_MAX) {
-            if (setpriority(PRIO_PROCESS, getpid(), oniceval) != 0) {
+            if (setpriority(PRIO_PROCESS, (id_t)getpid(), oniceval) != 0) {
                 /* ignore failure, just continue */
             }
         }
@@ -233,7 +233,7 @@
             execve("/bin/sh", args, environ);
         }
         _exit(1);
-        break;
+        /*NOTREACHED*/
     default: /* parent */
         break;
     }
@@ -249,7 +249,7 @@
         if (pdes) {
             while ((buf = fgetln(pdes, &linelen)) != NULL) {
                 char *sbuf;
-                int slen;
+                size_t slen;
 
                 /*
                 * Allocate enough space to insert a terminating

Modified: branches/new-help-system/base/src/pextlib1.0/tests/filemap.tcl
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/tests/filemap.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/tests/filemap.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -18,8 +18,8 @@
 		puts {![filemap exists testmap "/foo/bar"]}
 		exit 1
 	}
-	if {[filemap get testmap "/foo/bar"] != "foobar"} {
-		puts {[filemap get testmap "/foo/bar"] != "foobar"}
+	if {[filemap get testmap "/foo/bar"] ne "foobar"} {
+		puts {[filemap get testmap "/foo/bar"] ne "foobar"}
 		exit 1
 	}
 	filemap unset testmap "/foo/bar"
@@ -116,8 +116,8 @@
 		puts [filemap get testmap2 "/foobar"]
 		exit 1
 	}
-	if {[filemap get testmap2 "/bar/bar-3"] != "somevalue"} {
-		puts {[filemap get testmap2 "/bar/bar-3"] != "somevalue"}
+	if {[filemap get testmap2 "/bar/bar-3"] ne "somevalue"} {
+		puts {[filemap get testmap2 "/bar/bar-3"] ne "somevalue"}
 		puts [filemap get testmap2 "/bar/bar-3"]
 		exit 1
 	}

Modified: branches/new-help-system/base/src/pextlib1.0/tests/fs-traverse.tcl
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/tests/fs-traverse.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/tests/fs-traverse.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -85,7 +85,7 @@
         # Test skipping parts of the tree
         set output [list]
         fs-traverse file $root {
-            if {[string match */a $file]} {
+            if {[string match "*/a" $file]} {
                 continue
             }
             lappend output $file
@@ -161,7 +161,7 @@
         # Test to make sure deleting files during traversal works as expected
         set output [list]
         fs-traverse file $root {
-            if {[string match */a $file]} {
+            if {[string match "*/a" $file]} {
                 # use /bin/rm because on 10.3 file delete doesn't work on directories properly
                 exec /bin/rm -rf $file
                 continue

Modified: branches/new-help-system/base/src/pextlib1.0/tracelib.c
===================================================================
--- branches/new-help-system/base/src/pextlib1.0/tracelib.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/pextlib1.0/tracelib.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -63,7 +63,7 @@
 
 #include "strlcat.h"
 
-#ifdef __APPLE__
+#ifdef HAVE_TRACEMODE_SUPPORT
 #ifndef HAVE_STRLCPY
 /* Define strlcpy if it's not available. */
 size_t strlcpy(char *dst, const char *src, size_t size);
@@ -99,14 +99,14 @@
 static void send_file_map(int sock);
 static void dep_check(int sock, char *path);
 static void sandbox_violation(int sock, const char *path);
-static void ui_warn(const char *format, ...);
+static void ui_warn(const char *format, ...) __printflike(1, 2);
 #if 0
-static void ui_info(const char *format, ...);
+static void ui_info(const char *format, ...) __printflike(1, 2);
 #endif
-static void ui_error(const char *format, ...);
+static void ui_error(const char *format, ...) __printflike(1, 2);
 
 #define MAX_SOCKETS (1024)
-#define BUFSIZE     (1024)
+#define BUFSIZE     (4096)
 
 /**
  * send a buffer \c buf with the given length \c size to the socket \c sock, by
@@ -140,9 +140,9 @@
  * Different sockets should be used for different ports (and maybe even
  * phases).
  *
- * \param[inout] interp the Tcl interpreter
+ * \param[in,out] interp the Tcl interpreter
  * \param[in] objc the number of parameters
- * \param[in] the parameters
+ * \param[in] objv the parameters
  * \return a Tcl return code
  */
 static int TracelibSetNameCmd(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
@@ -157,6 +157,9 @@
         return TCL_ERROR;
     }
 
+    // initialize the depends field, in case we don't actually have any dependencies
+    depends = NULL;
+
     return TCL_OK;
 }
 
@@ -169,9 +172,9 @@
  * In variable;
  *  /dev/null\0/dev/tty\0/tmp:\0\0
  *
- * \param[inout] interp the Tcl interpreter
+ * \param[in,out] interp the Tcl interpreter
  * \param[in] objc the number of parameters
- * \param[in] the parameters
+ * \param[in] objv the parameters
  * \return a Tcl return code
  */
 static int TracelibSetSandboxCmd(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
@@ -309,7 +312,7 @@
     if (!filemap) {
         char *t, * _;
 
-        size_t remaining = 1024;
+        size_t remaining = BUFSIZE;
         filemap = (char *)malloc(remaining);
         if (!filemap) {
             ui_warn("send_file_map: memory allocation failed");
@@ -318,10 +321,12 @@
         t = filemap;
 
 #       define append_allow(path, resolution) do { strlcpy(t, path, remaining); \
-            if (remaining < (strlen(t)+3)) \
+            if (remaining < (strlen(t)+3)) { \
                 remaining=0; \
-            else \
+                fprintf(stderr, "tracelib: insufficient filemap memory\n"); \
+            } else { \
                 remaining-=strlen(t)+3; \
+            } \
             t+=strlen(t)+1; \
             *t++=resolution; \
             *t++=0; \
@@ -406,7 +411,7 @@
     reg_error error;
 
     if (NULL == (reg = registry_for(interp, reg_attached))) {
-        ui_error(Tcl_GetStringResult(interp));
+        ui_error("%s", Tcl_GetStringResult(interp));
         /* send unexpected output to make the build fail */
         answer(sock, "#");
     }
@@ -424,12 +429,12 @@
     /* find the port's name to compare with out list */
     if (!reg_entry_propget(&entry, "name", &port, &error)) {
         /* send unexpected output to make the build fail */
-        ui_error(error.description);
+        ui_error("%s", error.description);
         answer(sock, "#");
     }
 
     /* check our list of dependencies */
-    for (t = depends; *t; t += strlen(t) + 1) {
+    for (t = depends; t && *t; t += strlen(t) + 1) {
         if (strcmp(t, port) == 0) {
             free(port);
             answer(sock, "+");
@@ -441,6 +446,7 @@
     answer(sock, "!");
 }
 
+__printflike(2, 0)
 static void ui_msg(const char *severity, const char *format, va_list va) {
     char buf[1024], tclcmd[32];
 
@@ -456,6 +462,7 @@
 
 }
 
+__printflike(1, 2)
 static void ui_warn(const char *format, ...) {
     va_list va;
 
@@ -465,6 +472,7 @@
 }
 
 #if 0
+__printflike(1, 2)
 static void ui_info(const char *format, ...) {
     va_list va;
 
@@ -474,6 +482,7 @@
 }
 #endif
 
+__printflike(1, 2)
 static void ui_error(const char *format, ...) {
     va_list va;
     va_start(va, format);
@@ -504,7 +513,7 @@
     if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
         ui_warn("getrlimit failed (%d), skipping setrlimit", errno);
     } else {
-#if defined(__APPLE__) && defined(OPEN_MAX)
+#ifdef OPEN_MAX
         if (rl.rlim_max > OPEN_MAX) {
             rl.rlim_max = OPEN_MAX;
         }
@@ -539,13 +548,10 @@
     return TCL_OK;
 }
 
-#if HAVE_KQUEUE
 /* create this on heap rather than stack, due to its rather large size */
 static struct kevent res_kevents[MAX_SOCKETS];
-#endif
 
 static int TracelibRunCmd(Tcl_Interp *in) {
-#if HAVE_KQUEUE
     struct kevent kev;
     int flags;
     int oldsock;
@@ -759,10 +765,6 @@
     pthread_mutex_unlock(&sock_mutex);
 
     return TCL_OK;
-#else
-    Tcl_SetResult(in, "tracelib not supported on this platform", TCL_STATIC);
-    return TCL_ERROR;
-#endif
 }
 
 static int TracelibCleanCmd(Tcl_Interp *interp UNUSED) {
@@ -770,7 +772,6 @@
     cleanuping = 1;
     pthread_mutex_lock(&sock_mutex);
     if (sock != -1) {
-        /* shutdown(sock, SHUT_RDWR);*/
         close(sock);
         sock = -1;
     }
@@ -794,9 +795,7 @@
     cleanuping = 1;
     pthread_mutex_lock(&sock_mutex);
     if (sock != -1) {
-        int oldsock = sock;
-        /*shutdown(sock, SHUT_RDWR);*/
-        close(oldsock);
+        close(sock);
         sock = -1;
 
         if (kq != -1) {
@@ -811,7 +810,7 @@
     return TCL_OK;
 }
 
-static int TracelibSetDeps(Tcl_Interp *interp UNUSED, int objc, Tcl_Obj *CONST objv[]) {
+static int TracelibSetDeps(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
     char *t, * d;
     size_t l;
     if (objc != 3) {
@@ -844,7 +843,7 @@
     filemap = 0;
     return TCL_OK;
 }
-#endif /* __APPLE__ */
+#endif /* defined(HAVE_TRACEMODE_SUPPORT) */
 
 int TracelibCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
     int result = TCL_OK;
@@ -867,7 +866,7 @@
         return TCL_ERROR;
     }
 
-#ifdef __APPLE__
+#ifdef HAVE_TRACEMODE_SUPPORT
     result = Tcl_GetIndexFromObj(interp, objv[1], options, "option", 0, (int *)&current_option);
     if (result == TCL_OK) {
         switch (current_option) {
@@ -897,10 +896,10 @@
                 break;
         }
     }
-#else /* __APPLE__ */
+#else /* defined(HAVE_TRACEMODE_SUPPORT) */
     Tcl_SetResult(interp, "tracelib not supported on this platform", TCL_STATIC);
     result = TCL_ERROR;
-#endif /* __APPLE__ */
+#endif /* defined(HAVE_TRACEMODE_SUPPORT) */
 
     return result;
 }

Modified: branches/new-help-system/base/src/port/port.tcl
===================================================================
--- branches/new-help-system/base/src/port/port.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port/port.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -34,6 +34,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
+package require term::ansi::send
+
 source [file join "@macports_tcl_dir@" macports1.0 macports_fastload.tcl]
 package require macports
 package require Pextlib 1.0
@@ -155,7 +157,7 @@
 
 
 # Format an integer representing bytes using given units
-proc bytesize {siz {unit {}}} {
+proc bytesize {siz {unit {}} {format {%.3f}}} {
     if {$unit == {}} {
         if {$siz > 0x40000000} {
             set unit "GiB"
@@ -169,22 +171,22 @@
     }
     switch -- $unit {
         KiB {
-            set siz [expr $siz / 1024.0]
+            set siz [expr {$siz / 1024.0}]
         }
         kB {
-            set siz [expr $siz / 1000.0]
+            set siz [expr {$siz / 1000.0}]
         }
         MiB {
-            set siz [expr $siz / 1048576.0]
+            set siz [expr {$siz / 1048576.0}]
         }
         MB {
-            set siz [expr $siz / 1000000.0]
+            set siz [expr {$siz / 1000000.0}]
         }
         GiB {
-            set siz [expr $siz / 1073741824.0]
+            set siz [expr {$siz / 1073741824.0}]
         }
         GB {
-            set siz [expr $siz / 1000000000.0]
+            set siz [expr {$siz / 1000000000.0}]
         }
         B { }
         default {
@@ -192,8 +194,8 @@
             set unit "B"
         }
     }
-    if {[expr round($siz)] != $siz} {
-        set siz [format {%.3f} $siz]
+    if {[expr {round($siz)}] != $siz} {
+        set siz [format $format $siz]
     }
     return "$siz $unit"
 }
@@ -250,16 +252,16 @@
     set pos {}
     set neg {}
     foreach { key val } $variations {
-        if {$val == "+"} {
+        if {$val eq "+"} {
             lappend pos $key
-        } elseif {$val == "-"} {
+        } elseif {$val eq "-"} {
             lappend neg $key
         }
     }
 
     # If there is no version, we have nothing to do
     set composite_version ""
-    if {$version != "" || $emptyVersionOkay} {
+    if {$version ne "" || $emptyVersionOkay} {
         set pos_str ""
         set neg_str ""
 
@@ -314,7 +316,7 @@
     set ilist [registry::installed $portname $portversion]
     if { [llength $ilist] > 1 } {
         # set portname again since the one we were passed may not have had the correct case
-        set portname [lindex [lindex $ilist 0] 0]
+        set portname [lindex $ilist 0 0]
         ui_notice "The following versions of $portname are currently installed:"
         foreach i [portlist_sortint $ilist] { 
             set iname [lindex $i 0]
@@ -356,12 +358,12 @@
     if {![info exists port(options)]}   { set port(options) [array get global_options] }
 
     # If neither portname nor url is specified, then default to the current port
-    if { $port(url) == "" && $port(name) == "" } {
+    if { $port(url) eq "" && $port(name) eq "" } {
         set url file://.
         set portname [url_to_portname $url]
         set port(url) $url
         set port(name) $portname
-        if {$portname == ""} {
+        if {$portname eq ""} {
             ui_error "A default port name could not be supplied."
         }
     }
@@ -423,7 +425,7 @@
     global private_options
     upvar $nameportlist portlist
 
-    if {[llength $portlist] == 0 && (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) == "no")} {
+    if {[llength $portlist] == 0 && (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) eq "no")} {
         if {${is_upgrade} == "yes"} {
             # $> port upgrade outdated
             # Error: No ports matched the given expression
@@ -642,7 +644,7 @@
     set string [split $line " "]
     if {$indentfirstline == 0} {
         set newline ""
-        set maxlen [expr $maxlen - [string length $indent]]
+        set maxlen [expr {$maxlen - [string length $indent]}]
     } else {
         set newline $indent
     }
@@ -657,7 +659,7 @@
             # If indentfirstline is set to 0, reset maxlen to its
             # original length after appending the first line to lines.
             if {$first == 1 && $indentfirstline == 0} {
-                set maxlen [expr $maxlen + [string length $indent]]
+                set maxlen [expr {$maxlen + [string length $indent]}]
             }
             set first 0
         }
@@ -678,7 +680,7 @@
 # @param maxlen text width (0 defaults to current terminal width)
 # @return wrapped string
 proc wraplabel {label string maxlen {indent ""}} {
-    append label ": [string repeat " " [expr [string length $indent] - [string length "$label: "]]]"
+    append label ": [string repeat " " [expr {[string length $indent] - [string length "$label: "]}]]"
     return "$label[wrap $string $maxlen $indent 0]"
 }
 
@@ -761,7 +763,7 @@
 proc get_current_port {} {
     set url file://.
     set portname [url_to_portname $url]
-    if {$portname == ""} {
+    if {$portname eq ""} {
         ui_msg "To use the current port, you must be in a port's directory."
         return [list]
     }
@@ -775,7 +777,7 @@
 proc get_installed_ports { {ignore_active yes} {active yes} } {
     set ilist {}
     if { [catch {set ilist [registry::installed]} result] } {
-        if {$result != "Registry error: No ports registered as installed."} {
+        if {$result ne "Registry error: No ports registered as installed."} {
             global errorInfo
             ui_debug "$errorInfo"
             fatal "port installed failed: $result"
@@ -850,7 +852,7 @@
     # Get the list of installed ports
     set ilist {}
     if { [catch {set ilist [registry::installed]} result] } {
-        if {$result != "Registry error: No ports registered as installed."} {
+        if {$result ne "Registry error: No ports registered as installed."} {
             global errorInfo
             ui_debug "$errorInfo"
             fatal "port installed failed: $result"
@@ -904,20 +906,20 @@
             # Compare versions, first checking epoch, then version, then revision
             set comp_result 0
             if {$installed_version != $latest_version} {
-                set comp_result [expr $installed_epoch - $latest_epoch]
+                set comp_result [expr {$installed_epoch - $latest_epoch}]
                 if { $comp_result == 0 } {
                     set comp_result [vercmp $installed_version $latest_version]
                 }
             }
             if { $comp_result == 0 } {
-                set comp_result [expr $installed_revision - $latest_revision]
+                set comp_result [expr {$installed_revision - $latest_revision}]
             }
             if {$comp_result == 0} {
                 set regref [registry::open_entry $portname $installed_version $installed_revision $installed_variants $installed_epoch]
                 set os_platform_installed [registry::property_retrieve $regref os_platform]
                 set os_major_installed [registry::property_retrieve $regref os_major]
-                if {$os_platform_installed != "" && $os_platform_installed != 0
-                    && $os_major_installed != "" && $os_major_installed != 0
+                if {$os_platform_installed ne "" && $os_platform_installed != 0
+                    && $os_major_installed ne "" && $os_major_installed != 0
                     && ($os_platform_installed != ${macports::os_platform} || $os_major_installed != ${macports::os_major})} {
                     set comp_result -1
                 }
@@ -959,7 +961,7 @@
 proc get_ports_with_prop {propname propval} {
     set ilist {}
     if { [catch {set ilist [registry::installed]} result] } {
-        if {$result != "Registry error: No ports registered as installed."} {
+        if {$result ne "Registry error: No ports registered as installed."} {
             global errorInfo
             ui_debug "$errorInfo"
             fatal "port installed failed: $result"
@@ -994,7 +996,7 @@
 proc get_leaves_ports {} {
     set ilist {}
     if { [catch {set ilist [registry::installed]} result] } {
-        if {$result != "Registry error: No ports registered as installed."} {
+        if {$result ne "Registry error: No ports registered as installed."} {
             global errorInfo
             ui_debug "$errorInfo"
             fatal "port installed failed: $result"
@@ -1004,7 +1006,7 @@
     set results {}
     foreach i $ilist {
         set iname [lindex $i 0]
-        if {[registry::list_dependents $iname] == ""} {
+        if {[registry::list_dependents $iname] eq ""} {
             add_to_portlist results [list name $iname version "[lindex $i 1]_[lindex $i 2]" variants [split_variants [lindex $i 3]]]
         }
     }
@@ -1408,7 +1410,7 @@
             # Break up the token, because older Tcl switch doesn't support -matchvar
             regexp {^(\w+):(.*)} $token matchvar selector portname
 
-            set recursive [string equal $selector rdependentof]
+            set recursive [string equal $selector "rdependentof"]
             add_multiple_ports reslist [get_dependent_ports $portname $recursive]
             
             set el 1
@@ -1421,7 +1423,7 @@
             # Break up the token, because older Tcl switch doesn't support -matchvar
             regexp {^(\w+):(.*)} $token matchvar selector portname
 
-            set recursive [string equal $selector rdepof]
+            set recursive [string equal $selector "rdepof"]
             add_multiple_ports reslist [get_dep_ports $portname $recursive]
             
             set el 1
@@ -1446,7 +1448,7 @@
         ^\\w+:.+            { # Handle a url by trying to open it as a port and mapping the name
             advance
             set name [url_to_portname $token]
-            if {$name != ""} {
+            if {$name ne ""} {
                 parsePortSpec version requested_variants options
                 add_to_portlist reslist [list url $token \
                   name $name \
@@ -1487,7 +1489,7 @@
     parsePortSpec version variants options $remainder
     
     array unset overrides
-    if {$version != ""} { set overrides(version) $version }
+    if {$version ne ""} { set overrides(version) $version }
     if {[array size variants]} {
         # we always record the requested variants separately,
         # but requested ones always override existing ones
@@ -1645,7 +1647,7 @@
             if {[string match "*/*" $portname]} {
                 set url "file://$portname"
                 set name [url_to_portname $url 1]
-                if { $name != "" } {
+                if { $name ne "" } {
                     # We mapped the url to valid port
                     set porturl $url
                     set portname $name
@@ -1696,10 +1698,10 @@
     set opt $remainder
     set adv 0
     set consumed 0
-    for {set firstTime 1} {$opt != "" || [moreargs]} {set firstTime 0} {
+    for {set firstTime 1} {$opt ne "" || [moreargs]} {set firstTime 0} {
     
         # Refresh opt as needed
-        if {$opt == ""} {
+        if {$opt eq ""} {
             if {$adv} advance
             set opt [lookahead]
             set adv 1
@@ -1717,14 +1719,14 @@
             set sepPos [string first "/" $opt]
             if {$sepPos >= 0} {
                 # Version terminated by "/" to disambiguate -variant from part of version
-                set portversion [string range $opt 0 [expr $sepPos-1]]
-                set opt [string range $opt [expr $sepPos+1] end]
+                set portversion [string range $opt 0 [expr {$sepPos - 1}]]
+                set opt [string range $opt [expr {$sepPos + 1}] end]
             } else {
                 # Version terminated by "+", or else is complete
                 set sepPos [string first "+" $opt]
                 if {$sepPos >= 0} {
                     # Version terminated by "+"
-                    set portversion [string range $opt 0 [expr $sepPos-1]]
+                    set portversion [string range $opt 0 [expr {$sepPos - 1}]]
                     set opt [string range $opt $sepPos end]
                 } else {
                     # Unterminated version
@@ -1745,7 +1747,7 @@
             } elseif {[regexp {^([-+])([[:alpha:]_]+[\w\.]*)} $opt match sign variant] == 1} {
                 # It's a variant
                 set portvariants($variant) $sign
-                set opt [string range $opt [expr [string length $variant]+1] end]
+                set opt [string range $opt [expr {[string length $variant] + 1}] end]
                 set consumed 1
             } else {
                 # Not an option we recognize, so break from port option processing
@@ -1793,7 +1795,7 @@
 
         set ret "Usage: "
         set len [string length $action]
-        append ret [wrap "$action$cmds$args" 0 [string repeat " " [expr 8 + $len]] 0]
+        append ret [wrap "$action$cmds$args" 0 [string repeat " " [expr {8 + $len}]] 0]
         append ret "\n"
 
         return $ret
@@ -1912,8 +1914,8 @@
             set portdir [file split [macports::getportdir $porturl]]
             set lsize [llength $portdir]
             set portdir \
-                [file join [lindex $portdir [expr $lsize - 2]] \
-                           [lindex $portdir [expr $lsize - 1]]]
+                [file join [lindex $portdir [expr {$lsize - 2}]] \
+                           [lindex $portdir [expr {$lsize - 1}]]]
             if {[catch {mportsearch $portdir no exact portdir} result]} {
                 ui_debug "$::errorInfo"
                 break_softcontinue "Portdir $portdir not found" 1 status
@@ -1989,7 +1991,7 @@
         array unset portinfo
         # If we have a url, use that, since it's most specific
         # otherwise try to map the portname to a url
-        if {$porturl == "" || $index_only} {
+        if {$porturl eq "" || $index_only} {
         # Verify the portname, getting portinfo to map to a porturl
             if {[catch {mportlookup $portname} result]} {
                 ui_debug "$::errorInfo"
@@ -2097,7 +2099,7 @@
         }
 
         # Interpret a convenient field abbreviation
-        if {[info exists options(ports_info_depends)] && $options(ports_info_depends) == "yes"} {
+        if {[info exists options(ports_info_depends)] && $options(ports_info_depends) eq "yes"} {
             array unset options ports_info_depends
             set options(ports_info_depends_fetch) yes
             set options(ports_info_depends_extract) yes
@@ -2249,7 +2251,7 @@
                 }
             } 
             #End of special pretty-print formatting for certain fields
-            if [info exists list_map($ropt)] {
+            if {[info exists list_map($ropt)]} {
                 set field [join $inf $subfield_sep]
             } else {
                 set field $inf
@@ -2267,10 +2269,10 @@
             }
             lappend fields_tried $label
             if {$pretty_print} {
-                if {![string length $field]} {
+                if {$field eq ""} {
                     continue
                 }
-                if {![string length $label]} {
+                if {$label eq ""} {
                     set wrap_len 0
                     if {[info exists pretty_wrap($ropt)]} {
                         set wrap_len $pretty_wrap($ropt)
@@ -2424,7 +2426,7 @@
     foreach filename $portlist {
         set file [file normalize $filename]
         if {[file exists $file] || ![catch {file type $file}]} {
-            if {![file isdirectory $file] || [file type $file] == "link"} {
+            if {![file isdirectory $file] || [file type $file] eq "link"} {
                 set port [registry::file_registered $file]
                 if { $port != 0 } {
                     puts "$file is provided by: $port"
@@ -2457,7 +2459,7 @@
 
             set i [lindex $ilist 0]
             set regref [registry::entry open $portname [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
-            if {[$regref installtype] == "image" && [registry::run_target $regref activate [array get options]]} {
+            if {[$regref installtype] eq "image" && [registry::run_target $regref activate [array get options]]} {
                 continue
             }
         }
@@ -2491,9 +2493,9 @@
             set iversion [lindex $i 1]
             set irevision [lindex $i 2]
             set ivariants [lindex $i 3]
-            if {$composite_version == "" || $composite_version == "${iversion}_${irevision}${ivariants}"} {
+            if {$composite_version eq "" || $composite_version == "${iversion}_${irevision}${ivariants}"} {
                 set regref [registry::entry open $portname $iversion $irevision $ivariants [lindex $i 5]]
-                if {[$regref installtype] == "image" && [registry::run_target $regref deactivate [array get options]]} {
+                if {[$regref installtype] eq "image" && [registry::run_target $regref deactivate [array get options]]} {
                     continue
                 }
             }
@@ -2652,7 +2654,7 @@
         return 1
     }
     # set or unset?
-    set val [string equal $action setrequested]
+    set val [string equal $action "setrequested"]
     foreachport $portlist {
         set composite_version [composite_version $portversion [array get variations]]
         if {![catch {set ilist [registry::installed $portname $composite_version]} result]} {
@@ -2713,7 +2715,7 @@
 
 
 proc action_version { action portlist opts } {
-    if ![macports::ui_isset ports_quiet] {
+    if {![macports::ui_isset ports_quiet]} {
         puts -nonewline "Version: "
     }
     puts [macports::version]
@@ -2722,7 +2724,7 @@
 
 
 proc action_platform { action portlist opts } {
-    if ![macports::ui_isset ports_quiet] {
+    if {![macports::ui_isset ports_quiet]} {
         puts -nonewline "Platform: "
     }
     puts "${macports::os_platform} ${macports::os_major} ${macports::os_arch}"
@@ -2759,15 +2761,15 @@
                 set index 0
             }
             # set portname again since the one we were passed may not have had the correct case
-            set portname [lindex [lindex $ilist $index] 0]
-            set iversion [lindex [lindex $ilist $index] 1]
-            set irevision [lindex [lindex $ilist $index] 2]
-            set ivariants [lindex [lindex $ilist $index] 3]
+            set portname [lindex $ilist $index 0]
+            set iversion [lindex $ilist $index 1]
+            set irevision [lindex $ilist $index 2]
+            set ivariants [lindex $ilist $index 3]
         }
         
         set deplist [registry::list_dependents $portname $iversion $irevision $ivariants]
         if { [llength $deplist] > 0 } {
-            if {$action == "rdependents"} {
+            if {$action eq "rdependents"} {
                 set toplist $deplist
                 while 1 {
                     set newlist {}
@@ -2877,8 +2879,8 @@
             set portdir [file split [macports::getportdir $porturl]]
             set lsize [llength $portdir]
             set portdir \
-                [file join [lindex $portdir [expr $lsize - 2]] \
-                           [lindex $portdir [expr $lsize - 1]]]
+                [file join [lindex $portdir [expr {$lsize - 2}]] \
+                           [lindex $portdir [expr {$lsize - 1}]]]
             if {[catch {mportsearch $portdir no exact portdir} result]} {
                 ui_debug "$::errorInfo"
                 break_softcontinue "Portdir $portdir not found" 1 status
@@ -2932,7 +2934,7 @@
         # get list of direct deps
         foreach type $deptypes {
             if {[info exists portinfo($type)]} {
-                if {$action == "rdeps" || [macports::ui_isset ports_verbose]} {
+                if {$action eq "rdeps" || [macports::ui_isset ports_verbose]} {
                     foreach dep $portinfo($type) {
                         lappend deplist $dep
                     }
@@ -2941,7 +2943,7 @@
                         lappend deplist [lindex [split $dep :] end]
                     }
                 }
-                if {$action == "deps"} {
+                if {$action eq "deps"} {
                     set label "$labeldict($type) Dependencies"
                     lappend deps_output [wraplabel $label [join $deplist ", "] 0 [string repeat " " 22]]
                     incr ndeps [llength $deplist]
@@ -2959,7 +2961,7 @@
         }
 
         puts -nonewline $separator
-        if {$action == "deps"} {
+        if {$action eq "deps"} {
             if {$ndeps == 0} {
                 ui_notice "$portname @${version}_${revision}${variants} has no dependencies."
             } else {
@@ -3130,7 +3132,7 @@
     set restrictedList 0
     set ilist {}
     
-    if { [llength $portlist] || (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) == "no")} {
+    if { [llength $portlist] || (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) eq "no")} {
         set restrictedList 1
         foreachport $portlist {
             set composite_version [composite_version $portversion [array get variations]]
@@ -3144,7 +3146,7 @@
         }
     } else {
         if { [catch {set ilist [registry::installed]} result] } {
-            if {$result != "Registry error: No ports registered as installed."} {
+            if {$result ne "Registry error: No ports registered as installed."} {
                 global errorInfo
                 ui_debug "$errorInfo"
                 ui_error "port installed failed: $result"
@@ -3171,10 +3173,10 @@
                 set os_platform [registry::property_retrieve $regref os_platform]
                 set os_major [registry::property_retrieve $regref os_major]
                 set archs [registry::property_retrieve $regref archs]
-                if {$os_platform != 0 && $os_platform != "" && $os_major != 0 && $os_major != ""} {
+                if {$os_platform != 0 && $os_platform ne "" && $os_major != 0 && $os_major ne ""} {
                     append extra " platform='$os_platform $os_major'"
                 }
-                if {$archs != 0 && $archs != ""} {
+                if {$archs != 0 && $archs ne ""} {
                     append extra " archs='$archs'"
                 }
             }
@@ -3201,7 +3203,7 @@
     # If port names were supplied, limit ourselves to those ports, else check all installed ports
     set ilist {}
     set restrictedList 0
-    if { [llength $portlist] || (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) == "no")} {
+    if { [llength $portlist] || (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) eq "no")} {
         set restrictedList 1
         foreach portspec $portlist {
             array set port $portspec
@@ -3217,7 +3219,7 @@
         }
     } else {
         if { [catch {set ilist [registry::installed]} result] } {
-            if {$result != "Registry error: No ports registered as installed."} {
+            if {$result ne "Registry error: No ports registered as installed."} {
                 global errorInfo
                 ui_debug "$errorInfo"
                 ui_error "port installed failed: $result"
@@ -3274,10 +3276,10 @@
             }
             
             # Compare versions, first checking epoch, then version, then revision
-            set epoch_comp_result [expr $installed_epoch - $latest_epoch]
+            set epoch_comp_result [expr {$installed_epoch - $latest_epoch}]
             set comp_result [vercmp $installed_version $latest_version]
             if { $comp_result == 0 } {
-                set comp_result [expr $installed_revision - $latest_revision]
+                set comp_result [expr {$installed_revision - $latest_revision}]
             }
             set reason ""
             if {$epoch_comp_result != 0 && $installed_version != $latest_version} {
@@ -3289,8 +3291,8 @@
                 set regref [registry::open_entry $portname $installed_version $installed_revision [lindex $i 3] $installed_epoch]
                 set os_platform_installed [registry::property_retrieve $regref os_platform]
                 set os_major_installed [registry::property_retrieve $regref os_major]
-                if {$os_platform_installed != "" && $os_platform_installed != 0
-                    && $os_major_installed != "" && $os_major_installed != 0
+                if {$os_platform_installed ne "" && $os_platform_installed != 0
+                    && $os_major_installed ne "" && $os_major_installed != 0
                     && ($os_platform_installed != ${macports::os_platform} || $os_major_installed != ${macports::os_major})} {
                     set comp_result -1
                     set reason { (platform $os_platform_installed $os_major_installed != ${macports::os_platform} ${macports::os_major})}
@@ -3354,7 +3356,7 @@
     foreachport $portlist {
         if { ![catch {set ilist [registry::installed $portname]} result] } {
             # set portname again since the one we were passed may not have had the correct case
-            set portname [lindex [lindex $ilist 0] 0]
+            set portname [lindex $ilist 0 0]
         }
         set files [registry::port_registered $portname]
         if { $files != 0 } {
@@ -3377,17 +3379,17 @@
 
 # expand abbreviations of size units
 proc complete_size_units {units} {
-    if {$units == "K" || $units == "Ki"} {
+    if {$units eq "K" || $units eq "Ki"} {
         return "KiB"
-    } elseif {$units == "k"} {
+    } elseif {$units eq "k"} {
         return "kB"
-    } elseif {$units == "Mi"} {
+    } elseif {$units eq "Mi"} {
         return "MiB"
-    } elseif {$units == "M"} {
+    } elseif {$units eq "M"} {
         return "MB"
-    } elseif {$units == "Gi"} {
+    } elseif {$units eq "Gi"} {
         return "GiB"
-    } elseif {$units == "G"} {
+    } elseif {$units eq "G"} {
         return "GB"
     } else {
         return $units
@@ -3411,17 +3413,17 @@
             if { [llength $files] > 0 } {
                 foreach file $files {
                     catch {
-                        set space [expr $space + [file size $file] ]
+                        set space [expr {$space + [file size $file]}]
                     }
                 }
-                if {![info exists options(ports_space_total)] || $options(ports_space_total) != "yes"} {
+                if {![info exists options(ports_space_total)] || $options(ports_space_total) ne "yes"} {
                     set msg "[bytesize $space $units] $portname"
                     if { $portversion != {} } {
                         append msg " @$portversion"
                     }
                     puts $msg
                 }
-                set spaceall [expr $space + $spaceall]
+                set spaceall [expr {$space + $spaceall}]
             } else {
                 puts stderr "Port $portname does not contain any file or is not active."
             }
@@ -3429,7 +3431,7 @@
             puts stderr "Port $portname is not installed."
         }
     }
-    if {[llength $portlist] > 1 || ([info exists options(ports_space_total)] && $options(ports_space_total) == "yes")} {
+    if {[llength $portlist] > 1 || ([info exists options(ports_space_total)] && $options(ports_space_total) eq "yes")} {
         puts "[bytesize $spaceall $units] total"
     }
     return 0
@@ -3558,7 +3560,7 @@
 proc action_search { action portlist opts } {
     global private_options global_options
     set status 0
-    if {![llength $portlist] && [info exists private_options(ports_no_args)] && $private_options(ports_no_args) == "yes"} {
+    if {![llength $portlist] && [info exists private_options(ports_no_args)] && $private_options(ports_no_args) eq "yes"} {
         ui_error "You must specify a search pattern"
         return 1
     }
@@ -3566,7 +3568,7 @@
     # Copy global options as we are going to modify the array
     array set options [array get global_options]
 
-    if {[info exists options(ports_search_depends)] && $options(ports_search_depends) == "yes"} {
+    if {[info exists options(ports_search_depends)] && $options(ports_search_depends) eq "yes"} {
         array unset options ports_search_depends
         set options(ports_search_depends_fetch) yes
         set options(ports_search_depends_extract) yes
@@ -3583,7 +3585,7 @@
     foreach { option } [array names options ports_search_*] {
         set opt [string range $option 13 end]
 
-        if { $options($option) != "yes" } {
+        if { $options($option) ne "yes" } {
             continue
         }
         switch -- $opt {
@@ -3619,7 +3621,7 @@
 
         set searchstring $portname
         set matchstyle $filter_matchstyle
-        if {$matchstyle == "none"} {
+        if {$matchstyle eq "none"} {
             # Guess if the given string was a glob expression, if not do a substring search
             if {[string first "*" $portname] == -1 && [string first "?" $portname] == -1} {
                 set searchstring "*$portname*"
@@ -3670,7 +3672,7 @@
                 puts $portinfo(name)
             } else {
                 if {[info exists options(ports_search_line)]
-                        && $options(ports_search_line) == "yes"} {
+                        && $options(ports_search_line) eq "yes"} {
                     # check for ports without category, e.g. replaced_by stubs
                     if {[info exists portinfo(categories)]} {
                         puts "$portinfo(name)\t$portinfo(version)\t$portinfo(categories)\t$portinfo(description)"
@@ -3700,7 +3702,7 @@
             ui_notice "No match for $portname found"
         } elseif {[llength $res] > 1} {
             if {(![info exists global_options(ports_search_line)]
-                    || $global_options(ports_search_line) != "yes")} {
+                    || $global_options(ports_search_line) ne "yes")} {
                 ui_notice "\nFound [llength $res] ports."
             }
         }
@@ -3720,12 +3722,12 @@
     set status 0
     
     # Default to list all ports if no portnames are supplied
-    if { ![llength $portlist] && [info exists private_options(ports_no_args)] && $private_options(ports_no_args) == "yes"} {
+    if { ![llength $portlist] && [info exists private_options(ports_no_args)] && $private_options(ports_no_args) eq "yes"} {
         add_to_portlist portlist [list name "-all-"]
     }
     
     foreachport $portlist {
-        if {$portname == "-all-"} {
+        if {$portname eq "-all-"} {
            if {[catch {set res [mportlistall]} result]} {
                 global errorInfo
                 ui_debug "$errorInfo"
@@ -3763,13 +3765,13 @@
         if {![macports::ui_isset ports_quiet]} {
             set opts {}
             foreach { key value } [array get options] {
-                if ![info exists global_options($key)] {
+                if {![info exists global_options($key)]} {
                     lappend opts "$key=$value"
                 }
             }
 
             set composite_version [composite_version $portversion [array get variations] 1]
-            if { $composite_version != "" } {
+            if { $composite_version ne "" } {
                 set ver_field "@$composite_version"
             } else {
                 set ver_field ""
@@ -3797,7 +3799,7 @@
     foreachport $portlist {
         array unset portinfo
         # If we have a url, use that, since it's most specific, otherwise try to map the portname to a url
-        if {$porturl == ""} {
+        if {$porturl eq ""} {
         
             # Verify the portname, getting portinfo to map to a porturl
             if {[catch {set res [mportlookup $portname]} result]} {
@@ -3839,7 +3841,7 @@
                     # may want stuff from it as well, like TERM.
                     array unset env_save; array set env_save [array get env]
                     array unset env *
-                    if {${macports::macosx_version} == "10.5"} {
+                    if {${macports::macosx_version} eq "10.5"} {
                         unsetenv *
                     }
                     array set env [array get boot_env]
@@ -3859,7 +3861,7 @@
                     }
                     
                     # Use a reasonable canned default if no editor specified or set in env
-                    if { $editor == "" } { set editor "/usr/bin/vi" }
+                    if { $editor eq "" } { set editor "/usr/bin/vi" }
                     
                     # Invoke the editor
                     if {[catch {eval exec >@stdout <@stdin 2>@stderr $editor {$portfile}} result]} {
@@ -3870,7 +3872,7 @@
                     
                     # Restore internal MacPorts environment
                     array unset env *
-                    if {${macports::macosx_version} == "10.5"} {
+                    if {${macports::macosx_version} eq "10.5"} {
                         unsetenv *
                     }
                     array set env [array get env_save]
@@ -3923,7 +3925,7 @@
                     }
 
                     # If not available, get the homepage for the port by opening the Portfile
-                    if {$homepage == "" && ![catch {set ctx [mportopen $porturl]} result]} {
+                    if {$homepage eq "" && ![catch {set ctx [mportopen $porturl]} result]} {
                         array set portinfo [mportinfo $ctx]
                         if {[info exists portinfo(homepage)]} {
                             set homepage $portinfo(homepage)
@@ -3932,7 +3934,7 @@
                     }
 
                     # Try to open a browser to the homepage for the given port
-                    if { $homepage != "" } {
+                    if { $homepage ne "" } {
                         if {[catch {system "${macports::autoconf::open_path} '$homepage'"} result]} {
                             global errorInfo
                             ui_debug "$errorInfo"
@@ -3973,14 +3975,14 @@
     if {[require_portlist portlist]} {
         return 1
     }
-    if {($action == "install" || $action == "archive") && [prefix_unwritable] && ![macports::global_option_isset ports_dryrun]} {
+    if {($action eq "install" || $action eq "archive") && [prefix_unwritable] && ![macports::global_option_isset ports_dryrun]} {
         return 1
     }
     foreachport $portlist {
         array unset portinfo
         # If we have a url, use that, since it's most specific
         # otherwise try to map the portname to a url
-        if {$porturl == ""} {
+        if {$porturl eq ""} {
             # Verify the portname, getting portinfo to map to a porturl
             if {[catch {set res [mportlookup $portname]} result]} {
                 global errorInfo
@@ -4001,7 +4003,7 @@
         }
 
         # use existing variants iff none were explicitly requested
-        if {[array get requested_variations] == "" && [array get variations] != ""} {
+        if {[array get requested_variations] eq "" && [array get variations] ne ""} {
             array unset requested_variations
             array set requested_variations [array get variations]
         }
@@ -4020,13 +4022,13 @@
             set options(ports_version_glob) $portversion
         }
         # if installing, mark the port as explicitly requested
-        if {$action == "install"} {
+        if {$action eq "install"} {
             if {![info exists options(ports_install_unrequested)]} {
                 set options(ports_requested) 1
             }
             # we actually activate as well
             set target activate
-        } elseif {$action == "archive"} {
+        } elseif {$action eq "archive"} {
             set target install
         } else {
             set target $action
@@ -4059,7 +4061,7 @@
         }
     }
     
-    if {$status == 0 && $action == "install" && ![macports::global_option_isset ports_dryrun]} {
+    if {$status == 0 && $action eq "install" && ![macports::global_option_isset ports_dryrun]} {
         array set options $opts
         if {![info exists options(ports_nodeps)] && ![info exists options(ports_install_no-rev-upgrade)] && ${macports::revupgrade_autorun}} {
             set status [action_revupgrade $action $portlist $opts]
@@ -4366,9 +4368,9 @@
     while {[moreargs]} {
         set arg [lookahead]
         
-        if {[string index $arg 0] != "-"} {
+        if {[string index $arg 0] ne "-"} {
             break
-        } elseif {[string index $arg 1] == "-"} {
+        } elseif {[string index $arg 1] eq "-"} {
             # Process long arguments
             switch -- $arg {
                 -- { # This is the options terminator; do no further option processing
@@ -4386,8 +4388,8 @@
                         }
                         return -code error "\"port ${action} --${key}\" is ambiguous: \n  port ${action} [join $errlst "\n  port ${action} "]"
                     }
-                    set key   [lindex [lindex $kopts 0] 0]
-                    set kargc [lindex [lindex $kopts 0] 1]
+                    set key   [lindex $kopts 0 0]
+                    set kargc [lindex $kopts 0 1]
                     if {$kargc == 0} {
                         set global_options(ports_${action}_${key}) yes
                     } else {
@@ -4395,10 +4397,10 @@
                         while {[moreargs] && $kargc > 0} {
                             advance
                             lappend args [lookahead]
-                            set kargc [expr $kargc - 1]
+                            set kargc [expr {$kargc - 1}]
                         }
                         if {$kargc > 0} {
-                            return -code error "--${key} expects [expr $kargc + [llength $args]] parameters!"
+                            return -code error "--${key} expects [expr {$kargc + [llength $args]}] parameters!"
                         }
                         set global_options(ports_${action}_${key}) $args
                     }
@@ -4670,7 +4672,7 @@
     }
 
     # Decide how to do completion based on where we are in the string
-    set prefix [string range $text 0 [expr $start - 1]]
+    set prefix [string range $text 0 [expr {$start - 1}]]
     
     # If only whitespace characters preceed us, or if the
     # previous non-whitespace character was a ;, then we're
@@ -4688,7 +4690,7 @@
     upvar $linename line
     
     set line ""
-    while { $line == "" } {
+    while { $line eq "" } {
 
         if {$use_readline} {
             set len [readline read -attempted_completion attempt_completion line $prompt]
@@ -4704,7 +4706,7 @@
         
         set line [string trim $line]
 
-        if { $use_readline && $line != "" } {
+        if { $use_readline && $line ne "" } {
             rl_history add $line
         }
     }
@@ -4719,7 +4721,7 @@
     # Initialize readline
     set isstdin [string match $in "stdin"]
     set name "port"
-    set use_readline [expr $isstdin && [readline init $name]]
+    set use_readline [expr {$isstdin && [readline init $name]}]
     set history_file [file normalize "${macports::macports_user_dir}/history"]
 
     # Read readline history
@@ -4787,7 +4789,7 @@
     # For each file in the command list, process commands
     # in the file
     foreach file $filelist {
-        if {$file == "-"} {
+        if {$file eq "-"} {
             set in stdin
         } else {
             if {[catch {set in [open $file]} result]} {
@@ -4797,7 +4799,7 @@
 
         set exit_status [process_command_file $in]
 
-        if {$in != "stdin"} {
+        if {$in ne "stdin"} {
             close $in
         }
 
@@ -4810,7 +4812,229 @@
     return $exit_status
 }
 
+##
+# Progress callback for generic operations executed by macports 1.0.
+#
+# @param action
+#        One of "start", "update", "intermission" or "finish", where start will
+#        be called before any number of update calls, interrupted by any number
+#        of intermission calls (called because other output is being produced),
+#        followed by one call to finish.
+# @param args
+#        A list of variadic args that differ for each action.
+#        For "start": empty.
+#        For "update": contains the arguments $cur and $total where $cur is the
+#        current number of units processed and $total is the total number of
+#        units to be processed.
+#        For "intermission": empty.
+#        For "finish": empty.
+proc port_progress_generic {action args} {
+    global _port_progress_starttime _port_progress_display_bar
+    switch -nocase -- $action {
+        start {
+            set _port_progress_starttime [clock milliseconds]
+            set _port_progress_display_bar no
+        }
+        update {
+            # the for loop is a simple hack because Tcl 8.4 doesn't have
+            # lassign
+            foreach {now total} $args {
+                if {${_port_progress_display_bar} ne yes} {
+                    # check whether we should show a progress bar for this transfer
+                    if {[expr {[clock milliseconds] - ${_port_progress_starttime}}] > 500 && ($total == 0 || [expr {$now / $total}] < 0.5)} {
+                        # wait 500ms, then, if we don't know the total or we're
+                        # not past 50% yet, display a progress bar.
+                        set _port_progress_display_bar yes
+                    }
+                }
+                if {${_port_progress_display_bar} eq yes} {
+                    set barprefix "      "
+                    if {$total != 0} {
+                        progress_bar $now $total 20 $barprefix
+                    } else {
+                        unprogress_bar $now 20 $barprefix
+                    }
+                }
+            }
+        }
+        intermission -
+        finish {
+            # erase to start of line
+            ::term::ansi::send::esol
+            # return cursor to start of line
+            puts -nonewline "\r"
+            flush stdout
+        }
+    }
 
+    return 0
+}
+
+
+##
+# Progress callback for downloads executed by macports 1.0.
+#
+# This is essentially a cURL progress callback.
+#
+# @param action
+#        One of "start", "update" or "finish", where start will be called
+#        before any number of update calls, followed by one call to finish.
+# @param args
+#        A list of variadic args that differ for each action.
+#        For "start": contains a single argument "ul" or "dl" indicating
+#        whether this is an up- or download.
+#        For "update": contains the arguments ("ul"|"dl") total now speed where
+#        ul/dl are as for start, and total, now and speed are doubles
+#        indicating the total transfer size, currently transferred amount and
+#        average speed per second in bytes.
+#        For "finish": empty.
+proc port_progress_download {action args} {
+    global _port_progress_starttime _port_progress_display_bar
+    switch -nocase -- $action {
+        start {
+            set _port_progress_starttime [clock milliseconds]
+            set _port_progress_display_bar no
+        }
+        update {
+            # the for loop is a simple hack because Tcl 8.4 doesn't have
+            # lassign
+            foreach {type total now speed} $args {
+                if {${_port_progress_display_bar} ne yes} {
+                    # check whether we should show a progress bar for this transfer
+                    if {[expr {[clock milliseconds] - ${_port_progress_starttime}}] > 500 && ($total == 0 || [expr {$now / $total}] < 0.5)} {
+                        # wait 500ms, then, if we don't know the total or we're
+                        # not past 50% yet, display a progress bar.
+                        set _port_progress_display_bar yes
+                    }
+                }
+                if {${_port_progress_display_bar} eq yes} {
+                    set barprefix "      "
+                    if {$total != 0} {
+                        set barsuffix [format "        speed: %-13s" "[bytesize $speed {} "%.1f"]/s"]
+                        progress_bar $now $total 20 $barprefix $barsuffix
+                    } else {
+                        set barsuffix [format " %-10s     speed: %-13s" [bytesize $now {} "%6.1f"] "[bytesize $speed {} "%.1f"]/s"]
+                        unprogress_bar $now 20 $barprefix $barsuffix
+                    }
+                }
+            }
+        }
+        finish {
+            # erase to start of line
+            ::term::ansi::send::esol
+            # return cursor to start of line
+            puts -nonewline "\r"
+            flush stdout
+        }
+    }
+
+    return 0
+}
+
+##
+# Draw a progress bar using unicode block drawing characters
+#
+# @param current
+#        the current progress value
+# @param total
+#        the progress value representing 100%
+# @param halfwidth
+#        the half width in characters of the progress bar
+# @param prefix
+#        prefix to be printed in front of the progress bar
+# @param suffix
+#        suffix to be printed after the progress bar
+proc progress_bar {current total halfwidth {prefix ""} {suffix ""}} {
+    # we use 8 different states per character, so let's multiply the width by
+    # 8 and map the percentage to this range
+    set percent [expr {(double($current) * 100 / double($total))}]
+    set progress [expr {int(round(($current * $halfwidth * 8) / $total))}]
+    set fullfields [expr {int($progress / 8)}]
+    set remainder [expr {$progress % 8}]
+
+    # clear the current line
+    set progressbar ""
+    for {set i 0} {$i < $fullfields} {incr i} {
+        # U+2588 FULL BLOCK doesn't match the other blocks in some fonts :/
+        # Use two half blocks instead
+        # Since we use two chars here, make sure to remove a space for each of
+        # those used!
+        append progressbar "\u258c\u258c"
+    }
+
+    if {$remainder == 0 && $fullfields < $halfwidth} {
+        append progressbar " "
+    } elseif {$remainder == 1} {
+        # U+258F LEFT ONE EIGHTH BLOCK
+        append progressbar "\u258f"
+    } elseif {$remainder == 2} {
+        # U+258E LEFT ONE QUARTER BLOCK
+        append progressbar "\u258e"
+    } elseif {$remainder == 3} {
+        # U+258D LEFT THREE EIGHTHS BLOCK
+        append progressbar "\u258d"
+    } elseif {$remainder == 4} {
+        # U+258C LEFT HALF BLOCK
+        append progressbar "\u258c"
+    } elseif {$remainder == 5} {
+        # U+258B LEFT FIVE EIGHTHS BLOCK
+        append progressbar "\u258b"
+    } elseif {$remainder == 6} {
+        # U+258A LEFT THREE QUARTERS BLOCK
+        append progressbar "\u258a"
+    } elseif {$remainder == 7} {
+        # U+2589 LEFT SEVEN EIGHTHS BLOCK
+        append progressbar "\u2589"
+    }
+
+    for {set i [expr {[string length $progressbar]}]} {$i < [expr {2 * $halfwidth}]} {incr i} {
+        append progressbar " "
+    }
+    set percentagesuffix [format " %5.1f %%" $percent]
+
+    puts -nonewline "\r${prefix}\[${progressbar}\]${percentagesuffix}${suffix}"
+    flush stdout
+}
+
+##
+# Draw a progress indicator
+#
+# @param current
+#        the number of bytes currently downloaded
+# @param halfwidth
+#        the half width in characters of the progress indicator
+# @param prefix
+#        prefix to be printed in front of the progress indicator
+# @param suffix
+#        suffix to be printed after the progress indicator
+proc unprogress_bar {current halfwidth {prefix ""} {suffix ""}} {
+    global _port_progress_unprogressbar_state
+
+    set numstates 4
+
+    if {![info exists _port_progress_unprogressbar_state]} {
+        set _port_progress_unprogressbar_state 0
+    } else {
+        set _port_progress_unprogressbar_state [expr {(${_port_progress_unprogressbar_state} + 1) % $numstates}]
+    }
+
+    # clear the current line
+    set progressbar ""
+
+    for {set i 0} {$i < [expr {2 * $halfwidth}]} {incr i} {
+        if {[expr $i % $numstates] == ${_port_progress_unprogressbar_state}} {
+            # U+2022 BULLET
+            append progressbar "\u2022"
+        } else {
+            append progressbar " "
+        }
+    }
+
+    puts -nonewline "\r${prefix}\[${progressbar}\]${suffix}"
+    flush stdout
+}
+
+
 ##########################################
 # Main
 ##########################################
@@ -4846,7 +5070,7 @@
 # If we've been invoked as portf, then the first argument is assumed
 # to be the name of a command file (i.e., there is an implicit -F
 # before any arguments).
-if {[moreargs] && $cmdname == "portf"} {
+if {[moreargs] && $cmdname eq "portf"} {
     lappend ui_options(ports_commandfiles) [lookahead]
     advance
 }
@@ -4858,6 +5082,11 @@
     exit 1
 }
 
+if {[isatty stdout] && (![info exists ui_options(ports_quiet)] || $ui_options(ports_quiet) ne "yes")} {
+    set ui_options(progress_download) port_progress_download
+    set ui_options(progress_generic)  port_progress_generic
+}
+
 # Get arguments remaining after option processing
 set remaining_args [lrange $cmd_argv $cmd_argn end]
 
@@ -4865,7 +5094,7 @@
 # interactive mode
 if { [llength $remaining_args] == 0 && ![info exists ui_options(ports_commandfiles)] } {
     lappend ui_options(ports_commandfiles) -
-} elseif {[lookahead] == "selfupdate" || [lookahead] == "sync"} {
+} elseif {[lookahead] eq "selfupdate" || [lookahead] eq "sync"} {
     # tell mportinit not to tell the user they should selfupdate
     set ui_options(ports_no_old_index_warning) 1
 }

Modified: branches/new-help-system/base/src/port/portindex.tcl
===================================================================
--- branches/new-help-system/base/src/port/portindex.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port/portindex.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -39,7 +39,7 @@
            ui_options port_options save_prefix keepkeys
 
     # try to reuse the existing entry if it's still valid
-    if {$full_reindex != "1" && [info exists qindex([string tolower [file tail $portdir]])]} {
+    if {$full_reindex != 1 && [info exists qindex([string tolower [file tail $portdir]])]} {
         try {
             set mtime [file mtime [file join $directory $portdir Portfile]]
             if {$oldmtime >= $mtime} {
@@ -102,12 +102,12 @@
 
         foreach availkey [array names portinfo] {
             # store list of subports for top-level ports only
-            if {![info exists keepkeys($availkey)] && $availkey != "subports"} {
+            if {![info exists keepkeys($availkey)] && $availkey ne "subports"} {
                 unset portinfo($availkey)
             }
         }
         set output [array get portinfo]
-        set len [expr [string length $output] + 1]
+        set len [expr {[string length $output] + 1}]
         puts $fd [list $portinfo(name) $len]
         puts $fd $output
         set mtime [file mtime [file join $directory $portdir Portfile]]
@@ -138,7 +138,7 @@
                     }
                 }
                 set output [array get portinfo]
-                set len [expr [string length $output] + 1]
+                set len [expr {[string length $output] + 1}]
                 puts $fd [list $portinfo(name) $len]
                 puts $fd $output
             }
@@ -146,7 +146,7 @@
     }
 }
 
-if {[expr $argc > 8]} {
+if {$argc > 8} {
     print_usage
     exit 1
 }
@@ -155,23 +155,23 @@
     set arg [lindex $argv $i]
     switch -regex -- $arg {
         {^-.+} {
-            if {$arg == "-d"} { # Turn on debug output
+            if {$arg eq "-d"} { # Turn on debug output
                 set ui_options(ports_debug) yes
-            } elseif {$arg == "-o"} { # Set output directory
+            } elseif {$arg eq "-o"} { # Set output directory
                 incr i
                 set outdir [file join [pwd] [lindex $argv $i]]
-            } elseif {$arg == "-p"} { # Set platform
+            } elseif {$arg eq "-p"} { # Set platform
                 incr i
                 set platlist [split [lindex $argv $i] _]
                 set os_platform [lindex $platlist 0]
                 set os_major [lindex $platlist 1]
                 set os_arch [lindex $platlist 2]
-                if {$os_platform == "macosx"} {
+                if {$os_platform eq "macosx"} {
                     lappend port_options os.subplatform $os_platform os.universal_supported yes
                     set os_platform darwin
                 }
                 lappend port_options os.platform $os_platform os.major $os_major os.arch $os_arch
-            } elseif {$arg == "-f"} { # Completely rebuild index
+            } elseif {$arg eq "-f"} { # Completely rebuild index
                 set full_reindex 1
             } else {
                 puts stderr "Unknown option: $arg"
@@ -249,6 +249,6 @@
 file mtime $outpath $newest
 mports_generate_quickindex $outpath
 puts "\nTotal number of ports parsed:\t$stats(total)\
-      \nPorts successfully parsed:\t[expr $stats(total) - $stats(failed)]\
+      \nPorts successfully parsed:\t[expr {$stats(total) - $stats(failed)}]\
       \nPorts failed:\t\t\t$stats(failed)\
       \nUp-to-date ports skipped:\t$stats(skipped)\n"

Modified: branches/new-help-system/base/src/port/portmirror.tcl
===================================================================
--- branches/new-help-system/base/src/port/portmirror.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port/portmirror.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -82,7 +82,7 @@
     puts "Usage: $argv0"
 }
 
-if {[expr $argc > 0]} {
+if {$argc > 0} {
     print_usage
     exit 1
 }


Property changes on: branches/new-help-system/base/src/port1.0
___________________________________________________________________
Modified: svn:ignore
   - port_autoconf.tcl
pkgIndex.tcl

   + port_autoconf.tcl
port_test_autoconf.tcl
pkgIndex.tcl


Modified: branches/new-help-system/base/src/port1.0/Makefile
===================================================================
--- branches/new-help-system/base/src/port1.0/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -23,7 +23,7 @@
 	rm -f pkgIndex.tcl
 
 distclean:: clean
-	rm -f port_autoconf.tcl
+	rm -f port_autoconf.tcl port_test_autoconf.tcl
 
 install:: all
 	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} ${INSTALLDIR}
@@ -33,6 +33,4 @@
 	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 pkgIndex.tcl ${INSTALLDIR}
 
 test::
-	${TCLSH} tests/portutil.tcl ${macports_tcl_dir}
-	${TCLSH} tests/portdestroot.tcl ${macports_tcl_dir}
-	${TCLSH} tests/portfetch.tcl ${macports_tcl_dir}
+	$(TCLSH) ./tests/test.tcl -nocolor

Modified: branches/new-help-system/base/src/port1.0/fetch_common.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/fetch_common.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/fetch_common.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -48,7 +48,7 @@
 # percent-encode all characters in str that are not unreserved in URIs
 proc portfetch::percent_encode {str} {
     set outstr ""
-    while {[string length $str] > 0} {
+    while {$str ne ""} {
         set char [string index $str 0]
         set str [string range $str 1 end]
         switch -- $char {
@@ -75,7 +75,7 @@
 # Given a site url and the name of the distfile, assemble url and
 # return it.
 proc portfetch::assemble_url {site distfile} {
-    if {[string index $site end] != "/"} {
+    if {[string index $site end] ne "/"} {
         append site /
     }
     return "${site}[percent_encode ${distfile}]"
@@ -106,11 +106,11 @@
         # tag will be after the last colon after the
         # first slash after the ://
         set lastcolon [string last : $element]
-        set aftersep [expr [string first : $element] + 3]
+        set aftersep [expr {[string first : $element] + 3}]
         set firstslash [string first / $element $aftersep]
         if {$firstslash != -1 && $firstslash < $lastcolon} {
-            set mirror_tag [string range $element [expr $lastcolon + 1] end]
-            set element [string range $element 0 [expr $lastcolon - 1]]
+            set mirror_tag [string range $element [expr {$lastcolon + 1}] end]
+            set element [string range $element 0 [expr {$lastcolon - 1}]]
         } else {
             set mirror_tag ""
         }
@@ -122,9 +122,9 @@
             set mirror_tag ""
         }
 
-        if {$mirror_tag == "mirror"} {
+        if {$mirror_tag eq "mirror"} {
             set thesubdir ${dist_subdir}
-        } elseif {$subdir == "" && $mirror_tag != "nosubdir"} {
+        } elseif {$subdir eq "" && $mirror_tag ne "nosubdir"} {
             set thesubdir ${name}
         } else {
             set thesubdir ${subdir}
@@ -192,10 +192,10 @@
         # add in the global, fallback and user-defined mirrors for each tag
         foreach site $site_list {
             if {[regexp {([a-zA-Z]+://.+/?):([0-9A-Za-z_-]+)$} $site match site tag] && ![info exists extras_added($tag)]} {
-                if {$sglobal != ""} {
+                if {$sglobal ne ""} {
                     set site_list [concat $site_list [mirror_sites $sglobal $tag "" $mirrorfile]]
                 }
-                if {$sfallback != ""} {
+                if {$sfallback ne ""} {
                     set site_list [concat $site_list [mirror_sites $sfallback $tag "" $mirrorfile]]
                 }
                 if {[info exists env($senv)]} {
@@ -247,7 +247,7 @@
         }
 
         foreach site $urllist {
-            if {[string range $site 0 6] == "file://"} {
+            if {[string range $site 0 6] eq "file://"} {
                 set pingtimes(localhost) 0
                 continue
             }
@@ -299,7 +299,7 @@
 
         set pinglist {}
         foreach site $urllist {
-            if {[string range $site 0 6] == "file://"} {
+            if {[string range $site 0 6] eq "file://"} {
                 set host localhost
             } else {
                 regexp $hostregex $site -> host
@@ -343,6 +343,6 @@
 proc portfetch::check_dns {} {
     # check_broken_dns returns true at most once, so we don't have to worry about spamming this message
     if {[check_broken_dns]} {
-        ui_warn "Your DNS servers incorrectly claim to know the address of nonexistent hosts. This may cause checksum mismatches for some ports."
+        ui_warn "Your DNS servers incorrectly claim to know the address of nonexistent hosts. This may cause checksum mismatches for some ports. See this page for more information: <https://trac.macports.org/wiki/MisbehavingServers>"
     }
 }

Copied: branches/new-help-system/base/src/port1.0/port_test_autoconf.tcl.in (from rev 117083, trunk/base/src/port1.0/port_test_autoconf.tcl.in)
===================================================================
--- branches/new-help-system/base/src/port1.0/port_test_autoconf.tcl.in	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/port_test_autoconf.tcl.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,37 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
+# macports-autoconf.tcl.in
+# $Id: macports_autoconf.tcl.in 90070 2012-02-20 21:54:35Z jberry at macports.org $
+#
+# Copyright (c) 2006 - 2009, 2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Apple Inc. nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+namespace eval macports::autoconf {
+    variable macports_tcl_dir "@macports_tcl_dir@"
+    variable prefix "@prefix@"
+}

Modified: branches/new-help-system/base/src/port1.0/portactivate.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portactivate.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portactivate.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -43,6 +43,7 @@
 target_provides ${org.macports.activate} activate
 target_requires ${org.macports.activate} main archivefetch fetch checksum extract patch configure build destroot install
 target_prerun ${org.macports.activate} portactivate::activate_start
+target_postrun ${org.macports.activate} portactivate::activate_finish
 
 namespace eval portactivate {
 }
@@ -97,10 +98,18 @@
         ui_notice ""
     }
 
+    return 0
+}
+
+proc portactivate::activate_finish {args} {
+    global subport startupitem.autostart UI_PREFIX
+
+    # Do this _after_ activate_main, because post-activate hooks might create
+    # the files needed for this
     if {[tbool startupitem.autostart]} {
-        ui_notice "$UI_PREFIX [format [msgcat::mc "Loading %s"] [option subport]]"
+        ui_notice "$UI_PREFIX [format [msgcat::mc "Loading %s"] $subport]"
         if {[eval_targets "load"]} {
-            ui_error [format [msgcat::mc "Failed to load %s"] [option subport]]
+            ui_error [format [msgcat::mc "Failed to load %s"] $subport]
             return 1
         }
     }

Modified: branches/new-help-system/base/src/port1.0/portbuild.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portbuild.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portbuild.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -69,12 +69,12 @@
     if {!${build.type.add_deps}} {
         return
     }
-    if {[option build.type] == "bsd" && [option os.platform] == "darwin"} {
+    if {[option build.type] eq "bsd" && [option os.platform] eq "darwin"} {
         ui_debug "build.type is BSD, adding bin:bsdmake:bsdmake build dependency"
         depends_build-delete bin:bsdmake:bsdmake
         depends_build-append bin:bsdmake:bsdmake
     }
-    if {[option build.type] == "gnu" && [option os.platform] == "freebsd"} {
+    if {[option build.type] eq "gnu" && [option os.platform] eq "freebsd"} {
         ui_debug "build.type is GNU, adding bin:gmake:gmake build dependency"
         depends_build-delete bin:gmake:gmake
         depends_build-append bin:gmake:gmake
@@ -87,23 +87,23 @@
 default build.type.add_deps yes
 
 proc portbuild::build_getmaketype {args} {
-    if {[option build.type] == "default"} {
+    if {[option build.type] eq "default"} {
         return [findBinary make $portutil::autoconf::make_path]
     }
     switch -exact -- [option build.type] {
         bsd {
-            if {[option os.platform] == "darwin"} {
+            if {[option os.platform] eq "darwin"} {
                 return [findBinary bsdmake $portutil::autoconf::bsdmake_path]
-            } elseif {[option os.platform] == "freebsd"} {
+            } elseif {[option os.platform] eq "freebsd"} {
                 return [findBinary make $portutil::autoconf::make_path]
             } else {
                 return [findBinary pmake $portutil::autoconf::bsdmake_path]
             }
         }
         gnu {
-            if {[option os.platform] == "darwin"} {
+            if {[option os.platform] eq "darwin"} {
                 return [findBinary gnumake $portutil::autoconf::gnumake_path]
-            } elseif {[option os.platform] == "linux"} {
+            } elseif {[option os.platform] eq "linux"} {
                 return [findBinary make $portutil::autoconf::make_path]
             } else {
                 return [findBinary gmake $portutil::autoconf::gnumake_path]
@@ -111,12 +111,12 @@
         }
         pbx -
         xcode {
-            if {[option os.platform] != "darwin"} {
+            if {[option os.platform] ne "darwin"} {
                 return -code error "[format [msgcat::mc "This port requires 'xcodebuild', which is not available on %s."] [option os.platform]]"
             }
 
             global xcodebuildcmd
-            if {$xcodebuildcmd != "none"} {
+            if {$xcodebuildcmd ne "none"} {
                 return $xcodebuildcmd
             } else {
                 return -code error "xcodebuild was not found on this system!"
@@ -140,7 +140,7 @@
             ui_warn "defaulting to $jobs jobs, consider setting buildmakejobs to a nonzero value in macports.conf"
         }
         if {[info exists memsize] && $jobs > $memsize / 1000000000 + 1} {
-            set jobs [expr $memsize / 1000000000 + 1]
+            set jobs [expr {$memsize / 1000000000 + 1}]
         }
     }
     if {![string is integer -strict $jobs] || $jobs <= 1} {
@@ -150,8 +150,8 @@
 }
 
 proc portbuild::build_getargs {args} {
-    if {(([option build.type] == "default" && [option os.platform] != "freebsd") || \
-         ([option build.type] == "gnu")) \
+    if {(([option build.type] eq "default" && [option os.platform] ne "freebsd") || \
+         ([option build.type] eq "gnu")) \
         && [regexp "^(/\\S+/|)(g|gnu|)make(\\s+.*|)$" [option build.cmd]]} {
         # Print "Entering directory" lines for better log debugging
         return "-w [option build.target]"

Modified: branches/new-help-system/base/src/port1.0/portchecksum.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portchecksum.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portchecksum.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -53,13 +53,13 @@
 set_ui_prefix
 
 # The list of the types of checksums we know.
-set checksum_types "md5 sha1 rmd160 sha256"
+set checksum_types [list md5 sha1 rmd160 sha256 size]
 
 # The number of types we know.
 set checksum_types_count [llength $checksum_types]
 
 # types to recommend if none are specified in the portfile
-set default_checksum_types {rmd160 sha256}
+set default_checksum_types [list rmd160 sha256]
 
 # Using global all_dist_files, parse the checksums and store them into the
 # global array checksums_array.
@@ -82,8 +82,8 @@
     set nb_checksum [llength $checksums_str]
 
     if {[llength $all_dist_files] == 1
-        && [expr $nb_checksum % 2] == 0
-        && [expr $nb_checksum / 2] <= $checksum_types_count
+        && [expr {$nb_checksum % 2}] == 0
+        && [expr {$nb_checksum / 2}] <= $checksum_types_count
         && [lsearch -exact $checksum_types [lindex $checksums_str 0]] >= 0} {
         # Convert to format #2
         set checksums_str [linsert $checksums_str 0 [lindex $all_dist_files 0]]
@@ -185,6 +185,15 @@
     return [sha256 file $file]
 }
 
+# calc_size
+#
+# Get the size of the given file.
+# Return the size.
+#
+proc portchecksum::calc_size {file} {
+    return [file size $file]
+}
+
 # checksum_start
 #
 # Target prerun procedure; simply prints a message about what we're doing.
@@ -226,7 +235,7 @@
 
     # if everything is fine with the syntax, keep on and check the checksum of
     # the distfiles.
-    if {[parse_checksums $checksums_str] == "yes"} {
+    if {[parse_checksums $checksums_str] eq "yes"} {
         set distpath [option distpath]
 
         foreach distfile $all_dist_files {
@@ -264,7 +273,11 @@
                 foreach {type sum} $portfile_checksums {
                     set calculated_sum [calc_$type $fullpath]
                     lappend sums [format "%-8s%s" $type $calculated_sum]
-                    if {[string equal $sum $calculated_sum]} {
+
+		    # Used for regression testing
+                    ui_debug "[format [msgcat::mc "Calculated (%s) is %s"] $type $calculated_sum]"
+
+                    if {$sum eq $calculated_sum} {
                         ui_debug "[format [msgcat::mc "Correct (%s) checksum for %s"] $type $distfile]"
                     } else {
                         ui_error "[format [msgcat::mc "Checksum (%s) mismatch for %s"] $type $distfile]"

Modified: branches/new-help-system/base/src/port1.0/portclean.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portclean.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portclean.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -67,26 +67,26 @@
         ui_warn "Only cleaning in ~/.macports; insufficient privileges for standard locations"
     }
 
-    if {[info exists ports_clean_all] && $ports_clean_all == "yes" || \
-        [info exists ports_clean_dist] && $ports_clean_dist == "yes"} {
+    if {[info exists ports_clean_all] && $ports_clean_all eq "yes" || \
+        [info exists ports_clean_dist] && $ports_clean_dist eq "yes"} {
         ui_info "$UI_PREFIX [format [msgcat::mc "Removing distfiles for %s"] [option subport]]"
         clean_dist
     }
-    if {([info exists ports_clean_all] && $ports_clean_all == "yes" || \
-        [info exists ports_clean_archive] && $ports_clean_archive == "yes")
+    if {([info exists ports_clean_all] && $ports_clean_all eq "yes" || \
+        [info exists ports_clean_archive] && $ports_clean_archive eq "yes")
         && !$usealtworkpath} {
         ui_info "$UI_PREFIX [format [msgcat::mc "Removing temporary archives for %s"] [option subport]]"
         clean_archive
     }
-    if {[info exists ports_clean_all] && $ports_clean_all == "yes" || \
-        [info exists ports_clean_work] && $ports_clean_work == "yes" || \
-        [info exists ports_clean_archive] && $ports_clean_archive == "yes" || \
-        [info exists ports_clean_dist] && $ports_clean_dist == "yes" || \
-        !([info exists ports_clean_logs] && $ports_clean_logs == "yes")} {
+    if {[info exists ports_clean_all] && $ports_clean_all eq "yes" || \
+        [info exists ports_clean_work] && $ports_clean_work eq "yes" || \
+        [info exists ports_clean_archive] && $ports_clean_archive eq "yes" || \
+        [info exists ports_clean_dist] && $ports_clean_dist eq "yes" || \
+        !([info exists ports_clean_logs] && $ports_clean_logs eq "yes")} {
          ui_info "$UI_PREFIX [format [msgcat::mc "Removing work directory for %s"] [option subport]]"
          clean_work
     }
-    if {(([info exists ports_clean_logs] && $ports_clean_logs == "yes") || ($keeplogs == "no"))
+    if {(([info exists ports_clean_logs] && $ports_clean_logs eq "yes") || ($keeplogs eq "no"))
         && !$usealtworkpath} {
         clean_logs
     }
@@ -165,7 +165,7 @@
     # or if user forces us to
     set dirlist [list]
     if {$dist_subdir != $name} {
-        if {!([info exists ports_force] && $ports_force == "yes")
+        if {!([info exists ports_force] && $ports_force eq "yes")
             && [file isdirectory $distpath]
             && [llength [readdir $distpath]] > 0} {
             ui_warn [format [msgcat::mc "Distfiles directory '%s' may contain distfiles needed for other ports, use the -f flag to force removal" ] $distpath]
@@ -291,7 +291,7 @@
             # delete anything ending in .TMP since those are incomplete and
             # thus can't be checked and aren't useful anyway.
             set archivetype [string range [file extension $path] 1 end]
-            if {[file isfile $path] && ($archivetype == "TMP"
+            if {[file isfile $path] && ($archivetype eq "TMP"
                 || [extract_archive_metadata $path $archivetype portname] == $subport)} {
                 ui_debug "Removing archive: $path"
                 if {[catch {delete $path} result]} {

Modified: branches/new-help-system/base/src/port1.0/portconfigure.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portconfigure.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portconfigure.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
 # $Id$
 #
-# Copyright (c) 2007 - 2013 The MacPorts Project
+# Copyright (c) 2007 - 2014 The MacPorts Project
 # Copyright (c) 2007 Markus W. Weissmann <mww at macports.org>
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
@@ -51,9 +51,11 @@
 default configure.nice      {${buildnicevalue}}
 default configure.dir       {${worksrcpath}}
 default autoreconf.dir      {${worksrcpath}}
-default autoreconf.pre_args {--install}
+default autoreconf.args     {{--install --verbose}}
 default autoconf.dir        {${worksrcpath}}
+default autoconf.args       {--verbose}
 default automake.dir        {${worksrcpath}}
+default automake.args       {--verbose}
 default xmkmf.cmd           xmkmf
 default xmkmf.dir           {${worksrcpath}}
 default use_configure       yes
@@ -74,8 +76,8 @@
     global ${type}.cmd option_defaults
 
     if {![info exists ${type}.cmd] || (
-        ([info exists option_defaults(${type}.cmd)] && [set ${type}.cmd] == $option_defaults(${type}.cmd)) ||
-        (![info exists option_defaults(${type}.cmd)] && [set ${type}.cmd] == "${type}")
+        ([info exists option_defaults(${type}.cmd)] && [set ${type}.cmd] eq $option_defaults(${type}.cmd)) ||
+        (![info exists option_defaults(${type}.cmd)] && [set ${type}.cmd] eq ${type})
         )} {
             eval [linsert $dep 0 depends_build-append]
     }
@@ -92,7 +94,7 @@
         xmkmf       port:imake
     }
 
-    if {[string equal ${action} "set"]} {
+    if {$action eq "set"} {
         switch $option {
             autoreconf.cmd  -
             automake.cmd    -
@@ -139,7 +141,7 @@
 default configure.cxxflags      {${configure.optflags}}
 default configure.objcflags     {${configure.optflags}}
 default configure.objcxxflags   {${configure.optflags}}
-default configure.cppflags      {-I${prefix}/include}
+default configure.cppflags      {-isystem${prefix}/include}
 default configure.ldflags       {"-L${prefix}/lib -Wl,-headerpad_max_install_names"}
 default configure.libs          {}
 default configure.fflags        {${configure.optflags}}
@@ -160,10 +162,12 @@
 default configure.pkg_config        {}
 default configure.pkg_config_path   {}
 
-options configure.build_arch configure.ld_archflags configure.sdkroot
+options configure.build_arch configure.ld_archflags \
+        configure.sdk_version configure.sdkroot
 default configure.build_arch    {[portconfigure::choose_supported_archs ${build_arch}]}
 default configure.ld_archflags  {[portconfigure::configure_get_ld_archflags]}
-default configure.sdkroot       {[portconfigure::configure_get_sdkroot]}
+default configure.sdk_version   {$macosx_sdk_version}
+default configure.sdkroot       {[portconfigure::configure_get_sdkroot ${configure.sdk_version}]}
 foreach tool {cc cxx objc objcxx f77 f90 fc} {
     options configure.${tool}_archflags
     default configure.${tool}_archflags  "\[portconfigure::configure_get_archflags $tool\]"
@@ -227,7 +231,7 @@
         {^macports-llvm-gcc-4\.2$}          {MacPorts LLVM-GCC 4.2}
     }
     foreach {re fmt} $valid_compilers {
-        if {[set matches [regexp -inline $re $compiler]] ne {}} {
+        if {[set matches [regexp -inline $re $compiler]] ne ""} {
             set compiler_name [eval [linsert [lrange $matches 1 end] 0 format $fmt]]
             break
         }
@@ -242,10 +246,10 @@
     if {${configure.ccache}} {
         # Create ccache directory with correct permissions with root privileges
         elevateToRoot "configure ccache"
-        if [catch {
+        if {[catch {
                 file mkdir ${ccache_dir}
                 file attributes ${ccache_dir} -owner ${macportsuser} -permissions 0755
-            } result] {
+            } result]} {
             ui_warn "ccache_dir ${ccache_dir} could not be created; disabling ccache: $result"
             set configure.ccache no
         }
@@ -253,9 +257,9 @@
 
         # Initialize ccache directory with the given maximum size
         if {${configure.ccache}} {
-            if [catch {
+            if {[catch {
                 exec ccache -M ${ccache_size} >/dev/null
-            } result] {
+            } result]} {
                 ui_warn "ccache_dir ${ccache_dir} could not be initialized; disabling ccache: $result"
                 set configure.ccache no
             }
@@ -268,16 +272,16 @@
 # universal_archs
 proc portconfigure::choose_supported_archs {archs} {
     global supported_archs
-    if {$supported_archs == ""} {
+    if {$supported_archs eq ""} {
         return $archs
     }
     set ret {}
     foreach arch $archs {
         if {[lsearch -exact $supported_archs $arch] != -1} {
             set add_arch $arch
-        } elseif {$arch == "x86_64" && [lsearch -exact $supported_archs "i386"] != -1} {
+        } elseif {$arch eq "x86_64" && [lsearch -exact $supported_archs "i386"] != -1} {
             set add_arch "i386"
-        } elseif {$arch == "ppc64" && [lsearch -exact $supported_archs "ppc"] != -1} {
+        } elseif {$arch eq "ppc64" && [lsearch -exact $supported_archs "ppc"] != -1} {
             set add_arch "ppc"
         } else {
             continue
@@ -297,14 +301,14 @@
         set flags "-m64"
     } elseif {[tbool configure.m32]} {
         set flags "-m32"
-    } elseif {${configure.build_arch} != ""} {
+    } elseif {${configure.build_arch} ne ""} {
         if {[arch_flag_supported ${configure.compiler}] &&
             [regexp {^(?:cc|cxx|objc|objcxx)$} $tool]
         } then {
             set flags "-arch ${configure.build_arch}"
-        } elseif {${configure.build_arch} == "x86_64" || ${configure.build_arch} == "ppc64"} {
+        } elseif {${configure.build_arch} eq "x86_64" || ${configure.build_arch} eq "ppc64"} {
             set flags "-m64"
-        } elseif {${configure.compiler} != "gcc-3.3"} {
+        } elseif {${configure.compiler} ne "gcc-3.3"} {
             set flags "-m32"
         }
     }
@@ -317,32 +321,32 @@
 # ld directly. So we punt and let portfiles deal with that case.
 proc portconfigure::configure_get_ld_archflags {args} {
     global configure.build_arch configure.compiler
-    if {${configure.build_arch} != "" && [arch_flag_supported ${configure.compiler}]} {
+    if {${configure.build_arch} ne "" && [arch_flag_supported ${configure.compiler}]} {
         return "-arch ${configure.build_arch}"
     } else {
         return ""
     }
 }
 
-proc portconfigure::configure_get_sdkroot {} {
-    global developer_dir macosx_deployment_target macosx_version xcodeversion os.arch os.platform
-    if {${os.platform} == "darwin" && ($macosx_deployment_target != $macosx_version
-        || (${os.arch} == "powerpc" && $macosx_version == "10.4" && [variant_exists universal] && [variant_isset universal]))} {
+proc portconfigure::configure_get_sdkroot {sdk_version} {
+    global developer_dir macosx_version xcodeversion os.arch os.platform
+    if {${os.platform} eq "darwin" && ($sdk_version ne $macosx_version
+        || (${os.arch} eq "powerpc" && $macosx_version eq "10.4" && [variant_exists universal] && [variant_isset universal]))} {
         if {[vercmp $xcodeversion 4.3] < 0} {
-            set sdks_dir "${developer_dir}/SDKs"
+            set sdks_dir ${developer_dir}/SDKs
         } else {
-            set sdks_dir "${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs"
+            set sdks_dir ${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs
         }
-        if {$macosx_deployment_target == "10.4"} {
-            set sdk "${sdks_dir}/MacOSX10.4u.sdk"
+        if {$sdk_version eq "10.4"} {
+            set sdk ${sdks_dir}/MacOSX10.4u.sdk
         } else {
-            set sdk "${sdks_dir}/MacOSX${macosx_deployment_target}.sdk"
+            set sdk ${sdks_dir}/MacOSX${sdk_version}.sdk
         }
         if {[file exists $sdk]} {
             return $sdk
         }
     }
-    return ""
+    return {}
 }
 
 # internal function to determine the "-arch xy" flags for the compiler
@@ -350,7 +354,7 @@
     global configure.universal_archs
     set flags ""
     foreach arch ${configure.universal_archs} {
-        if {$flags == ""} {
+        if {$flags eq ""} {
             set flags "-arch $arch"
         } else {
             append flags " -arch $arch"
@@ -374,18 +378,15 @@
     return [regexp {^gcc-4|llvm|apple|clang} $compiler]
 }
 
-# Mapping from compiler names to compiler ports, for private use by
-# compiler_port_name. Do not access directly.
-set portconfigure::valid_compiler_ports {
-    {^apple-gcc-(\d+)\.(\d+)$}                          {apple-gcc%s%s}
-    {^macports-clang-(\d+\.\d+)$}                       {clang-%s}
-    {^macports-dragonegg-(\d+\.\d+)(-gcc-\d+\.\d+)?$}   {dragonegg-%s%s}
-    {^macports-(llvm-)?gcc-(\d+)\.(\d+)$}               {%sgcc%s%s}
-}
-
 proc portconfigure::compiler_port_name {compiler} {
-    foreach {re fmt} $portconfigure::valid_compiler_ports {
-        if {[set matches [regexp -inline $re $compiler]] ne {}} {
+    set valid_compiler_ports {
+        {^apple-gcc-(\d+)\.(\d+)$}                          {apple-gcc%s%s}
+        {^macports-clang-(\d+\.\d+)$}                       {clang-%s}
+        {^macports-dragonegg-(\d+\.\d+)(-gcc-\d+\.\d+)?$}   {dragonegg-%s%s}
+        {^macports-(llvm-)?gcc-(\d+)\.(\d+)$}               {%sgcc%s%s}
+    }
+    foreach {re fmt} $valid_compiler_ports {
+        if {[set matches [regexp -inline $re $compiler]] ne ""} {
             return [eval [linsert [lrange $matches 1 end] 0 format $fmt]]
         }
     }
@@ -393,12 +394,12 @@
 }
 
 proc portconfigure::compiler_is_port {compiler} {
-    return [expr {[portconfigure::compiler_port_name ${compiler}] != ""}]
+    return [expr {[portconfigure::compiler_port_name ${compiler}] ne ""}]
 }
 
 # internal function to determine the default compiler
 proc portconfigure::configure_get_default_compiler {args} {
-    if {[option compiler.whitelist] != {}} {
+    if {[option compiler.whitelist] ne ""} {
         set search_list [option compiler.whitelist]
     } else {
         set search_list [option compiler.fallback]
@@ -424,21 +425,19 @@
 
 # internal function to choose compiler fallback list based on platform
 proc portconfigure::get_compiler_fallback {} {
-    global xcodeversion macosx_deployment_target default_compilers
+    global xcodeversion macosx_deployment_target default_compilers configure.sdkroot
     if {[info exists default_compilers]} {
         return $default_compilers
-    } elseif {$xcodeversion == "none" || $xcodeversion == ""} {
+    } elseif {$xcodeversion eq "none" || $xcodeversion eq ""} {
         return {cc}
-    } elseif {[vercmp $xcodeversion 4.6] >= 0} {
+    } elseif {[vercmp $xcodeversion 5.0] >= 0} {
         return {clang macports-llvm-gcc-4.2 apple-gcc-4.2 macports-clang-3.3}
     } elseif {[vercmp $xcodeversion 4.2] >= 0} {
         return {clang llvm-gcc-4.2 apple-gcc-4.2 macports-clang-3.3}
     } elseif {[vercmp $xcodeversion 4.0] >= 0} {
         return {llvm-gcc-4.2 clang gcc-4.2 macports-clang-3.3 apple-gcc-4.2}
     } elseif {[vercmp $xcodeversion 3.2] >= 0} {
-        if {$macosx_deployment_target == "10.4"} {
-            # It's not the deployment target that is the issue, it's the
-            # 10.4u SDK which base chooses if the deployment_target is set
+        if {[string match *10.4u* ${configure.sdkroot}]} {
             return {gcc-4.0}
         } else {
             return {gcc-4.2 clang llvm-gcc-4.2 macports-clang-3.3 macports-llvm-gcc-4.2 apple-gcc-4.2 gcc-4.0}
@@ -446,7 +445,7 @@
     } elseif {[vercmp $xcodeversion 3.0] >= 0} {
         return {gcc-4.2 apple-gcc-4.2 gcc-4.0 macports-clang-3.3}
     } else {
-        return {gcc-4.0 apple-gcc-4.2 gcc-3.3 macports-clang-3.3}
+        return {apple-gcc-4.2 gcc-4.0 gcc-3.3 macports-clang-3.3}
     }
 }
 
@@ -477,7 +476,7 @@
 # internal function to find correct compilers
 proc portconfigure::configure_get_compiler {type {compiler {}}} {
     global configure.compiler prefix
-    if {$compiler == {}} {
+    if {$compiler eq ""} {
         set compiler ${configure.compiler}
     }
     # Tcl 8.4's switch doesn't support -matchvar.
@@ -487,7 +486,7 @@
             objc    { return ${prefix}/bin/gcc-apple${suffix} }
             cxx     -
             objcxx  {
-                if {$suffix == "-4.2"} {
+                if {$suffix eq "-4.2"} {
                     return ${prefix}/bin/g++-apple${suffix}
                 }
             }
@@ -523,7 +522,7 @@
             cpp     { return [find_developer_tool llvm-cpp-4.2] }
         }
     } elseif {[regexp {^macports-clang(-\d+\.\d+)?$} $compiler -> suffix]} {
-        if {$suffix ne {}} {
+        if {$suffix ne ""} {
             set suffix "-mp${suffix}"
         }
         switch $type {
@@ -534,7 +533,7 @@
         }
     } elseif {[regexp {^macports-dragonegg(-\d+\.\d+)(?:-gcc(-\d+\.\d+))?$} $compiler \
                 -> infix suffix]} {
-        if {$suffix ne {}} {
+        if {$suffix ne ""} {
             set suffix "-mp${suffix}"
         }
         switch $type {
@@ -548,7 +547,7 @@
             f90     { return ${prefix}/bin/dragonegg${infix}-gfortran${suffix} }
         }
     } elseif {[regexp {^macports-gcc(-\d+\.\d+)?$} $compiler -> suffix]} {
-        if {$suffix ne {}} {
+        if {$suffix ne ""} {
             set suffix "-mp${suffix}"
         }
         switch $type {
@@ -707,12 +706,12 @@
         }
 
         # https://trac.macports.org/ticket/34221
-        if {${os.platform} == "darwin" && ${os.major} == 12} {
+        if {${os.platform} eq "darwin" && ${os.major} == 12} {
             append_to_environment_value configure "__CFPREFERENCES_AVOID_DAEMON" 1
         }
 
         # add SDK flags if cross-compiling (or universal on ppc tiger)
-        if {${configure.sdkroot} != ""} {
+        if {${configure.sdkroot} ne ""} {
             foreach env_var {CPPFLAGS CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS} {
                 append_to_environment_value configure $env_var -isysroot ${configure.sdkroot}
             }
@@ -732,17 +731,17 @@
             eval [linsert ${configure.universal_args} 0 configure.pre_args-append]
         } else {
             foreach env_var {CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS FFLAGS F90FLAGS FCFLAGS LDFLAGS} {
-                if {${configure.march} != {}} {
+                if {${configure.march} ne ""} {
                     append_to_environment_value configure $env_var -march=${configure.march}
                 }
-                if {${configure.mtune} != {}} {
+                if {${configure.mtune} ne ""} {
                     append_to_environment_value configure $env_var -mtune=${configure.mtune}
                 }
             }
         }
 
         # Add flags to specify C++ STL implementation
-        if {${configure.cxx_stdlib} ne {} && [string match *clang* [option configure.cxx]]} {
+        if {${configure.cxx_stdlib} ne "" && [string match "*clang*" [option configure.cxx]]} {
             append_to_environment_value configure CXXFLAGS -stdlib=${configure.cxx_stdlib}
             append_to_environment_value configure OBJCXXFLAGS -stdlib=${configure.cxx_stdlib}
         }

Modified: branches/new-help-system/base/src/port1.0/portdestroot.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portdestroot.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portdestroot.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -93,8 +93,8 @@
 set_ui_prefix
 
 proc portdestroot::destroot_getargs {args} {
-    if {(([option build.type] == "default" && [option os.platform] != "freebsd") || \
-         ([option build.type] == "gnu")) \
+    if {(([option build.type] eq "default" && [option os.platform] ne "freebsd") || \
+         ([option build.type] eq "gnu")) \
         && [regexp "^(/\\S+/|)(g|gnu|)make(\\s+.*|)$" [option destroot.cmd]]} {
         # Print "Entering directory" lines for better log debugging
         return "-w [option destroot.target]"
@@ -163,7 +163,7 @@
     }
 
     foreach fileToDelete {share/info/dir lib/charset.alias} {
-        if [file exists "${destroot}${prefix}/${fileToDelete}"] {
+        if {[file exists "${destroot}${prefix}/${fileToDelete}"]} {
             ui_debug "Deleting stray ${fileToDelete} file."
             file delete "${destroot}${prefix}/${fileToDelete}"
         }
@@ -172,7 +172,7 @@
     # Prevent overlinking due to glibtool .la files: https://trac.macports.org/ticket/38010
     ui_debug "Fixing glibtool .la files in destroot for ${subport}"
     fs-traverse -depth fullpath ${destroot} {
-        if {[file extension $fullpath] == ".la" && [file type $fullpath] == "file"} {
+        if {[file extension $fullpath] eq ".la" && [file type $fullpath] eq "file"} {
             # Make sure it is from glibtool ... "a libtool library file" will appear in the first line
             if {![catch {set fp [open $fullpath]}]} {
                 if {[gets $fp line] > 0 && [string first "a libtool library file" $line] != -1} {
@@ -201,7 +201,7 @@
         }
     }
     fs-traverse -depth dir ${destroot} {
-        if {[file type $dir] == "directory"} {
+        if {[file type $dir] eq "directory"} {
             catch {file delete $dir}
         }
     }
@@ -221,18 +221,18 @@
     set gzip [findBinary gzip ${portutil::autoconf::gzip_path}]
     set gunzip "$gzip -d"
     set bunzip2 "[findBinary bzip2 ${portutil::autoconf::bzip2_path}] -d"
-    if {[file isdirectory ${manpath}] && [file type ${manpath}] == "directory"} {
+    if {[file isdirectory ${manpath}] && [file type ${manpath}] eq "directory"} {
         ui_info "$UI_PREFIX [format [msgcat::mc "Compressing man pages for %s"] ${subport}]"
         set found 0
         set manlinks [list]
         foreach mandir [readdir "${manpath}"] {
             if {![regexp {^(cat|man)(.)$} ${mandir} match ignore manindex]} { continue }
             set mandirpath [file join ${manpath} ${mandir}]
-            if {[file isdirectory ${mandirpath}] && [file type ${mandirpath}] == "directory"} {
+            if {[file isdirectory ${mandirpath}] && [file type ${mandirpath}] eq "directory"} {
                 ui_debug "Scanning ${mandir}"
                 foreach manfile [readdir ${mandirpath}] {
                     set manfilepath [file join ${mandirpath} ${manfile}]
-                    if {[file isfile ${manfilepath}] && [file type ${manfilepath}] == "file"} {
+                    if {[file isfile ${manfilepath}] && [file type ${manfilepath}] eq "file"} {
                         if {[regexp "^(.*\[.\]${manindex}\[a-z\]*)\[.\]gz\$" ${manfile} gzfile manfile]} {
                             set found 1
                             system "cd ${manpath} && \
@@ -258,7 +258,7 @@
                                 file attributes ${gzmanfilepath} -permissions $desired
                             }
                         }
-                    } elseif {[file type ${manfilepath}] == "link"} {
+                    } elseif {[file type ${manfilepath}] eq "link"} {
                         lappend manlinks [file join ${mandir} ${manfile}]
                     }
                 }
@@ -336,14 +336,14 @@
                             set mtree_violation "yes"
                         }
                     }
-                } elseif {[string equal -length [expr [string length $dfile] + 1] $dfile/ $prefix]} {
+                } elseif {[string equal -length [expr {[string length $dfile] + 1}] $dfile/ $prefix]} {
                     # we've found a subpath of our prefix
                     lpush pathsToCheck $dfile
                 } else {
                     set dir_allowed no
                     # these files are (at least potentially) outside of the prefix
                     foreach dir "$applications_dir $frameworks_dir /Library/LaunchAgents /Library/LaunchDaemons /Library/StartupItems" {
-                        if {[string equal -length [expr [string length $dfile] + 1] $dfile/ $dir]} {
+                        if {[string equal -length [expr {[string length $dfile] + 1}] $dfile/ $dir]} {
                             # it's a prefix of one of the allowed paths
                             set dir_allowed yes
                             break

Modified: branches/new-help-system/base/src/port1.0/portdistcheck.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portdistcheck.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portdistcheck.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -61,7 +61,7 @@
     ui_debug "Portfile modification date is [clock format $port_moddate]"
 
     set curl_options {}
-    if [tbool fetch.ignore_sslcert] {
+    if {[tbool fetch.ignore_sslcert]} {
         lappend curl_options "--ignore-ssl-cert"
     }
 
@@ -127,13 +127,13 @@
                 set size $totalsize
                 set humansize "${size}"
             } elseif {$totalsize < 1024*1024} {
-                set size [expr $totalsize / 1024.0]
+                set size [expr {$totalsize / 1024.0}]
                 set humansize [format "%.1fK" $size]
             } elseif {$totalsize < 1024*1024*1024} {
-                set size [expr $totalsize / (1024.0*1024.0)]
+                set size [expr {$totalsize / (1024.0*1024.0)}]
                 set humansize [format "%.1fM" $size]
             } else {
-                set size [expr $totalsize / (1024.0*1024.0*1024.0)]
+                set size [expr {$totalsize / (1024.0*1024.0*1024.0)}]
                 set humansize [format "%.1fG" $size]
             }
             ui_msg "$subport: $humansize"

Modified: branches/new-help-system/base/src/port1.0/portdistfiles.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portdistfiles.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portdistfiles.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -57,8 +57,8 @@
            portdbpath dist_subdir all_dist_files
     
     # give up on ports that do not provide URLs
-    if {(![info exists master_sites] || $master_sites == "{}")
-        && (![info exists patchfiles] || ![info exists patch_sites] || $patch_sites == "{}")} {
+    if {(![info exists master_sites] || $master_sites eq "{}")
+        && (![info exists patchfiles] || ![info exists patch_sites] || $patch_sites eq "{}")} {
         return 0
     }
 
@@ -81,7 +81,7 @@
         ui_msg "\[$distfile\] [file join $portdbpath distfiles $dist_subdir $distfile]"
 
         # print checksums if available
-        if {$result == "yes" && [array get checksums_array $distfile] != ""} {
+        if {$result eq "yes" && [array get checksums_array $distfile] ne ""} {
             foreach {type sum} $checksums_array($distfile) {
                 ui_msg " $type: $sum"
             }

Modified: branches/new-help-system/base/src/port1.0/portextract.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portextract.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portextract.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -75,7 +75,7 @@
 }
 
 proc portextract::extract_start {args} {
-    global UI_PREFIX extract.dir extract.mkdir use_bzip2 use_lzma use_xz use_zip use_7z use_dmg
+    global UI_PREFIX extract.dir extract.mkdir use_bzip2 use_lzma use_xz use_zip use_7z use_lzip use_dmg
 
     ui_notice "$UI_PREFIX [format [msgcat::mc "Extracting %s"] [option subport]]"
 
@@ -103,6 +103,10 @@
         option extract.cmd [binaryInPath "7za"]
         option extract.pre_args x
         option extract.post_args ""
+    } elseif {[tbool use_lzip]} {
+        option extract.cmd [binaryInPath "lzip"]
+        option extract.pre_args "-dc"
+        #option extract.post_args ""
     } elseif {[tbool use_dmg]} {
         global distname extract.cmd
         set dmg_mount [mkdtemp "/tmp/mports.XXXXXXXX"]

Modified: branches/new-help-system/base/src/port1.0/portfetch.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portfetch.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portfetch.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -48,7 +48,7 @@
 }
 
 # define options: distname master_sites
-options master_sites patch_sites extract.suffix distfiles patchfiles use_bzip2 use_lzma use_xz use_zip use_7z use_dmg dist_subdir \
+options master_sites patch_sites extract.suffix distfiles patchfiles use_bzip2 use_lzma use_xz use_zip use_7z use_lzip use_dmg dist_subdir \
     fetch.type fetch.user fetch.password fetch.use_epsv fetch.ignore_sslcert \
     master_sites.mirror_subdir patch_sites.mirror_subdir \
     bzr.url bzr.revision \
@@ -128,6 +128,7 @@
 option_proc use_xz    portfetch::set_extract_type
 option_proc use_zip   portfetch::set_extract_type
 option_proc use_7z    portfetch::set_extract_type
+option_proc use_lzip  portfetch::set_extract_type
 option_proc use_dmg   portfetch::set_extract_type
 
 option_proc fetch.type portfetch::set_fetch_type
@@ -155,6 +156,10 @@
                 set extract.suffix .7z
                 depends_extract-append bin:7za:p7zip
             }
+            use_lzip {
+                set extract.suffix .tar.lz
+                depends_extract-append bin:lzip:lzip
+            }
             use_dmg {
                 set extract.suffix .dmg
             }
@@ -165,7 +170,7 @@
 proc portfetch::set_fetch_type {option action args} {
     global os.platform os.major
     if {[string equal ${action} "set"]} {
-        if {$args != "standard"} {
+        if {$args ne "standard"} {
             distfiles
         }
         switch $args {
@@ -225,7 +230,7 @@
                 set distsite [getdisttag $file]
                 set file [getdistname $file]
                 lappend all_dist_files $file
-                if {$distsite != ""} {
+                if {$distsite ne ""} {
                     lappend fetch_urls $distsite $file
                 } elseif {[info exists patch_sites]} {
                     lappend fetch_urls patch_sites $file
@@ -248,7 +253,7 @@
                 set distsite [getdisttag $file]
                 set file [getdistname $file]
                 lappend all_dist_files $file
-                if {$distsite != ""} {
+                if {$distsite ne ""} {
                     lappend fetch_urls $distsite $file
                 } else {
                     lappend fetch_urls master_sites $file
@@ -385,7 +390,7 @@
     }
     regexp {(.*://)?([[:alnum:].-]+)(:(\d+))?} $proxy_str - - proxy_host - proxy_port
     set ret "--config-option servers:global:http-proxy-host=${proxy_host}"
-    if {$proxy_port != ""} {
+    if {$proxy_port ne ""} {
         append ret " --config-option servers:global:http-proxy-port=${proxy_port}"
     }
     return $ret
@@ -496,8 +501,12 @@
     if {${fetch.remote_time} != "no"} {
         lappend fetch_options "--remote-time"
     }
-    if {$portverbose == "yes"} {
-        lappend fetch_options "-v"
+    if {$portverbose eq "yes"} {
+        lappend fetch_options "--progress"
+        lappend fetch_options "builtin"
+    } elseif {[llength [info commands ui_progress_download]] > 0} {
+        lappend fetch_options "--progress"
+        lappend fetch_options "ui_progress_download"
     }
     set sorted no
 

Modified: branches/new-help-system/base/src/port1.0/portinstall.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portinstall.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portinstall.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -238,7 +238,7 @@
     array set ourvariations $PortInfo(active_variants)
     set vlist [lsort -ascii [array names ourvariations]]
     foreach v $vlist {
-        if {$ourvariations($v) == "+"} {
+        if {$ourvariations($v) eq "+"} {
             puts $fd "@portvariant +${v}"
         }
     }
@@ -263,7 +263,7 @@
     # also save the contents for our own use later
     set installPlist {}
     fs-traverse -depth fullpath $destpath {
-        if {[file type $fullpath] == "directory"} {
+        if {[file type $fullpath] eq "directory"} {
             continue
         }
         set relpath [strsed $fullpath "s|^$destpath/||"]
@@ -310,13 +310,13 @@
     os.platform os.major portarchivetype installPlist
 
     set oldpwd [pwd]
-    if {$oldpwd == ""} {
+    if {$oldpwd eq ""} {
         set oldpwd $portpath
     }
 
     set location [get_portimage_path]
     set archive_path [find_portarchive_path]
-    if {$archive_path != ""} {
+    if {$archive_path ne ""} {
         set install_dir [file dirname $location]
         file mkdir $install_dir
         file rename -force $archive_path $install_dir
@@ -336,7 +336,7 @@
         if {[info exists $deplist]} {
             foreach dep [set $deplist] {
                 set dep_portname [_get_dep_port $dep]
-                if {$dep_portname != ""} {
+                if {$dep_portname ne ""} {
                     lappend dep_portnames $dep_portname
                 }
             }
@@ -356,7 +356,7 @@
         $regref os_major ${os.major}
         $regref archs [get_canonical_archs]
         # Trick to have a portable GMT-POSIX epoch-based time.
-        $regref date [expr [clock scan now -gmt true] - [clock scan "1970-1-1 00:00:00" -gmt true]]
+        $regref date [expr {[clock scan now -gmt true] - [clock scan "1970-1-1 00:00:00" -gmt true]}]
         if {[info exists negated_variants]} {
             $regref negated_variants $negated_variants
         }

Modified: branches/new-help-system/base/src/port1.0/portlint.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portlint.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portlint.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -138,7 +138,7 @@
             if {$nitpick} {
                 seek $f -1 end
                 set last [read $f 1]
-                if {![string match "\n" $last]} {
+                if {"\n" ne $last} {
                     ui_warn "Line $lineno has missing newline (at end of file)"
                     incr warnings
                 }
@@ -153,12 +153,12 @@
             incr errors
         }
 
-        if {($require_after == "PortSystem" || $require_after == "PortGroup") && \
+        if {($require_after eq "PortSystem" || $require_after eq "PortGroup") && \
             [string match "PortGroup*" $line]} {
             set require_blank false
         }
 
-        if {$nitpick && $require_blank && ($line != "")} {
+        if {$nitpick && $require_blank && ($line ne "")} {
             ui_warn "Line $lineno should be a newline (after $require_after)"
             incr warnings
         }
@@ -204,7 +204,7 @@
             set require_after "PortSystem"
         }
         if {[string match "PortGroup*" $line]} {
-            regexp {PortGroup\s+([a-z0-9_]+)\s+([0-9.]+)} $line -> portgroup portgroupversion
+            regexp {PortGroup\s+([A-Za-z0-9_]+)\s+([0-9.]+)} $line -> portgroup portgroupversion
             if {![info exists portgroup]} {
                 ui_error "Line $lineno has unrecognized PortGroup"
                 incr errors
@@ -228,7 +228,7 @@
         if {[string match "long_description*" $line]} {
             set in_description true
         }
-        if {$in_description && ([string range $line end end] != "\\")} {
+        if {$in_description && ([string range $line end end] ne "\\")} {
             set in_description false
             #set require_blank true
             #set require_after "long_description"
@@ -245,7 +245,7 @@
         
         if {[string match "platform\[ \t\]*" $line]} {
             regexp {platform\s+(?:\w+\s+(?:\w+\s+)?)?(\w+)} $line -> platform_arch
-            if {$platform_arch == "ppc"} {
+            if {$platform_arch eq "ppc"} {
                 ui_error "Arch 'ppc' in platform on line $lineno should be 'powerpc'"
                 incr errors
             }
@@ -271,7 +271,8 @@
     
             if {!$hashline
                     && ![regexp {^\s*PortSystem|^\s*PortGroup|^\s*version} $line]
-                    && ![regexp {^\s*[a-z0-9]+\.setup} $line]
+                    && ![regexp {^\s*[A-Za-z0-9_]+\.setup} $line]
+                    && ![regexp {^\s*license} $line]
                     && [string first [option version] $line] != -1} {
                 ui_warn "Line $lineno seems to hardcode the version number, consider using \${version} instead"
                 incr warnings
@@ -284,7 +285,16 @@
                     set hashline false
             }
         }
-            
+
+        # Check for hardcoded paths
+        if {!$hashline
+                && $name ne "MacPorts"
+                && [string match "*/opt/local*" $line]
+                && ![regexp {^\s*reinplace} $line]
+                && ![regexp {^\s*system.*\Wsed\W} $line]} {
+            ui_error "Line $lineno hardcodes /opt/local, use \${prefix} instead"
+        }
+
         ### TODO: more checks to Portfile syntax
 
         incr lineno
@@ -324,7 +334,7 @@
 
     foreach req_var $lint_required {
 
-        if {$req_var == "master_sites"} {
+        if {$req_var eq "master_sites"} {
             if {${fetch.type} != "standard"} {
                 ui_info "OK: $req_var not required for fetch.type ${fetch.type}"
                 continue
@@ -391,7 +401,7 @@
     foreach variant $all_variants {
         set variantname [ditem_key $variant name] 
         set variantdesc [lindex [ditem_key $variant description] 0]
-        if {![info exists variantname] || $variantname == ""} {
+        if {![info exists variantname] || $variantname eq ""} {
             ui_error "Variant number $variantnumber does not have a name"
             incr errors
         } else {
@@ -404,18 +414,18 @@
                 set name_ok false
             }
 
-            if {![info exists variantdesc] || $variantdesc == ""} {
+            if {![info exists variantdesc] || $variantdesc eq ""} {
                 # don't warn about missing descriptions for global variants
                 if {[lsearch -exact $local_variants $variantname] != -1 &&
-                    [variant_desc $porturl $variantname] == ""} {
+                    [variant_desc $porturl $variantname] eq ""} {
                     ui_warn "Variant $variantname does not have a description"
                     incr warnings
                     set desc_ok false
-                } elseif {$variantdesc == ""} {
+                } elseif {$variantdesc eq ""} {
                     set variantdesc "(pre-defined variant)"
                 }
             } else {
-                if {[variant_desc $porturl $variantname] != ""} {
+                if {[variant_desc $porturl $variantname] ne ""} {
                     ui_warn "Variant $variantname overrides global description"
                     incr warnings
                 }
@@ -460,7 +470,7 @@
             ui_debug "$errorInfo"
             continue
         }
-        if {$res == ""} {
+        if {$res eq ""} {
             ui_error "Unknown dependency: $dep"
             incr errors
         } else {
@@ -499,19 +509,19 @@
                 $addr == "openmaintainer at macports.org"} {
             ui_warn "Using full email address for no/open maintainer"
             incr warnings
-        } elseif [regexp "^(.+)@macports.org$" $addr -> localpart] {
+        } elseif {[regexp "^(.+)@macports.org$" $addr -> localpart]} {
             ui_warn "Maintainer email address for $localpart includes @macports.org"
             incr warnings
         } elseif {$addr == "darwinports at opendarwin.org"} {
             ui_warn "Using legacy email address for no/open maintainer"
             incr warnings
-        } elseif [regexp "^(.+)@(.+)$" $addr -> localpart domain] {
+        } elseif {[regexp "^(.+)@(.+)$" $addr -> localpart domain]} {
             ui_warn "Maintainer email address should be obfuscated as $domain:$localpart"
             incr warnings
         }
     }
 
-    if {$license == "unknown"} {
+    if {$license eq "unknown"} {
         ui_warn "no license set"
         incr warnings
     } else {
@@ -537,7 +547,7 @@
                         # if the last character of license name is a number or plus sign
                         # then a hyphen is missing
                         set license_end [string index $subtest end]
-                        if {[string equal "+" $license_end] || [string is integer -strict $license_end]} {
+                        if {"+" eq $license_end || [string is integer -strict $license_end]} {
                             ui_error "invalid license '${test}': missing hyphen before version"
                         }
                     }
@@ -591,7 +601,7 @@
         set refcount  [lindex [set ${deprecated_options_name}($option)] 1]
 
         if {$refcount > 0} {
-            if {$newoption != ""} {
+            if {$newoption ne ""} {
                 ui_warn "Using deprecated option '$option', superseded by '$newoption'"
             } else {
                 ui_warn "Using deprecated option '$option'"
@@ -612,22 +622,22 @@
 
     set svn_cmd ""
     catch {set svn_cmd [findBinary svn]}
-    if {$svn_cmd != "" && ([file exists $portpath/.svn] || ![catch {exec $svn_cmd info $portpath > /dev/null 2>@1}])} {
+    if {$svn_cmd ne "" && ([file exists $portpath/.svn] || ![catch {exec $svn_cmd info $portpath > /dev/null 2>@1}])} {
         ui_debug "Checking svn properties"
-        if [catch {exec $svn_cmd propget svn:keywords $portfile 2>@1} output] {
+        if {[catch {exec $svn_cmd propget svn:keywords $portfile 2>@1} output]} {
             ui_warn "Unable to check for svn:keywords property: $output"
         } else {
             ui_debug "Property svn:keywords is \"$output\", should be \"Id\""
-            if {$output != "Id"} {
+            if {$output ne "Id"} {
                 ui_error "Missing subversion property on Portfile, please execute: svn ps svn:keywords Id Portfile"
                 incr errors
             }
         }
-        if [catch {exec $svn_cmd propget svn:eol-style $portfile 2>@1} output] {
+        if {[catch {exec $svn_cmd propget svn:eol-style $portfile 2>@1} output]} {
             ui_warn "Unable to check for svn:eol-style property: $output"
         } else {
             ui_debug "Property svn:eol-style is \"$output\", should be \"native\""
-            if {$output != "native"} {
+            if {$output ne "native"} {
                 ui_error "Missing subversion property on Portfile, please execute: svn ps svn:eol-style native Portfile"
                 incr errors
             }

Modified: branches/new-help-system/base/src/port1.0/portlivecheck.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portlivecheck.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portlivecheck.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -77,7 +77,7 @@
     ui_debug "Port (livecheck) version is ${livecheck.version}"
 
     set curl_options {}
-    if [tbool livecheck.ignore_sslcert] {
+    if {[tbool livecheck.ignore_sslcert]} {
         lappend curl_options "--ignore-ssl-cert"
     }
 
@@ -99,7 +99,7 @@
                 if {[regexp "^($available_types)(?::(\[^:\]+))?" ${master_site} _ site subdir]} {
                     set subdirs [split $subdir /]
                     if {[llength $subdirs] > 1} {
-                        if {[lindex $subdirs 0] == "project"} {
+                        if {[lindex $subdirs 0] eq "project"} {
                             set subdir [lindex $subdirs 1]
                         } else {
                             set subdir ""

Modified: branches/new-help-system/base/src/port1.0/portload.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portload.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portload.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -53,7 +53,7 @@
     set launchctl_path ${portutil::autoconf::launchctl_path}
 
     foreach { path } "/Library/${startupitem.location}/${startupitem.plist}" {
-        if {[string length $launchctl_path] == 0} {
+        if {$launchctl_path eq ""} {
             return -code error [format [msgcat::mc "launchctl command was not found by configure"]]
         } elseif {![file exists $path]} {
             return -code error [format [msgcat::mc "Launchd plist %s was not found"] $path]

Modified: branches/new-help-system/base/src/port1.0/portmain.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portmain.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portmain.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -80,12 +80,12 @@
 default subbuildpath {[portmain::get_subbuildpath]}
 proc portmain::get_subbuildpath {} {
     global portpath portbuildpath subport
-    if {$subport != ""} {
+    if {$subport ne ""} {
         set subdir $subport
     } else {
         set subdir [file tail $portpath]
     }
-    return [file join $portbuildpath $subdir]
+    return [file normalize [file join $portbuildpath $subdir]]
 }
 default workpath {[getportworkpath_from_buildpath $subbuildpath]}
 default prefix /opt/local
@@ -120,7 +120,7 @@
 default os.endian {$os_endian}
 
 set macosx_version_text {}
-if {[option os.platform] == "darwin"} {
+if {[option os.platform] eq "darwin"} {
     set macosx_version_text "(Mac OS X ${macosx_version}) "
 }
 ui_debug "OS [option os.platform]/[option os.version] ${macosx_version_text}arch [option os.arch]"
@@ -128,7 +128,7 @@
 default universal_variant {${use_configure}}
 
 # sub-platforms of darwin
-if {[option os.platform] == "darwin"} {
+if {[option os.platform] eq "darwin"} {
     if {[file isdirectory /System/Library/Frameworks/Carbon.framework]} {
         default os.subplatform macosx
         # we're on Mac OS X and can therefore build universal
@@ -159,16 +159,16 @@
     # set global variable indicating to other functions to use ~/.macports as well
     set usealtworkpath yes
 
-    default worksymlink {[file join ${altprefix}${portpath} work]}
-    default distpath {[file join ${altprefix}${portdbpath} distfiles ${dist_subdir}]}
+    default worksymlink {[file normalize [file join ${altprefix}${portpath} work]]}
+    default distpath {[file normalize [file join ${altprefix}${portdbpath} distfiles ${dist_subdir}]]}
     set portbuildpath "${altprefix}${portbuildpath}"
 
     ui_debug "Going to use alternate build prefix: $altprefix"
     ui_debug "workpath = $workpath"
 } else {
     set usealtworkpath no
-    default worksymlink {[file join $portpath work]}
-    default distpath {[file join $portdbpath distfiles ${dist_subdir}]}
+    default worksymlink {[file normalize [file join $portpath work]]}
+    default distpath {[file normalize [file join $portdbpath distfiles ${dist_subdir}]]}
 }
 
 # end gsoc08-privileges

Modified: branches/new-help-system/base/src/port1.0/portmirror.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portmirror.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portmirror.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -58,7 +58,7 @@
     set mirror_filemap_path [file join $portdbpath distfiles_mirror.db]
     if {![info exists mirror_filemap]
         && [info exists ports_mirror_new]
-        && $ports_mirror_new == "yes"
+        && $ports_mirror_new eq "yes"
         && [file exists $mirror_filemap_path]} {
         # Trash the map file if it existed.
         file delete -force $mirror_filemap_path

Modified: branches/new-help-system/base/src/port1.0/portpatch.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portpatch.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portpatch.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -72,7 +72,7 @@
     global UI_PREFIX usealtworkpath altprefix
 
     # First make sure that patchfiles exists and isn't stubbed out.
-    if {![exists patchfiles] || [option patchfiles] == ""} {
+    if {![exists patchfiles] || [option patchfiles] eq ""} {
         return 0
     }
 

Modified: branches/new-help-system/base/src/port1.0/portsandbox.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portsandbox.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portsandbox.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -35,7 +35,7 @@
 
 options portsandbox_supported portsandbox_active portsandbox_profile
 default portsandbox_supported {[file executable $portutil::autoconf::sandbox_exec_path]}
-default portsandbox_active {[expr $portsandbox_supported && $sandbox_enable]}
+default portsandbox_active {[expr {$portsandbox_supported && $sandbox_enable}]}
 default portsandbox_profile {}
 
 # set up a suitable profile to pass to sandbox-exec, based on the target

Modified: branches/new-help-system/base/src/port1.0/portstartupitem.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portstartupitem.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portstartupitem.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -231,12 +231,12 @@
     puts ${item} "LOGFILE=\"${startupitem.logfile}\""
     puts ${item} "EXECUTABLE=\"${startupitem.executable}\""
     puts ${item} ""
-    puts ${item} "HAVE_STARTCMDS=[expr [llength ${startupitem.start}] ? "true" : "false"]"
-    puts ${item} "HAVE_STOPCMDS=[expr [llength ${startupitem.stop}] ? "true" : "false"]"
-    puts ${item} "HAVE_RESTARTCMDS=[expr [llength ${startupitem.restart}] ? "true" : "false"]"
+    puts ${item} "HAVE_STARTCMDS=[expr {[llength ${startupitem.start}] ? "true" : "false"}]"
+    puts ${item} "HAVE_STOPCMDS=[expr {[llength ${startupitem.stop}] ? "true" : "false"}]"
+    puts ${item} "HAVE_RESTARTCMDS=[expr {[llength ${startupitem.restart}] ? "true" : "false"}]"
     puts ${item} "DELETE_PIDFILE=${createPidFile}"
     puts ${item} "CREATE_PIDFILE=${deletePidFile}"
-    puts ${item} "LOG_EVENTS=[expr [tbool ${startupitem.logevents}] ? "true" : "false"]"
+    puts ${item} "LOG_EVENTS=[expr {[tbool ${startupitem.logevents}] ? "true" : "false"}]"
     puts ${item} ""
 
     # Emit the init lines
@@ -600,7 +600,7 @@
     
     puts ${plist} "<key>Debug</key><false/>"
     puts ${plist} "<key>Disabled</key><true/>"
-    if {$macosx_deployment_target != "10.4"} {
+    if {$macosx_deployment_target ne "10.4"} {
         puts ${plist} "<key>KeepAlive</key><true/>"
     } else {
         puts ${plist} "<key>OnDemand</key><false/>"

Modified: branches/new-help-system/base/src/port1.0/porttrace.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/porttrace.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/porttrace.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -40,7 +40,7 @@
 }
 
 proc porttrace::trace_start {workpath} {
-    global os.platform developer_dir
+    global os.platform developer_dir macportsuser
     if {${os.platform} == "darwin"} {
         if {[catch {package require Thread} error]} {
             ui_warn "trace requires Tcl Thread package ($error)"
@@ -87,17 +87,25 @@
             /tmp \
             /private/tmp \
             /var/tmp \
-            /var/folders \
             /private/var/tmp \
+            /var/folders \
+            /private/var/folders \
             /var/empty \
             /private/var/empty \
-            /private/var/folders \
+            /var/run \
+            /private/var/run \
+            /var/db/xcode_select_link \
+            /private/var/db/xcode_select_link \
+            /var/db/mds \
+            /private/var/db/mds \
+            [file normalize ~${macportsuser}/Library/Preferences/com.apple.dt.Xcode.plist] \
+            "$env(HOME)/Library/Preferences/com.apple.dt.Xcode.plist" \
+            /Library/Caches/com.apple.Xcode \
             /dev \
             /etc/passwd \
             /etc/groups \
             /etc/localtime \
             [file normalize ${developer_dir}/../..] \
-            /Library/Caches/com.apple.Xcode \
             "$env(HOME)/.ccache"]
             if {[info exists env(TMPDIR)]} {
                 lappend trace_sandbox $env(TMPDIR)
@@ -119,23 +127,9 @@
 # Enable the fence.
 # Only done for targets that should only happen in the sandbox.
 proc porttrace::trace_enable_fence {} {
-    global env trace_sandboxbounds
-    set env(DARWINTRACE_SANDBOX_BOUNDS) $trace_sandboxbounds
     tracelib enablefence
 }
 
-# Disable the fence.
-# Unused yet.
-proc porttrace::trace_disable_fence {} {
-    global env macosx_version
-    if [info exists env(DARWINTRACE_SANDBOX_BOUNDS)] {
-        unset env(DARWINTRACE_SANDBOX_BOUNDS)
-        if {$macosx_version == "10.5"} {
-            unsetenv DARWINTRACE_SANDBOX_BOUNDS
-        }
-    }
-}
-
 # Check the list of ports.
 # Output a warning for every port the trace revealed a dependency on
 # that isn't included in portslist
@@ -178,7 +172,7 @@
         global env trace_fifo macosx_version
         foreach var {DYLD_INSERT_LIBRARIES DYLD_FORCE_FLAT_NAMESPACE DARWINTRACE_LOG DARWINTRACE_SANDBOX_BOUNDS} {
             array unset env $var
-            if {$macosx_version == "10.5"} {
+            if {$macosx_version eq "10.5"} {
                 unsetenv $var
             }
         }
@@ -278,12 +272,12 @@
 
         # Skip empty lines.
         if {$line_length > 0} {
-            set path_start [expr [string first "\t" $theline] + 1]
-            set op [string range $theline 0 [expr $path_start - 2]]
-            set path [string range $theline $path_start [expr $line_length - 1]]
+            set path_start [expr {[string first "\t" $theline] + 1}]
+            set op [string range $theline 0 [expr {$path_start - 2}]]
+            set path [string range $theline $path_start [expr {$line_length - 1}]]
 
             # open/execve
-            if {$op == "open" || $op == "execve"} {
+            if {$op eq "open" || $op eq "execve"} {
                 # Only work on files.
                 if {[file isfile $path]} {
                     # Did we process the file yet?
@@ -307,7 +301,7 @@
                         catch {filemap set trace_filemap $path $port}
                     }
                 }
-            } elseif {$op == "sandbox_violation"} {
+            } elseif {$op eq "sandbox_violation"} {
                 lappend sandbox_violation_list $path
             }
         }

Modified: branches/new-help-system/base/src/port1.0/portunload.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portunload.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portunload.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -53,7 +53,7 @@
     set launchctl_path ${portutil::autoconf::launchctl_path}
 
     foreach { path } "/Library/${startupitem.location}/${startupitem.plist}" {
-        if {[string length $launchctl_path] == 0} {
+        if {$launchctl_path eq ""} {
             return -code error [format [msgcat::mc "launchctl command was not found by configure"]]
         } elseif {![file exists $path]} {
             return -code error [format [msgcat::mc "Launchd plist %s was not found"] $path]

Modified: branches/new-help-system/base/src/port1.0/portutil.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/portutil.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/portutil.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -114,6 +114,23 @@
 }
 
 ##
+# Handle option-prepend
+#
+# @param option name of the option
+# @param args arguments
+proc handle_option-prepend {option args} {
+    global $option user_options option_procs
+
+    if {![info exists user_options($option)]} {
+        if {[info exists $option]} {
+            set $option [concat $args [set $option]]
+        } else {
+            set $option $args
+        }
+    }
+}
+
+##
 # Handle option-delete
 #
 # @param option name of the option
@@ -162,7 +179,7 @@
             set deprecated_options(${option}-replace) [list ${option}-strsed 0]
         }
         set refcount [lindex $deprecated_options(${option}-replace) 1]
-        lset deprecated_options(${option}-replace) 1 [expr $refcount + 1]
+        lset deprecated_options(${option}-replace) 1 [expr {$refcount + 1}]
         return [eval handle_option-strsed $option $args]
     }
 
@@ -188,6 +205,7 @@
     foreach option $args {
         interp alias {} $option {} handle_option $option
         interp alias {} $option-append {} handle_option-append $option
+        interp alias {} $option-prepend {} handle_option-prepend $option
         interp alias {} $option-delete {} handle_option-delete $option
         interp alias {} $option-strsed {} handle_option-strsed $option
         interp alias {} $option-replace {} handle_option-replace $option
@@ -234,15 +252,15 @@
     set refcount  [lindex $deprecated_options($option) 1]
     global $newoption
 
-    if {$newoption == ""} {
+    if {$newoption eq ""} {
         ui_warn "Port $subport using deprecated option \"$option\"."
         return
     }
 
     # Increment reference counter
-    lset deprecated_options($option) 1 [expr $refcount + 1]
+    lset deprecated_options($option) 1 [expr {$refcount + 1}]
 
-    if {$action != "read"} {
+    if {$action ne "read"} {
         $newoption [set $option]
     } else {
         $option [set $newoption]
@@ -366,12 +384,12 @@
     set command_suffix ""
 
     if {[llength $args] > 0} {
-        if {[lindex $args 0] == "-notty"} {
+        if {[lindex $args 0] eq "-notty"} {
             set notty "-notty"
             set args [lrange $args 1 end]
         }
 
-        if {[lindex $args 0] == "-varprefix"} {
+        if {[lindex $args 0] eq "-varprefix"} {
             set varprefix [lindex $args 1]
             set args [lrange $args 2 end]
         }
@@ -417,7 +435,7 @@
 
     # Prepare nice value change
     set nice ""
-    if {[info exists ${varprefix}.nice] && [set ${varprefix}.nice] != ""} {
+    if {[info exists ${varprefix}.nice] && [set ${varprefix}.nice] ne ""} {
         set nice "-nice [set ${varprefix}.nice]"
     }
 
@@ -443,7 +461,7 @@
 
     # Restore the environment.
     array unset env *
-    if {$macosx_version == "10.5"} {
+    if {$macosx_version eq "10.5"} {
         unsetenv *
     }
     array set env [array get saved_env]
@@ -511,10 +529,10 @@
             # args is a list of strings/list
             foreach arg $args {
                 # Strip trailing empty lines
-                if {[string index $arg 0] == "\n"} {
+                if {[string index $arg 0] eq "\n"} {
                     set arg [string range $arg 1 end]
                 }
-                if {[string index $arg end] == "\n"} {
+                if {[string index $arg end] eq "\n"} {
                     set arg [string range $arg 0 end-1]
                 }
 
@@ -522,13 +540,13 @@
                 set indent ""
                 for {set i 0} {$i < [string length $arg]} {incr i} {
                     set c [string index $arg $i]
-                    if {$c != " " && $c != "\t"} {
+                    if {$c ne " " && $c ne "\t"} {
                         break
                     }
                     append indent $c
                 }
                 # Remove indent on first line
-                set arg [string replace $arg 0 [expr $i - 1]]
+                set arg [string replace $arg 0 [expr {$i - 1}]]
                 # Remove indent on each other line
                 set arg [string map "\"\n$indent\" \"\n\"" $arg]
 
@@ -563,7 +581,7 @@
         return -code error "Malformed variant specification"
     }
     set code [lindex $args end]
-    set args [lrange $args 0 [expr $len - 2]]
+    set args [lrange $args 0 [expr {$len - 2}]]
 
     set ditem [variant_new "temp-variant"]
 
@@ -611,7 +629,7 @@
         set vdesc [join [ditem_key $ditem description]]
 
         # read global variant description, if none given
-        if {$vdesc == ""} {
+        if {$vdesc eq ""} {
             set vdesc [variant_desc $porturl $variant_provides]
         }
 
@@ -650,7 +668,7 @@
 proc variant_isset {name} {
     global variations
 
-    if {[info exists variations($name)] && $variations($name) == "+"} {
+    if {[info exists variations($name)] && $variations($name) eq "+"} {
         return 1
     }
     return 0
@@ -713,7 +731,7 @@
                 incr lineno
                 set name [lindex $line 0]
                 set desc [lindex $line 1]
-                if {$name != "" && $desc != ""} {
+                if {$name ne "" && $desc ne ""} {
                     set variant_descs_global(${descfile}_$name) $desc
                 } else {
                     ui_warn "Invalid variant description in $descfile at line $lineno"
@@ -763,7 +781,7 @@
     }
     set code [lindex $args end]
     set os [lindex $args 0]
-    set args [lrange $args 1 [expr $len - 2]]
+    set args [lrange $args 1 [expr {$len - 2}]]
 
     foreach arg $args {
         if {[regexp {(^[0-9]+$)} $arg match result]} {
@@ -846,7 +864,7 @@
     foreach {key value} [array get env_array] {
         lappend env_list $key='$value'
     }
-    return [join $env_list]
+    return "\n[join [lsort $env_list] "\n"]"
 }
 
 ########### Distname utility functions ###########
@@ -952,6 +970,8 @@
     }
 
     foreach file $files {
+        global UI_PREFIX
+
         # if $file is an absolute path already, file join will just return the
         # absolute path, otherwise it is $dir/$file
         set file [file join $dir $file]
@@ -970,7 +990,7 @@
 
         set cmdline $portutil::autoconf::sed_command
         if {$extended} {
-            if {$portutil::autoconf::sed_ext_flag == "N/A"} {
+            if {$portutil::autoconf::sed_ext_flag eq "N/A"} {
                 ui_debug "sed extended regexp not available"
                 return -code error "reinplace sed(1) too old"
             }
@@ -979,22 +999,23 @@
         if {$suppress} {
             lappend cmdline -n
         }
-        set cmdline [concat $cmdline [list $pattern < $file >@ $tmpfd]]
-        if {$locale != ""} {
+        set cmdline [concat $cmdline [list $pattern < $file >@ $tmpfd 2>@stderr]]
+        if {$locale ne ""} {
             set env(LC_CTYPE) $locale
         }
+        ui_info "$UI_PREFIX [format [msgcat::mc "Patching %s: %s"] [file tail $file] $pattern]"
         ui_debug "Executing reinplace: $cmdline"
         if {[catch {eval exec $cmdline} error]} {
             global errorInfo
             ui_debug "$errorInfo"
             ui_error "reinplace: $error"
             file delete "$tmpfile"
-            if {$locale != ""} {
+            if {$locale ne ""} {
                 if {$oldlocale_exists} {
                     set env(LC_CTYPE) $oldlocale
                 } else {
                     unset env(LC_CTYPE)
-                    if {$macosx_version == "10.5"} {
+                    if {$macosx_version eq "10.5"} {
                         unsetenv LC_CTYPE
                     }
                 }
@@ -1003,12 +1024,12 @@
             return -code error "reinplace sed(1) failed"
         }
 
-        if {$locale != ""} {
+        if {$locale ne ""} {
             if {$oldlocale_exists} {
                 set env(LC_CTYPE) $oldlocale
             } else {
                 unset env(LC_CTYPE)
-                if {$macosx_version == "10.5"} {
+                if {$macosx_version eq "10.5"} {
                     unsetenv LC_CTYPE
                 }
             }
@@ -1045,20 +1066,15 @@
 }
 
 # delete
-# file delete -force by itself doesn't handle directories properly
-# on systems older than Tiger. Let's recurse using fs-traverse instead.
+# Wrapper for file delete -force
 proc delete {args} {
-    ui_debug "delete: $args"
-    fs-traverse -depth file $args {
-        file delete -force -- $file
-        continue
-    }
+    eval file delete -force -- $args
 }
 
 # touch
 # mimics the BSD touch command
 proc touch {args} {
-    while {[string match -* [lindex $args 0]]} {
+    while {[string match "-*" [lindex $args 0]]} {
         set arg [string range [lindex $args 0] 1 end]
         set args [lrange $args 1 end]
         switch -- $arg {
@@ -1069,7 +1085,7 @@
             t {
                 set narg [lindex $args 0]
                 set args [lrange $args 1 end]
-                if {[string length $narg] == 0} {
+                if {$narg eq ""} {
                     return -code error "touch: option requires an argument -- $arg"
                 }
                 set options($arg) $narg
@@ -1082,7 +1098,7 @@
 
     # parse the r/t options
     if {[info exists options(rt)]} {
-        if {[string equal $options(rt) r]} {
+        if {$options(rt) eq "r"} {
             # -r
             # get atime/mtime from the file
             if {[file exists $options(r)]} {
@@ -1097,9 +1113,9 @@
             # turn it into a CCyymmdd hhmmss
             set timespec {^(?:(\d\d)?(\d\d))?(\d\d)(\d\d)(\d\d)(\d\d)(?:\.(\d\d))?$}
             if {[regexp $timespec $options(t) {} CC YY MM DD hh mm SS]} {
-                if {[string length $YY] == 0} {
+                if {$YY eq ""} {
                     set year [clock format [clock seconds] -format %Y]
-                } elseif {[string length $CC] == 0} {
+                } elseif {$CC eq ""} {
                     if {$YY >= 69 && $YY <= 99} {
                         set year 19$YY
                     } else {
@@ -1108,7 +1124,7 @@
                 } else {
                     set year $CC$YY
                 }
-                if {[string length $SS] == 0} {
+                if {$SS eq ""} {
                     set SS 00
                 }
                 set atime [clock scan "$year$MM$DD $hh$mm$SS"]
@@ -1149,13 +1165,38 @@
 }
 
 # copy
+# Wrapper for file copy
 proc copy {args} {
     eval file copy $args
 }
 
 # move
+# Wrapper for file rename that handles case-only renames
 proc move {args} {
-    eval file rename $args
+    set options {}
+    while {[string match "-*" [lindex $args 0]]} {
+        set arg [string range [lindex $args 0] 1 end]
+        set args [lreplace $args 0 0]
+        switch -- $arg {
+            force {append options -$arg}
+            - break
+            default {return -code error "move: illegal option -- $arg"}
+        }
+    }
+    if {[llength $args] == 2} {
+        set oldname [lindex $args 0]
+        set newname [lindex $args 1]
+        if {[string equal -nocase $oldname $newname] && $oldname ne $newname} {
+            # case-only rename
+            set tempdir [mkdtemp ${oldname}-XXXXXXXX]
+            set tempname $tempdir/[file tail $oldname]
+            file rename $options -- $oldname $tempname
+            file rename $options -- $tempname $newname
+            delete $tempdir
+            return
+        }
+    }
+    eval file rename $options -- $args
 }
 
 # ln
@@ -1163,7 +1204,7 @@
 # ln [-f] [-h] [-s] [-v] source_file [target_file]
 # ln [-f] [-h] [-s] [-v] source_file ... target_dir
 proc ln {args} {
-    while {[string match -* [lindex $args 0]]} {
+    while {[string match "-*" [lindex $args 0]]} {
         set arg [string range [lindex $args 0] 1 end]
         if {[string length $arg] > 1} {
             set remainder -[string range $arg 1 end]
@@ -1189,7 +1230,7 @@
         set files $args
         set target ./
     } else {
-        set files [lrange $args 0 [expr [llength $args] - 2]]
+        set files [lrange $args 0 [expr {[llength $args] - 2}]]
         set target [lindex $args end]
     }
 
@@ -1316,11 +1357,11 @@
     set env(HOME) "${workpath}/.home"
     set env(TMPDIR) "${workpath}/.tmp"
 
-    if {[ditem_key $ditem state] != "no"} {
+    if {[ditem_key $ditem state] ne "no"} {
         set target_state_fd [open_statefile]
     }
 
-    if {$procedure != ""} {
+    if {$procedure ne ""} {
         set targetname [ditem_key $ditem name]
         set target [ditem_key $ditem provides]
         portsandbox::set_profile $target
@@ -1339,14 +1380,14 @@
         if {$result == 0} {
             # Skip the step if required and explain why through ui_debug.
             # check if the step was already done (as mentioned in the state file)
-            if {[ditem_key $ditem state] != "no"
+            if {[ditem_key $ditem state] ne "no"
                     && [check_statefile target $targetname $target_state_fd]} {
                 ui_debug "Skipping completed $targetname ($portname)"
                 set skipped 1
             }
 
             # Of course, if this is a dry run, don't do the task:
-            if {[info exists ports_dryrun] && $ports_dryrun == "yes"} {
+            if {[info exists ports_dryrun] && $ports_dryrun eq "yes"} {
                 # only one message per portname
                 if {$portname != $ports_dry_last_skipped} {
                     ui_notice "For $portname: skipping $targetname (dry run)"
@@ -1378,15 +1419,21 @@
                 #start tracelib
                 if {($result ==0
                   && [info exists ports_trace]
-                  && $ports_trace == "yes"
-                  && $target != "clean")} {
+                  && $ports_trace eq "yes"
+                  && $target ne "clean"
+                  && $target ne "uninstall")} {
+                    # uninstall will open a portfile from registry and call
+                    # deactivate and uninstall there; if we enable trace mode
+                    # for the first level the two trace threads will conflict
+                    # and cause a deadlock.
                     porttrace::trace_start $workpath
 
                     # Enable the fence to prevent any creation/modification
                     # outside the sandbox.
-                    if {$target != "activate"
-                      && $target != "archive"
-                      && $target != "install"} {
+                    if {$target ne "activate"
+                      && $target ne "deactivate"
+                      && $target ne "archive"
+                      && $target ne "install"} {
                         porttrace::trace_enable_fence
                     }
 
@@ -1425,7 +1472,7 @@
                     # Gather the dependencies for deptypes
                     foreach deptype $deptypes {
                         # Add to the list of dependencies if the option exists and isn't empty.
-                        if {[info exists PortInfo($deptype)] && $PortInfo($deptype) != ""} {
+                        if {[info exists PortInfo($deptype)] && $PortInfo($deptype) ne ""} {
                             set depends [concat $depends $PortInfo($deptype)]
                         }
                     }
@@ -1438,7 +1485,7 @@
 
                         # If portname is empty, the dependency is already satisfied by other means,
                         # for example a bin: dependency on a file not installed by MacPorts
-                        if {$name != ""} {
+                        if {$name ne ""} {
                             if {[lsearch -exact $deplist $name] == -1} {
                                 lappend deplist $name
                                 set deplist [recursive_collect_deps $name $deplist]
@@ -1447,7 +1494,7 @@
                     }
 
                     # Add ccache port for access to ${prefix}/bin/ccache binary
-                    if [option configure.ccache] {
+                    if {[option configure.ccache]} {
                         lappend deplist ccache
                     }
 
@@ -1485,20 +1532,12 @@
                         if {$result != 0} { break }
                     }
                 }
-                # Execute post-run procedure
-                if {[ditem_contains $ditem postrun] && $result == 0} {
-                    set postrun [ditem_key $ditem postrun]
-                    ui_debug "Executing $postrun"
-                    set result [catch {eval $postrun $targetname} errstr]
-                    # Save variables in order to re-throw the same error code.
-                    set errcode $::errorCode
-                    set errinfo $::errorInfo
-                }
 
                 # Check dependencies & file creations outside workpath.
                 if {[info exists ports_trace]
-                  && $ports_trace == "yes"
-                  && $target!="clean"} {
+                  && $ports_trace eq "yes"
+                  && $target ne "clean"
+                  && $target ne "uninstall"} {
 
                     tracelib closesocket
 
@@ -1507,6 +1546,17 @@
                     # End of trace.
                     porttrace::trace_stop
                 }
+
+                # Execute post-run procedure
+                if {[ditem_contains $ditem postrun] && $result == 0} {
+                    set postrun [ditem_key $ditem postrun]
+                    ui_debug "Executing $postrun"
+                    set result [catch {eval $postrun $targetname} errstr]
+                    # Save variables in order to re-throw the same error code.
+                    set errcode $::errorCode
+                    set errinfo $::errorInfo
+                }
+
                 # $oldpwd is deleted while uninstalling a port, changing back
                 # _will_ fail
                 catch {_cd $oldpwd}
@@ -1530,8 +1580,8 @@
             # - this step is not to always be performed
             # - this step must be written to file
             if {$skipped == 0
-          && [ditem_key $ditem runtype] != "always"
-          && [ditem_key $ditem state] != "no"} {
+          && [ditem_key $ditem runtype] ne "always"
+          && [ditem_key $ditem state] ne "no"} {
             write_statefile target $targetname $target_state_fd
             }
         } else {
@@ -1546,14 +1596,14 @@
         set result 1
     }
 
-    if {[ditem_key $ditem state] != "no"} {
+    if {[ditem_key $ditem state] ne "no"} {
         close $target_state_fd
     }
 
     set env(HOME) $savedhome
     if {[info exists env(TMPDIR)]} {
         unset env(TMPDIR)
-        if {$macosx_version == "10.5"} {
+        if {$macosx_version eq "10.5"} {
             unsetenv TMPDIR
         }
     }
@@ -1589,10 +1639,10 @@
     # the statefile will likely be autocleaned away after install,
     # so special-case already-completed install and activate
     if {[registry_exists $subport $version $revision $portvariants]} {
-        if {$target == "install"} {
+        if {$target eq "install"} {
             ui_debug "Skipping $target ($subport) since this port is already installed"
             return 0
-        } elseif {$target == "activate"} {
+        } elseif {$target eq "activate"} {
             set regref [registry_open $subport $version $revision $portvariants ""]
             if {[registry_prop_retr $regref active] != 0} {
                 # Something to close the registry entry may be called here, if it existed.
@@ -1610,13 +1660,13 @@
     }
 
     # Select the subset of targets under $target
-    if {$target != ""} {
+    if {$target ne ""} {
         set matches [dlist_search $dlist provides $target]
 
         if {[llength $matches] > 0} {
             set dlist [dlist_append_dependents $dlist [lindex $matches 0] [list]]
             # Special-case 'all'
-        } elseif {$target != "all"} {
+        } elseif {$target ne "all"} {
             ui_error "unknown target: $target"
             return 1
         }
@@ -1911,9 +1961,9 @@
         set ignored 0
         foreach flavor [ditem_key $ditem provides] {
             if {[info exists upvariations($flavor)]} {
-                if {$upvariations($flavor) == "+"} {
+                if {$upvariations($flavor) eq "+"} {
                     incr pros
-                } elseif {$upvariations($flavor) == "-"} {
+                } elseif {$upvariations($flavor) eq "-"} {
                     incr cons
                 }
             } else {
@@ -2069,14 +2119,14 @@
         set ditems [dlist_append_dependents $targets [lindex $ditems 0] [list]]
     }
     foreach d $ditems {
-        if {[ditem_key $d state] != "no"} {
+        if {[ditem_key $d state] ne "no"} {
             # At least one matching target requires the state file
             set statereq 1
             break
         }
     }
     if { $statereq &&
-        !([info exists ports_force] && $ports_force == "yes")} {
+        !([info exists ports_force] && $ports_force eq "yes")} {
 
         set state_fd [open_statefile]
 
@@ -2084,7 +2134,7 @@
         if {[check_statefile_variants variations oldvariations $state_fd]} {
             ui_error "Requested variants \"[canonicalize_variants [array get variations]]\" do not match original selection \"[canonicalize_variants [array get oldvariations]]\".\nPlease use the same variants again, perform 'port clean [option subport]' or specify the force option (-f)."
             set result 1
-        } elseif {!([info exists ports_dryrun] && $ports_dryrun == "yes")} {
+        } elseif {!([info exists ports_dryrun] && $ports_dryrun eq "yes")} {
             # Write variations out to the statefile
             foreach key [array names variations *] {
                 write_statefile variant $variations($key)$key $state_fd
@@ -2139,7 +2189,7 @@
     foreach target $args {
         set origproc [ditem_key $ditem procedure]
         set ident [ditem_key $ditem name]
-        if {[info commands $target] == ""} {
+        if {[info commands $target] eq ""} {
             proc $target {args} "
                 variable proc_index
                 set proc_index \[llength \[ditem_key $ditem proc\]\]
@@ -2235,7 +2285,6 @@
                 set PortInfo(vinfo) {}
             }
             array set vinfo $PortInfo(vinfo)
-
             foreach v $value {
                 if {[regexp {([-+])([-A-Za-z0-9_]+)} $v whole val variant] && ![info exists variations($variant)]} {
                     # Retrieve the information associated with this variant.
@@ -2265,9 +2314,9 @@
 proc handle_add_users {} {
     set cur ""
     foreach val [option add_users] {
-        if {[string match *=* $val] && $cur != ""} {
+        if {[string match "*=*" $val] && $cur ne ""} {
             set split_arg [split $val =]
-            if {[lindex $split_arg 0] == "group"} {
+            if {[lindex $split_arg 0] eq "group"} {
                 set groupname [lindex $split_arg 1]
                 addgroup $groupname
                 lappend args($cur) gid=[existsgroup $groupname]
@@ -2314,22 +2363,74 @@
 
     if {${os.platform} eq "darwin"} {
         set dscl [findBinary dscl $portutil::autoconf::dscl_path]
-        exec $dscl . -create /Users/${name} UniqueID ${uid}
+        set failed? 0
+        try {
+            exec $dscl . -create /Users/${name} UniqueID ${uid} 2>@stderr
 
-        # These are implicitly added on Mac OSX Lion.  AuthenticationAuthority
-        # causes the user to be visible in the Users & Groups Preference Pane,
-        # and the others are just noise, so delete them.
-        # https://trac.macports.org/ticket/30168
-        exec $dscl . -delete /Users/${name} AuthenticationAuthority
-        exec $dscl . -delete /Users/${name} PasswordPolicyOptions
-        exec $dscl . -delete /Users/${name} dsAttrTypeNative:KerberosKeys
-        exec $dscl . -delete /Users/${name} dsAttrTypeNative:ShadowHashData
+            # These are implicitly added on Mac OSX Lion.  AuthenticationAuthority
+            # causes the user to be visible in the Users & Groups Preference Pane,
+            # and the others are just noise, so delete them.
+            # https://trac.macports.org/ticket/30168
+            exec $dscl . -delete /Users/${name} AuthenticationAuthority 2>@stderr
+            exec $dscl . -delete /Users/${name} PasswordPolicyOptions 2>@stderr
+            exec $dscl . -delete /Users/${name} dsAttrTypeNative:KerberosKeys 2>@stderr
+            exec $dscl . -delete /Users/${name} dsAttrTypeNative:ShadowHashData 2>@stderr
 
-        exec $dscl . -create /Users/${name} RealName ${realname}
-        exec $dscl . -create /Users/${name} Password ${passwd}
-        exec $dscl . -create /Users/${name} PrimaryGroupID ${gid}
-        exec $dscl . -create /Users/${name} NFSHomeDirectory ${home}
-        exec $dscl . -create /Users/${name} UserShell ${shell}
+            exec $dscl . -create /Users/${name} RealName ${realname} 2>@stderr
+            exec $dscl . -create /Users/${name} Password ${passwd} 2>@stderr
+            exec $dscl . -create /Users/${name} PrimaryGroupID ${gid} 2>@stderr
+            exec $dscl . -create /Users/${name} NFSHomeDirectory ${home} 2>@stderr
+            exec $dscl . -create /Users/${name} UserShell ${shell} 2>@stderr
+        } catch {{CHILDKILLED *} eCode eMessage} {
+            # the foreachs are a simple workaround for Tcl 8.4, which doesn't
+            # seem to have lassign
+            foreach {- pid sigName msg} $eCode {
+                ui_error "dscl($pid) was killed by $sigName: $msg"
+                ui_debug "dscl printed: $eMessage"
+            }
+
+            set failed? 1
+        } catch {{CHILDSTATUS *} eCode eMessage} {
+            foreach {- pid code} $eCode {
+                ui_error "dscl($pid) termined with an exit status of $code"
+                ui_debug "dscl printed: $eMessage"
+            }
+            
+            set failed? 1
+        } catch {{POSIX *} eCode eMessage} {
+            foreach {- errName msg} {
+                ui_error "failed to execute $dscl: $errName: $msg"
+                ui_debug "dscl printed: $eMessage"
+            }
+
+            set failed? 1
+        } finally {
+            if {${failed?}} {
+                # creating the user properly failed and we're bailing out
+                # anyway, try to delete the half-created user to revert to the
+                # state before the error
+                ui_debug "Attempting to clean up failed creation of user $name"
+                try {
+                    exec $dscl . -delete /Users/${name} 2>@stderr
+                } catch {{CHILDKILLED *} eCode eMessage} {
+                    foreach {- pid sigName msg} {
+                        ui_warn "dscl($pid) was killed by $sigName: $msg while trying to clean up failed creation of user $name."
+                        ui_debug "dscl printed: $eMessage"
+                    }
+                } catch {{CHILDSTATUS *} eCode eMessage} {
+                    # ignoring childstatus failure, because that probably means
+                    # the first call failed and the user wasn't even created
+                } catch {{POSIX *} eCode eMessage} {
+                    foreach {- errName msg} {
+                        ui_warn "failed to execute $dscl: $errName: $msg while trying to clean up failed creation of user $name."
+                        ui_debug "dscl printed: $eMessage"
+                    }
+                }
+
+                # and raise an error to abort
+                error "dscl failed to create required user $name."
+            }
+        }
     } else {
         # XXX adduser is only available for darwin, add more support here
         ui_warn "adduser is not implemented on ${os.platform}."
@@ -2370,11 +2471,63 @@
 
     if {${os.platform} eq "darwin"} {
         set dscl [findBinary dscl $portutil::autoconf::dscl_path]
-        exec $dscl . -create /Groups/${name} Password ${passwd}
-        exec $dscl . -create /Groups/${name} RealName ${realname}
-        exec $dscl . -create /Groups/${name} PrimaryGroupID ${gid}
-        if {${users} ne ""} {
-            exec $dscl . -create /Groups/${name} GroupMembership ${users}
+        set failed? 0
+        try {
+            exec $dscl . -create /Groups/${name} Password ${passwd}
+            exec $dscl . -create /Groups/${name} RealName ${realname}
+            exec $dscl . -create /Groups/${name} PrimaryGroupID ${gid}
+            if {${users} ne ""} {
+                exec $dscl . -create /Groups/${name} GroupMembership ${users}
+            }
+        } catch {{CHILDKILLED *} eCode eMessage} {
+            # the foreachs are a simple workaround for Tcl 8.4, which doesn't
+            # seem to have lassign
+            foreach {- pid sigName msg} $eCode {
+                ui_error "dscl($pid) was killed by $sigName: $msg"
+                ui_debug "dscl printed: $eMessage"
+            }
+
+            set failed? 1
+        } catch {{CHILDSTATUS *} eCode eMessage} {
+            foreach {- pid code} $eCode {
+                ui_error "dscl($pid) termined with an exit status of $code"
+                ui_debug "dscl printed: $eMessage"
+            }
+            
+            set failed? 1
+        } catch {{POSIX *} eCode eMessage} {
+            foreach {- errName msg} {
+                ui_error "failed to execute $dscl: $errName: $msg"
+                ui_debug "dscl printed: $eMessage"
+            }
+
+            set failed? 1
+        } finally {
+            if {${failed?}} {
+                # creating the user properly failed and we're bailing out
+                # anyway, try to delete the half-created user to revert to the
+                # state before the error
+                ui_debug "Attempting to clean up failed creation of group $name"
+                try {
+                    exec $dscl . -delete /Groups/${name} 2>@stderr
+                } catch {{CHILDKILLED *} eCode eMessage} {
+                    foreach {- pid sigName msg} {
+                        ui_warn "dscl($pid) was killed by $sigName: $msg while trying to clean up failed creation of group $name."
+                        ui_debug "dscl printed: $eMessage"
+                    }
+                } catch {{CHILDSTATUS *} eCode eMessage} {
+                    # ignoring childstatus failure, because that probably means
+                    # the first call failed and the user wasn't even created
+                } catch {{POSIX *} eCode eMessage} {
+                    foreach {- errName msg} {
+                        ui_warn "failed to execute $dscl: $errName: $msg while trying to clean up failed creation of group $name."
+                        ui_debug "dscl printed: $eMessage"
+                    }
+                }
+
+                # and raise an error to abort
+                error "dscl failed to create required group $name."
+            }
         }
     } else {
         # XXX addgroup is only available for darwin, add more support here
@@ -2422,6 +2575,7 @@
 
     if {[file exists $groupFile]} {
         uplevel "source $groupFile"
+        ui_debug "Sourcing PortGroup $group $version from $groupFile"
     } else {
         ui_warn "PortGroup ${group} ${version} could not be located. ${group}-${version}.tcl does not exist."
     }
@@ -2446,7 +2600,7 @@
 # return path where a newly created image/archive for this port will be stored
 proc get_portimage_path {} {
     global portdbpath subport
-    return [file join ${portdbpath} software ${subport} [get_portimage_name]]
+    return [file normalize [file join ${portdbpath} software ${subport} [get_portimage_name]]]
 }
 
 # return list of archive types that we can extract
@@ -2607,7 +2761,7 @@
         close $fd
         file delete -force $tempdir
     }
-    if {$metadata_type == "contents"} {
+    if {$metadata_type eq "contents"} {
         set contents {}
         set ignore 0
         set sep [file separator]
@@ -2623,7 +2777,7 @@
             }
         }
         return $contents
-    } elseif {$metadata_type == "portname"} {
+    } elseif {$metadata_type eq "portname"} {
         foreach line [split $raw_contents \n] {
             if {[lindex $line 0] == "@portname"} {
                 return [lindex $line 1]
@@ -2688,7 +2842,7 @@
     set archs ""
     set base_arch ""
     foreach arch ${configure.universal_archs} {
-        if [file exists "${base}/${arch}"] {
+        if {[file exists "${base}/${arch}"]} {
             set archs [concat ${archs} ${arch}]
             set base_arch ${arch}
         }
@@ -2812,7 +2966,7 @@
         }
     } else {
         # not root, so can't set owner/group
-        set permissions [lindex $attributes [expr [lsearch $attributes "-permissions"] + 1]]
+        set permissions [lindex $attributes [expr {[lsearch $attributes "-permissions"] + 1}]]
         file attributes $file -permissions $permissions
     }
 }
@@ -2865,7 +3019,7 @@
 
 proc validate_macportsuser {} {
     global macportsuser
-    if {[getuid] == 0 && $macportsuser != "root" && 
+    if {[getuid] == 0 && $macportsuser ne "root" && 
         ([existsuser $macportsuser] == 0 || [existsgroup $macportsuser] == 0 )} {
         ui_warn "configured user/group $macportsuser does not exist, will build as root"
         set macportsuser "root"
@@ -2906,7 +3060,7 @@
 
     set i [string first . $depline]
     if {$i < 0} {set i [string length $depline]}
-    set depname [string range $depline 0 [expr $i - 1]]
+    set depname [string range $depline 0 [expr {$i - 1}]]
     set depversion [string range $depline $i end]
     regsub {\.} $depversion {\.} depversion
     if {${os.platform} == "darwin"} {
@@ -2942,7 +3096,7 @@
 
     regexp {^(.*)/(.*?)$} "$fullname" match search_path depregex
 
-    if {[string index $search_path 0] != "/"} {
+    if {[string index $search_path 0] ne "/"} {
         # Prepend prefix if not an absolute path
         set search_path "${prefix}/${search_path}"
     }
@@ -2973,7 +3127,7 @@
             set depfile [_pathtest $depspec 1]
         }
     }
-    if {$depfile == ""} {
+    if {$depfile eq ""} {
         return $portname
     } else {
         set theport [registry_file_registered $depfile]
@@ -2988,7 +3142,7 @@
 # returns the list of archs that the port is targeting
 proc get_canonical_archs {} {
     global supported_archs os.arch configure.build_arch configure.universal_archs
-    if {$supported_archs == "noarch"} {
+    if {$supported_archs eq "noarch"} {
         return "noarch"
     } elseif {[variant_exists universal] && [variant_isset universal]} {
         return [lsort -ascii ${configure.universal_archs}]
@@ -3006,7 +3160,7 @@
             return -code error "archflags do not exist for tool '$tool'"
         }
     } else {
-        if {$tool == "cc"} {
+        if {$tool eq "cc"} {
             set tool c
         }
         if {[catch {option configure.universal_${tool}flags} flags]} {
@@ -3019,7 +3173,7 @@
 # check that the selected archs are supported
 proc check_supported_archs {} {
     global supported_archs build_arch universal_archs configure.build_arch configure.universal_archs subport
-    if {$supported_archs == "noarch"} {
+    if {$supported_archs eq "noarch"} {
         return 0
     } elseif {[variant_exists universal] && [variant_isset universal]} {
         if {[llength ${configure.universal_archs}] > 1 || $universal_archs == ${configure.universal_archs}} {
@@ -3028,7 +3182,7 @@
             ui_error "$subport cannot be installed for the configured universal_archs '$universal_archs' because it only supports the arch(s) '$supported_archs'."
             return 1
         }
-    } elseif {$build_arch == "" || ${configure.build_arch} != ""} {
+    } elseif {$build_arch eq "" || ${configure.build_arch} != ""} {
         return 0
     }
     ui_error "$subport cannot be installed for the configured build_arch '$build_arch' because it only supports the arch(s) '$supported_archs'."
@@ -3039,7 +3193,7 @@
 proc _check_xcode_version {} {
     global os.subplatform macosx_version xcodeversion
 
-    if {${os.subplatform} == "macosx"} {
+    if {${os.subplatform} eq "macosx"} {
         switch $macosx_version {
             10.4 {
                 set min 2.0
@@ -3059,15 +3213,20 @@
             10.7 {
                 set min 4.1
                 set ok 4.1
-                set rec 4.6.2
+                set rec 4.6.3
             }
-            default {
+            10.8 {
                 set min 4.4
                 set ok 4.4
-                set rec 4.6.2
+                set rec 4.6.3
             }
+            default {
+                set min 5.0.1
+                set ok 5.0.1
+                set rec 5.0.1
+            }
         }
-        if {$xcodeversion == "none"} {
+        if {$xcodeversion eq "none"} {
             ui_warn "Xcode does not appear to be installed; most ports will likely fail to build."
             if {[file exists "/Applications/Install Xcode.app"]} {
                 ui_warn "You downloaded Xcode from the Mac App Store but didn't install it. Run \"Install Xcode\" in the /Applications folder."
@@ -3079,16 +3238,38 @@
             ui_warn "The installed version of Xcode (${xcodeversion}) is known to cause problems. Version $rec or later is recommended on Mac OS X ${macosx_version}."
         }
 
-        # Xcode 4.3 requires the command-line utilities package to be
-        # installed. 
-        if {[vercmp $xcodeversion 4.3] >= 0 ||
-            ($xcodeversion == "none" && [file exists "/Applications/Xcode.app"])} {
-            if {![file exists "/usr/bin/make"]} {
-                ui_warn "The Command Line Tools for Xcode don't appear to be installed; most ports will likely fail to build."
-                ui_warn "See http://guide.macports.org/chunked/installing.xcode.html for more information."
+        # Xcode 4.3 and above requires the command-line utilities package to be installed. 
+        if {[vercmp $xcodeversion 4.3] >= 0 || ($xcodeversion eq "none" && [file exists "/Applications/Xcode.app"])} {
+            if {[vercmp $macosx_version 10.9] >= 0} {
+                # on Mavericks, /usr/bin/make might always installed as a shim into the command line tools installer.
+                # Let's check for /Library/Developer/CommandLineTools, installed by the
+                # com.apple.pkg.CLTools_Executables package.
+                set cltpath "/Library/Developer/CommandLineTools"
+            } else {
+                set cltpath "/"
             }
+
+            # Check whether /usr/include and /usr/bin/make exist and tell users to install the command line tools, if they don't
+            if {   ![file isdirectory [file join $cltpath usr include]]
+                || ![file executable  [file join $cltpath usr bin make]]} {
+                ui_warn "The Xcode Command Line Tools don't appear to be installed; most ports will likely fail to build."
+                if {[vercmp $macosx_version 10.9] >= 0} {
+                    ui_warn "Install them by running `xcode-select --install'."
+                } else {
+                    ui_warn "You can install them from Xcode's Preferences in the Downloads section."
+                    ui_warn "See http://guide.macports.org/chunked/installing.xcode.html#installing.xcode.lion.43 for more information."
+                }
+            }
+
+            # Check whether users have agreed to the Xcode license agreement
+            catch {exec [findBinary xcrun $portutil::autoconf::xcrun_path] clang 2>@1} output
+            set output [join [lrange [split $output "\n"] 0 end-1] "\n"]
+            if {[string match -nocase "*license*" $output]} {
+                ui_error "It seems you have not accepted the Xcode license; most ports will fail to build."
+                ui_error "Agree to the license by opening Xcode or running `sudo xcodebuild -license'."
+                return 1
+            }
         }
-        
     }
     return 0
 }
@@ -3106,13 +3287,13 @@
         return 0
     }
 
-    if {[find_portarchive_path] != ""} {
+    if {[find_portarchive_path] ne ""} {
         set archive_available_result 1
         return 1
     }
 
     set archiverootname [file rootname [get_portimage_name]]
-    if {[file rootname [file tail $porturl]] == $archiverootname && [file extension $porturl] != ""} {
+    if {[file rootname [file tail $porturl]] eq $archiverootname && [file extension $porturl] ne ""} {
         set archive_available_result 1
         return 1
     }
@@ -3134,7 +3315,7 @@
     # look for and strip off any tag, which will start with the first colon after the
     # first slash after the ://
     set lastcolon [string last : $sites_entry]
-    set aftersep [expr [string first : $sites_entry] + 3]
+    set aftersep [expr {[string first : $sites_entry] + 3}]
     set firstslash [string first / $sites_entry $aftersep]
     if {$firstslash != -1 && $firstslash < $lastcolon} {
         incr lastcolon -1
@@ -3142,7 +3323,7 @@
     } else {
         set site $sites_entry
     }
-    if {[string index $site end] != "/"} {
+    if {[string index $site end] ne "/"} {
         append site "/[option archive.subdir]"
     } else {
         append site [option archive.subdir]

Copied: branches/new-help-system/base/src/port1.0/tests/Portfile (from rev 117083, trunk/base/src/port1.0/tests/Portfile)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/Portfile	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/Portfile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,55 @@
+# $Id: Portfile 85472 2011-10-14 01:52:18Z dports at macports.org $
+
+PortSystem              1.0
+
+name                    fondu
+version                 060102
+revision                1
+platforms               darwin
+categories              print
+license                 BSD
+maintainers             nomaintainer
+homepage                http://fondu.sourceforge.net/
+master_sites            http://fondu.sourceforge.net/
+
+description             A set of programs to interconvert between Mac font \
+                        formats and pfb, ttf, otf and bdf files on UNIX.
+
+long_description        Dealing with Mac fonts is hard on other operating \
+                        systems because Mac fonts are stored in the resource \
+                        fork, and other operating systems do not support \
+                        this concept. Fondu will extract the resource fork \
+                        from either a MacBinary file or a BinHex file. Ufond \
+                        will create a resource fork inside a MacBinary file.
+
+checksums               md5 e20861beacddc1ab392bef7813641bf8
+extract.suffix          .tgz
+distfiles               ${name}_src-${version}${extract.suffix}
+
+patchfiles
+
+patch {
+    foreach patch $patchfiles {
+        set fd [open ${portpath}/files/${patch} r]
+        set var [gets $fd]
+        close $fd
+        set fd [open ${workpath}/${distname}/test_patch w+]
+        puts $fd $var
+        close $fd
+    }
+}
+
+post-patch {
+    reinplace "s|^CFLAGS = -g \$(WFLAGS)|CFLAGS = -g \$(WFLAGS) ${configure.cppflags} ${configure.cflags} ${configure.ldflags} [get_canonical_archflags]|g" ${worksrcpath}/Makefile.in
+}
+
+configure.args          --bindir=${prefix}/bin \
+                        --mandir=${prefix}/share/man
+
+post-destroot {
+    eval xinstall -m 644 [glob ${worksrcpath}/*.1] ${destroot}${prefix}/share/man/man1/
+}
+
+test {
+    file delete -force $worksrcpath/README
+}

Deleted: branches/new-help-system/base/src/port1.0/tests/common.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/common.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/tests/common.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,18 +0,0 @@
-proc test_equal {statement value} {
-    uplevel 1 "\
-        puts -nonewline {checking if $statement == \"$value\"... }
-        if {\[catch {
-                set actual $statement
-                if {\$actual == \[subst {$value}\]} { \n\
-                    puts yes
-                } else { \n\
-                    puts \"no (was \$actual)\" \n\
-                    exit 1 \n\
-                } \n\
-            } msg\]} { \n\
-                puts \"caught error: \$msg\" \n\
-                exit 1 \n\
-            }"
-}
-
-

Copied: branches/new-help-system/base/src/port1.0/tests/library.tcl (from rev 117083, trunk/base/src/port1.0/tests/library.tcl)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/library.tcl	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/library.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,65 @@
+##
+# This is basically a copy of macports::worker_init, but without using
+# sub-interpreters
+proc macports_worker_init {} {
+    interp alias {} _cd {} cd
+    proc PortSystem {version} {
+        package require port $version
+    }
+    # Clearly separate slave interpreters and the master interpreter.
+    interp alias {} mport_exec      {} mportexec
+    interp alias {} mport_open      {} mportopen
+    interp alias {} mport_close     {} mportclose
+    interp alias {} mport_lookup    {} mportlookup
+    interp alias {} mport_info      {} mportinfo
+    # Export some utility functions defined here.
+    interp alias {} macports_create_thread          {} macports::create_thread
+    interp alias {} getportworkpath_from_buildpath  {} macports::getportworkpath_from_buildpath
+    interp alias {} getportresourcepath             {} macports::getportresourcepath
+    interp alias {} getportlogpath                  {} macports::getportlogpath
+    interp alias {} getdefaultportresourcepath      {} macports::getdefaultportresourcepath
+    interp alias {} getprotocol                     {} macports::getprotocol
+    interp alias {} getportdir                      {} macports::getportdir
+    interp alias {} findBinary                      {} macports::findBinary
+    interp alias {} binaryInPath                    {} macports::binaryInPath
+    # New Registry/Receipts stuff
+    interp alias {} registry_new                    {} registry::new_entry
+    interp alias {} registry_open                   {} registry::open_entry
+    interp alias {} registry_write                  {} registry::write_entry
+    interp alias {} registry_prop_store             {} registry::property_store
+    interp alias {} registry_prop_retr              {} registry::property_retrieve
+    interp alias {} registry_exists                 {} registry::entry_exists
+    interp alias {} registry_exists_for_name        {} registry::entry_exists_for_name
+    interp alias {} registry_activate               {} portimage::activate
+    interp alias {} registry_deactivate             {} portimage::deactivate
+    interp alias {} registry_deactivate_composite   {} portimage::deactivate_composite
+    interp alias {} registry_uninstall              {} registry_uninstall::uninstall
+    interp alias {} registry_register_deps          {} registry::register_dependencies
+    interp alias {} registry_fileinfo_for_index     {} registry::fileinfo_for_index
+    interp alias {} registry_fileinfo_for_file      {} registry::fileinfo_for_file
+    interp alias {} registry_bulk_register_files    {} registry::register_bulk_files
+    interp alias {} registry_active                 {} registry::active
+    interp alias {} registry_file_registered        {} registry::file_registered
+    interp alias {} registry_port_registered        {} registry::port_registered
+    interp alias {} registry_list_depends           {} registry::list_depends
+    # deferred options processing.
+    interp alias {} getoption {} macports::getoption
+    # ping cache
+    interp alias {} get_pingtime {} macports::get_pingtime
+    interp alias {} set_pingtime {} macports::set_pingtime
+    # archive_sites.conf handling
+    interp alias {} get_archive_sites_conf_values {} macports::get_archive_sites_conf_values
+    foreach opt $macports::portinterp_options {
+        if {![info exists $opt]} {
+            global macports::$opt
+            set ::$opt macports::$opt
+        }
+        if {[info exists $opt]} {
+            set system_options($opt) $opt
+            set ::$opt $opt
+        }
+    }
+
+    # We don't need to handle portinterp_deferred_options, they're
+    # automatically handled correctly.
+}

Copied: branches/new-help-system/base/src/port1.0/tests/portactivate.test (from rev 117083, trunk/base/src/port1.0/tests/portactivate.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portactivate.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portactivate.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,107 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portactivate 1.0
+package require registry 1.0
+source ./library.tcl
+macports_worker_init
+
+
+test activate_start {
+    Activate start unit test.
+    Requires root for setting euid.
+} -constraints {
+    root
+} -setup {
+    # file writable $prefix is used to determine whether privilege escalation
+    # is needed, so set prefix to a directory unwritable for this user
+    set prefix /usr/bin
+
+    # elevateToRoot uses $euid and $egid as the IDs to set
+    set euid 0
+    set egid 0
+
+} -body {
+    # drop privileges; the code won't attempt to elevate privileges without
+    # that
+    seteuid 333
+    if {[catch {portactivate::activate_start args}] != 0} {
+        return "FAIL: couldn't elevate privileges"
+    }
+
+    # when uid == 0 and euid == 0, the code will not attempt to elevate
+    # privileges
+    seteuid 0
+    if {[catch {portactivate::activate_start args}] != 0} {
+        return "FAIL: couldn't elevate privileges"
+    }
+    return "Activate_start successful."
+} -result "Activate_start successful."
+
+
+test activate_main {
+    Activate main unit test.
+} -constraints {
+    root
+} -setup {
+    set destpath $pwd/work/destroot
+    set portbuildpath $pwd
+    set portdbpath $pwd/dbpath
+    set portpath $pwd
+
+    set mport [mportopen file://.]
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+
+    # hide all output. Deactivate this for debugging!
+    set oldchannels [array get macports::channels]
+    set macports::channels(msg)    {}
+    set macports::channels(notice) {}
+
+    if {[$workername eval eval_targets install] != 0} {
+        return "FAIL: port install failed"
+    }
+
+} -body {
+    if {[$workername eval eval_targets activate] != 0} {
+        return "FAIL: cannot activate port after install"
+    }
+    if {[$workername eval eval_targets deactivate] != 0} {
+        return "FAIL: cannot deactivate port"
+    }
+    if {[$workername eval eval_targets activate] != 0} {
+        return "FAIL: cannot activate port after deactivate"
+    }
+    return "Port activate successful."
+
+} -cleanup {
+    if {[$workername eval eval_targets uninstall] != 0} {
+        return "FAIL: uninstall failed"
+    }
+    if {[$workername eval eval_targets clean] != 0} {
+        return "FAIL: clean failed"
+    }
+    array set macports::channels $oldchannels
+
+    mportclose $mport
+} -result "Port activate successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portchecksum.test (from rev 117083, trunk/base/src/port1.0/tests/portchecksum.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portchecksum.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portchecksum.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,148 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portchecksum 1.0
+
+
+test parse_checksum {
+    Parse checksum unit test.
+} -body {
+    set all_dist_files {file file2}
+    set checksums_str {file md5 1111 file2 sha1 3333}
+
+    set res [portchecksum::parse_checksums $checksums_str]
+    if {$res != "yes"} {return "FAIL: error in checksum parse"}
+    if {$checksums_array(file) != "md5 1111"} {
+	   return "FAIL: invalid file options"
+    }
+    if {$checksums_array(file2) != "sha1 3333"} {
+	   return "FAIL: invalid file options"
+    }
+    return "Parse checksum successful."
+} -result "Parse checksum successful."
+
+
+test calc_md5 {
+    Calculate md5 unit test. Based on a file it creates.
+} -body {
+    set fd [open $pwd/file w+]
+    puts $fd "test.file"
+    close $fd
+
+    set res [portchecksum::calc_md5 $pwd/file]
+    if {$res != "9f70ecc1095ff10df81be6b5f218328d"} {
+	   return "FAIL: unexpected md5"
+    }
+    return "Calc md5 successful."
+
+} -cleanup {
+    file delete -force $pwd/file
+} -result "Calc md5 successful."
+
+
+test calc_sha1 {
+    Calculate sha1 unit test.
+} -body {
+    set fd [open $pwd/file w+]
+    puts $fd "test.file"
+    close $fd
+
+    set res [portchecksum::calc_sha1 $pwd/file]
+    if {$res != "5560df60ff202ca8b8c3dcf51ad650b78e859261"} {
+	   return "FAIL: unexpected sha1"
+    }
+    return "Calc sha1 successful."
+
+} -cleanup {
+    file delete -force $pwd/file
+} -result "Calc sha1 successful."
+
+
+test calc_rmd160 {
+    Calculate rmd160 unit test.
+} -body {
+    set fd [open $pwd/file w+]
+    puts $fd "test.file"
+    close $fd
+
+    set res [portchecksum::calc_rmd160 $pwd/file]
+    if {$res != "5aee5d12fe536e2e288e9f1daafd84f1bc17c3e6"} {
+	   return "FAIL: unexpected rmd160"
+    }
+    return "Calc rmd160 successful."
+
+} -cleanup {
+    file delete -force $pwd/file
+} -result "Calc rmd160 successful."
+
+
+test calc_sha256 {
+    Calculate sha256 unit test.
+} -body {
+    set fd [open $pwd/file w+]
+    puts $fd "test.file"
+    close $fd
+
+    set res [portchecksum::calc_sha256 $pwd/file]
+    if {$res != "2f686816f2a80e8efcc4ef40ac4e898d27ce4205a61ee422d56f8c5e8b46612e"} {
+	   return "FAIL: unexpected sha1"
+    }
+    return "Calc sha256 successful."
+
+} -cleanup {
+    file delete -force $pwd/file
+} -result "Calc sha256 successful."
+
+
+# test checksum_start
+
+
+test checksum_main {
+    Checksum main unit test. Checks for empty files.
+} -body {
+    set all_dist_files {file file2}
+    set checksum.skip yes
+
+    if {[portchecksum::checksum_main] != 0} {
+	   return "FAIL: checksum not skipped"
+    }
+
+    set checksum.skip no
+    set distpath $pwd/dpath
+    set usealtworkpath no
+    set altprefix prefix
+
+    file mkdir $distpath
+    close [open $distpath/file w]
+    close [open $distpath/file2 w]
+    array set checksums_array {
+	   file {md5 d41d8cd98f00b204e9800998ecf8427e}
+	   file2 {sha1 da39a3ee5e6b4b0d3255bfef95601890afd80709}
+    }
+
+    if {[portchecksum::checksum_main] != 0} {
+	   return "FAIL: incorrect checksum"
+    }
+    return "Checksum main successful."
+
+} -cleanup {
+    file delete -force $distpath
+    file delete -force file
+    file delete -force file2
+} -result "Checksum main successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portclean.test (from rev 117083, trunk/base/src/port1.0/tests/portclean.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portclean.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portclean.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,213 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portclean 1.0
+source ../port_autoconf.tcl
+source ./library.tcl
+macports_worker_init
+
+
+test clean_start {
+    Clean start unit test.
+} -constraints {
+    root
+} -body {
+    set prefix /opt/local
+    seteuid 333
+    if {[catch {clean_start args}] != 1} {
+       return "FAIL: couldn't elevate privileges"
+    }
+    seteuid 0
+    return "Clean_start successful."
+} -result "Clean_start successful."
+
+
+# test clean_main
+
+
+test clean_dist {
+    Clean distfiles unit test.
+} -body {
+    set usealtworkpath no
+    set ports_force yes
+    set portdbpath $pwd/dbpath
+    set altprefix /tmp/altprefix
+    set dist_subdir subdir
+    set name subdir_name
+    set distpath $pwd/distpath
+    lappend distfiles $distpath/dist_file
+    lappend distfiles $distpath/dist_file2
+    set patchpath $pwd/patchpath
+    lappend patchfiles $patchpath/patch_file
+    lappend patchfiles $patchpath/patch_file2
+
+    # create files
+    file mkdir $distpath
+    close [open $distpath/dist_file w+]
+    close [open $distpath/dist_file2 w+]
+    file mkdir $altprefix$distpath
+    close [open $altprefix$distpath/dist_file2 w+]
+    file mkdir $portdbpath/distfiles/$dist_subdir
+    close [open $portdbpath/distfiles/$dist_subdir/subdir_file w+]
+    close [open $portdbpath/distfiles/$dist_subdir/subdir_$name w+]
+
+    # create patch files
+    file mkdir $patchpath
+    close [open $patchpath/patch_file2 w+]
+    file mkdir $altprefix$patchpath
+    close [open $altprefix$patchpath/patch_file2 w+]
+
+    portclean::clean_dist
+
+    if {[file exists $distpath/dist_file]} {
+       return "FAIL: distfile not removed"
+    }
+    if {[file exists $distpath/dist_file2]} {
+       return "FAIL: distfile not removed"
+    }
+    if {[file exists $altprefix$distpath/dist_file2]} {
+       return "FAIL: alt distfile not removed"
+    }
+    if {[file exists $patchpath/patch_file2]} {
+       return "FAIL: patchfile not removed"
+    }
+    if {[file exists $altprefix$patchpath/patch_file2]} {
+       return "FAIL: alt patchfile not removed"
+    }
+    if {[file exists $portdbpath/distfiles/$dist_subdir]} {
+       return "FAIL: distfiles dir not removed"
+    }
+
+    return "Clean distfiles successful."
+
+} -cleanup {
+    file delete -force $distpath
+    file delete -force $portdbpath
+    file delete -force $patchpath
+    file delete -force $altprefix
+
+} -result "Clean distfiles successful."
+
+
+test clean_work {
+    Clean work unit test.
+} -constraints {
+    root
+} -body {
+    set usealtworkpath no
+    set altprefix $pwd/prefix
+    set portpath portpath
+    set subbuildpath /subbuild
+    set worksymlink $pwd/symlink
+
+    # create files
+    file mkdir $subbuildpath
+    close [open $subbuildpath/test.work w+]
+    file mkdir $altprefix/subbuild
+    close [open $altprefix/subbuild/test.work w+]
+    close [open $altprefix/$portpath w+]
+    file link -symbolic $worksymlink $subbuildpath
+
+    portclean::clean_work
+
+    if {[file exists $subbuildpath]} {
+       return "FAIL: buildpath not removed"
+    }
+    if {[file exists $altprefix/subbuild]} {
+       return "FAIL: subbuild not removed"
+    }
+    if {[file exists $worksymlink]} {
+       return "FAIL: symlink not removed"
+    }
+    if {[file exists $altprefix$portpath]} {
+       return "FAIL: port dir in alt prefix not removed"
+    }
+
+    return "Clean work successful."
+
+} -cleanup {
+    file delete -force $subbuildpath
+    file delete -force $altprefix
+    file delete -force $worksymlink
+
+} -result "Clean work successful."
+
+
+test clean_logs {
+    Clean logs unit test.
+} -constraints {
+    root
+} -body {
+    set portpath $pwd/portpath
+    set logpath [getportlogpath $portpath]
+    set subport $logpath/subport
+
+    # create files
+    file mkdir $subport
+    close [open $subport/test.log w+]
+
+    portclean::clean_logs
+
+    if {[file exists $subport]} {
+       return "FAIL: log dir not removed"
+    }
+    return "Clean logs successful."
+
+} -cleanup {
+    file delete -force $portpath
+    file delete -force $subport
+
+} -result "Clean logs successful."
+
+
+test clean_archive {
+    Clean archive unit test.
+} -body {
+    set subport subport
+    set portdbpath $pwd/dbpath
+
+    file mkdir $portdbpath/incoming
+    close [open $portdbpath/incoming/test.clean w+]
+    close [open $portdbpath/incoming/subport-1_0.0.0.0.TMP w+]
+
+    # create zip
+    set fd [open $pwd/+CONTENTS w+]
+    puts $fd "@portname subport"
+    close $fd
+    exec zip $portdbpath/incoming/subport-2_0.0.0.0.zip +CONTENTS
+
+    portclean::clean_archive
+
+    if {[file exists $portdbpath/incoming/subport-1_0.0.0.0.TMP]} {
+       return "FAIL: .TMP file not removed"
+    }
+    if {![file exists $portdbpath/incoming/test.clean]} {
+       return "FAIL: removed unrelated file"
+    }
+    if {[file exists $portdbpath/incoming/subport-2_0.0.0.0.zip]} {
+       return "FAIL: zip archive not removed"
+    }
+
+    return "Clean archive successful."
+
+} -cleanup {
+    file delete -force $pwd/+CONTENTS
+    file delete -force $portdbpath
+
+} -result "Clean archive successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portdeactivate.test (from rev 117083, trunk/base/src/port1.0/tests/portdeactivate.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portdeactivate.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portdeactivate.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,104 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portdeactivate 1.0
+package require registry 1.0
+source ./library.tcl
+macports_worker_init
+
+
+test activate_start {
+    Deactivate start unit test.
+    Requires root for setting euid.
+} -constraints {
+    root
+} -setup {
+    # file writable $prefix is used to determine whether privilege escalation
+    # is needed, so set prefix to a directory unwritable for this user
+    set prefix /usr/bin
+
+    # elevateToRoot uses $euid and $egid as the IDs to set
+    set euid 0
+    set egid 0
+
+} -body {
+    # drop privileges; the code won't attempt to elevate privileges without
+    # that
+    seteuid 333
+    if {[catch {portdeactivate::deactivate_start args}] != 0} {
+        return "FAIL: couldn't elevate privileges"
+    }
+
+    # when uid == 0 and euid == 0, the code will not attempt to elevate
+    # privileges
+    seteuid 0
+    if {[catch {portdeactivate::deactivate_start args}] != 0} {
+        return "FAIL: couldn't elevate privileges"
+    }
+    return "Deactivate_start successful."
+} -result "Deactivate_start successful."
+
+
+test deactivate_main {
+    Deactivate main unit test.
+} -constraints {
+    root
+} -setup {
+    set destpath $pwd/work/destroot
+    set portbuildpath $pwd
+    set portdbpath $pwd/dbpath
+    set portpath $pwd
+
+    set mport [mportopen file://.]
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+
+    # hide all output. Deactivate this for debugging!
+    set oldchannels [array get macports::channels]
+    set macports::channels(msg)    {}
+    set macports::channels(notice) {}
+
+    if {[$workername eval eval_targets install] != 0} {
+        return "FAIL: port install failed"
+    }
+
+} -body {
+    if {[$workername eval eval_targets activate] != 0} {
+        return "FAIL: cannot activate port after install"
+    }
+    if {[$workername eval eval_targets deactivate] != 0} {
+        return "FAIL: cannot deactivate port after activate"
+    }
+    return "Port deactivate successful."
+
+} -cleanup {
+    if {[$workername eval eval_targets uninstall] != 0} {
+        return "FAIL: uninstall failed"
+    }
+    if {[$workername eval eval_targets clean] != 0} {
+        return "FAIL: clean failed"
+    }
+    array set macports::channels $oldchannels
+
+    mportclose $mport
+} -result "Port deactivate successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portdepends.test (from rev 117083, trunk/base/src/port1.0/tests/portdepends.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portdepends.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portdepends.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,39 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portdepends 1.0
+
+
+test validate_depends_options {
+    Validate depends unit test.
+} -body {
+    set res [catch {portdepends::validate_depends_options target set {lib:test.val:value}}]
+    if {$res != 0} {return "FAIL: value lib:test.val:value not accepted"}
+    set res [catch {portdepends::validate_depends_options target set {bin:test.val:value}}]
+    if {$res != 0} {return "FAIL: value bin:test.val:value not accepted"}
+    set res [catch {portdepends::validate_depends_options target set {path:test:value}}]
+    if {$res != 0} {return "FAIL: value path:test:value not accepted"}
+    set res [catch {portdepends::validate_depends_options target set {port:test3}}]
+    if {$res != 0} {return "FAIL: value port:test3 not accepted"}
+    set res [catch {portdepends::validate_depends_options target set {lib:test}}]
+    if {$res != 1} {return "FAIL: invalid options lib:test accepted"}
+    return "Validate depends successful."
+} -result "Validate depends successful."
+
+# test validate_depends_options_new
+
+
+cleanupTests

Deleted: branches/new-help-system/base/src/port1.0/tests/portdestroot.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portdestroot.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/tests/portdestroot.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,40 +0,0 @@
-source [file join [lindex $argv 0] macports1.0 macports_fastload.tcl]
-package require macports
-mportinit
-
-source [file dirname [info script]]/../portdestroot.tcl
-source [file dirname [info script]]/common.tcl
-
-namespace eval tests {
-
-proc "when destroot cmd is not gmake no -w argument is added" {} {
-    global build.type build.cmd destroot.cmd destroot.target
-
-    set build.type "gnu"
-    set build.cmd "gmake"
-    set destroot.cmd "_destroot_cmd_"
-    set destroot.target "_target_"
-
-    test_equal {[portdestroot::destroot_getargs]} "_target_"
-}
-
-proc "when destroot cmd is gmake a -w argument is added" {} {
-    global build.type build.cmd destroot.cmd destroot.target
-
-    set build.type "gnu"
-    set build.cmd "_build_cmd_"
-    set destroot.cmd "gmake"
-    set destroot.target "_target_"
-
-    test_equal {[portdestroot::destroot_getargs]} "-w _target_"
-}
-
-
-# run all tests
-foreach proc [info procs *] {
-    puts "* ${proc}"
-    $proc
-}
-
-# namespace eval tests
-}

Copied: branches/new-help-system/base/src/port1.0/tests/portdistcheck.test (from rev 117083, trunk/base/src/port1.0/tests/portdistcheck.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portdistcheck.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portdistcheck.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,50 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portdistcheck 1.0
+source ./library.tcl
+macports_worker_init
+
+
+test distcheck_main {
+    Distcheck main unit test.
+} -setup {
+    set portpath $pwd
+    set filespath $pwd/files
+
+    set name cocot
+    set subport $name
+    set distname cocot-20080315
+    set porturl "http://distfiles.macports.org/cocot/"
+    set master_sites $porturl
+    set extract.suffix .tar.bz2
+
+} -body {
+    set fetch.type standard
+    set distcheck.type moddate
+    if {[portdistcheck::distcheck_main] != ""} {
+        return "FAIL: unable to download or check file, type moddate"
+    }
+    set distcheck.type filesize
+    if {[portdistcheck::distcheck_main] != ""} {
+        return "FAIL: unable to download or check file, type filesize"
+    }
+
+    return "Distcheck main successful."
+} -result "Distcheck main successful."
+
+
+cleanupTests

Deleted: branches/new-help-system/base/src/port1.0/tests/portfetch.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portfetch.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/tests/portfetch.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,58 +0,0 @@
-source [file join [lindex $argv 0] macports1.0 macports_fastload.tcl]
-package require macports
-mportinit
-
-set scriptdir [file dirname [info script]]
-source ${scriptdir}/../portfetch.tcl
-source ${scriptdir}/common.tcl
-
-namespace eval tests {
-
-proc "mirror tags are parsed correctly" {} {
-    global distfiles master_sites name dist_subdir filespath scriptdir
-
-    set name test
-    set filespath $scriptdir
-    set dist_subdir tset
-    set portfetch::mirror_sites::sites(macports_test) {
-        http://distfiles.macports.org/:mirror
-        http://distfiles2.macports.org:80/:mirror
-        http://distfiles3.macports.org:80/
-        http://distfiles4.macports.org:80/some/subdir/
-        http://distfiles5.macports.org:80/some/subdir/:mirror
-    }
-    set distfiles test.tar.bz2
-    set master_sites macports_test
-    set fetch_urls {}
-    portfetch::checksites [list master_sites {}] ""
-    portfetch::checkdistfiles fetch_urls
-
-    global portfetch::urlmap
-    foreach {url_var distfile} $fetch_urls {
-        if {![info exists urlmap($url_var)]} {
-            set urlmap($url_var) $urlmap(master_sites)
-        }
-        foreach site $urlmap($url_var) {
-            set file_url [portfetch::assemble_url $site $distfile]
-            lappend all_file_urls $file_url
-        }
-    }
-    set all_file_urls [lsort $all_file_urls]
-
-    set expected [list http://distfiles.macports.org/tset/test.tar.bz2 \
-                       http://distfiles2.macports.org:80/tset/test.tar.bz2 \
-                       http://distfiles3.macports.org:80/test/test.tar.bz2 \
-                       http://distfiles4.macports.org:80/some/subdir/test/test.tar.bz2 \
-                       http://distfiles5.macports.org:80/some/subdir/tset/test.tar.bz2]
-
-    test_equal {$all_file_urls} {$expected}
-}
-
-# run all tests
-foreach proc [info procs *] {
-    puts "* ${proc}"
-    $proc
-}
-
-# namespace eval tests
-}

Copied: branches/new-help-system/base/src/port1.0/tests/portinstall.test (from rev 117083, trunk/base/src/port1.0/tests/portinstall.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portinstall.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portinstall.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,183 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portinstall 1.0
+source ../../registry2.0/portuninstall.tcl
+source ../port_autoconf.tcl
+source ./library.tcl
+macports_worker_init
+
+
+# Set env vars
+set os.platform darwin
+set macosx_version 10.8
+set os_version 12
+set os_arch i386
+set os.major 10
+set supported_archs {}
+set configure.build_arch build_arch
+set portarchivetype tgz
+
+set subport fondu
+set version 3.0
+set revision 2
+
+
+test install_start {
+    Install start unit test.
+} -constraints {
+    root
+} -setup {
+    set portvariants {var1}
+    set prefix prefix
+    set add_users no
+
+} -body {
+    if {[catch {portinstall::install_start}] != 0} {
+        return "FAIL: problem with install start"
+    }
+    return "Install start successful."
+} -result "Install start successful."
+
+
+test create_archive {
+    Create archive unit test.
+} -constraints {
+    root
+} -setup {
+    set destpath $pwd/work/destroot
+    set portbuildpath $pwd
+    set portdbpath $pwd/dbpath
+    set portpath $pwd
+    set create /dev/null
+
+    # destroot setup
+    file mkdir $pwd/$subport
+    set mport [mportopen file://.]
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # run destroot
+    if {[$workername eval eval_targets destroot] != 0} {
+        return "FAIL: destroot failed"
+    }
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+
+    # hide all output. Deactivate this for debugging!
+    set oldchannels [array get macports::channels]
+    set macports::channels(msg)    {}
+    set macports::channels(notice) {}
+
+    if {[$workername eval eval_targets install] != 0} {
+        return "FAIL: port install failed"
+    }
+
+} -body {
+    if {[catch {$workername eval portinstall::create_archive $create tgz}] != 0} {
+        return "FAIL: cannot create archive"
+    }
+    return "Create archive successful."
+
+} -cleanup {
+    if {[$workername eval eval_targets uninstall] != 0} {
+        return "FAIL: uninstall failed"
+    }
+    if {[$workername eval eval_targets clean] != 0} {
+        return "FAIL: clean failed"
+    }
+    array set macports::channels $oldchannels
+    mportclose $mport
+
+    file delete -force $pwd/$subport
+    file delete -force $portdbpath
+    file delete -force $pwd/work
+
+} -result "Create archive successful."
+
+
+# test extract_contents
+
+
+test install_main {
+    Install main unit test.
+} -constraints {
+    root
+
+} -setup {
+    set workpath $pwd/work
+    set portpath $pwd
+    set portdbpath $pwd/dbpath
+    set portbuildpath $pwd
+    set destpath $pwd/work/destroot
+    set portvariants {+var1}
+    
+    set epoch i386
+    set compiler.cpath /usr/bin/gcc
+    set compiler.library_path /usr/lib
+
+    # destroot setup
+    file mkdir $pwd/$subport
+    set mport [mportopen file://.]
+
+    if {[eval_variants variations] != 0} {
+        mportclose $mport
+        error "Error evaluating variants"
+    }
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # run destroot
+    if {[$workername eval eval_targets destroot] != 0} {
+        return "FAIL: destroot failed"
+    }
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+
+    # hide all output. Deactivate this for debugging!
+    set oldchannels [array get macports::channels]
+    set macports::channels(msg)    {}
+    set macports::channels(notice) {}
+
+} -body {
+    if {[$workername eval eval_targets install] != 0} {
+        return "FAIL: cannot install port"
+    }
+    return "Install main successful."
+
+} -cleanup {
+    if {[$workername eval eval_targets uninstall] != 0} {
+        return "FAIL: uninstall failed"
+    }
+    if {[$workername eval eval_targets clean] != 0} {
+        return "FAIL: clean failed"
+    }
+    array set macports::channels $oldchannels
+
+    mportclose $mport
+
+    file delete -force $pwd/$subport
+    file delete -force $portdbpath
+    file delete -force $pwd/work
+
+} -result "Install main successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portload.test (from rev 117083, trunk/base/src/port1.0/tests/portload.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portload.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portload.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,61 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portload 1.0
+source ../port_autoconf.tcl
+
+
+test load_main {
+    Load main unit test.
+} -constraints {
+    root
+
+} -setup {
+    set path /Library/test/files
+    file mkdir $path
+
+    # Create dummy plist
+    set fd [open $path/file.plist w+]
+    puts $fd "\<?xml version=\"1.0\" encoding=\"UTF-8\"?\>"
+    puts $fd "\<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"\>"
+    puts $fd "\<plist version=\"1.0\"\>"
+    puts $fd "\<dict\>"
+    puts $fd "\<key\>Label\</key\>"
+    puts $fd "\<string\>org.test.load\</string\>"
+    puts $fd "\<key\>ProgramArguments\</key\>"
+    puts $fd "\<array\>\<string\>/bin/ls\</string\>\</array\>"
+    puts $fd "\</dict\>"
+    puts $fd "\</plist\>"
+    close $fd
+
+} -body {
+    set launchctl_path ${portutil::autoconf::launchctl_path}
+    set startupitem.location test
+    set startupitem.plist files/file.plist
+
+    if {[portload::load_main] != ""} {
+        return "FAIL: unable to load plist"
+    }
+    return "Load successful."
+
+} -cleanup {
+    exec $launchctl_path unload -w $path 2>@stderr
+    file delete -force /Library/test
+
+} -result "Load successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portmain.test (from rev 117083, trunk/base/src/port1.0/tests/portmain.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portmain.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portmain.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,53 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+source ./library.tcl
+macports_worker_init
+package require portmain 1.0
+
+
+# Set testing vars
+set os_platform darwin
+set macosx_version 10.8
+set os_version 12
+set os_arch i386
+set portpath .
+set portbuildpath ./build
+
+
+test get_default_subport {
+    Get default subport unit test.
+} -body {
+    set portpath path/port/subport
+    if {[portmain::get_default_subport] != "subport"} {
+        return "FAIL: wrong subport"
+    }
+    return "Get default subport successful."
+} -result "Get default subport successful."
+
+
+test get_subbuildpath {
+    Get subbuildpath unit test.
+} -body {
+    set portpath path/port/subport
+    if {[portmain::get_subbuildpath] != [file normalize "./build/subport"]} {
+        return "FAIL: wrong subbuildpath"
+    }
+    return "Get subbuild path successful."
+} -result "Get subbuild path successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portpatch.test (from rev 117083, trunk/base/src/port1.0/tests/portpatch.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portpatch.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portpatch.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,78 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portpatch
+source ../port_autoconf.tcl
+source ./library.tcl
+macports_worker_init
+
+
+test build_getpatchtype {
+    Get patch type unit test.
+} -body {
+    set res [portpatch::build_getpatchtype]
+    if {$res != $portutil::autoconf::patch_path} {
+        return "FAIL: wrong path"
+    }
+    return "Get patch type successful."
+} -result "Get patch type successful."
+
+
+test patch_main {
+    Patch main unit test.
+} -constraints {
+    root
+} -setup {
+    set macosx_version 12
+
+    set subport fondu
+    set filespath $pwd/files
+    set distpath $pwd/dist
+    set usealtworkpath yes
+    set altprefix prefix
+
+    set workpath $pwd/work
+    set worksrcpath $workpath/src
+    set compiler.cpath /usr/bin/gcc
+    set compiler.library_path /usr/lib
+    set macosx_deployment_target $pwd/deploy_target
+
+    file mkdir $filespath
+    set fd [open $filespath/file.diff w+]
+    puts $fd "first line should get to the workpath"
+    close $fd
+
+    set mport [mportopen file://.]
+    set workername [ditem_key $mport workername]
+    $workername eval "set patchfiles {file.diff}"
+
+} -body {
+    if {[$workername eval eval_targets patch]} {
+        return "FAIL: cannot run patch"
+    }
+    if {![file exists $pwd/work/fondu-060102/test_patch]} {
+        return "FAIL: missing patched file"
+    }
+    return "Patch successful."
+
+} -cleanup {
+    file delete -force $filespath
+    file delete -force $pwd/work
+
+} -result "Patch successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/porttest.test (from rev 117083, trunk/base/src/port1.0/tests/porttest.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/porttest.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/porttest.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,71 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+source ./library.tcl
+macports_worker_init
+package require port 1.0
+package require registry 1.0
+
+
+# test test_start
+
+test test_main {
+    Test main unit test.
+} -constraints {
+    root
+} -setup {
+    set destpath $pwd/work/destroot
+    set portbuildpath $pwd
+    set portdbpath $pwd/dbpath
+    set portpath $pwd
+
+    set mport [mportopen file://.]
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+
+    # hide all output. Deactivate this for debugging!
+    set oldchannels [array get macports::channels]
+    set macports::channels(msg)    {}
+    set macports::channels(notice) {}
+
+    if {[$workername eval eval_targets install] != 0} {
+        return "FAIL: port install failed"
+    }
+
+} -body {
+    if {[$workername eval eval_targets test] != 0} {
+        return "FAIL: test target failed"
+    }
+
+    return "Test main successful."
+
+} -cleanup {
+    if {[$workername eval eval_targets uninstall] != 0} {
+        return "FAIL: uninstall failed"
+    }
+    if {[$workername eval eval_targets clean] != 0} {
+        return "FAIL: clean failed"
+    }
+    file delete -force $pwd/work
+
+} -result "Test main successful."
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/portuninstall.test (from rev 117083, trunk/base/src/port1.0/tests/portuninstall.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portuninstall.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portuninstall.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,95 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+package require portinstall 1.0
+source ../../registry2.0/portuninstall.tcl
+source ../port_autoconf.tcl
+source ./library.tcl
+macports_worker_init
+
+set subport fondu
+set version 3.0
+set revision 2
+
+
+# test uninstall_start
+
+
+test uninstall_main {
+    Uninstall main unit test.
+} -constraints {
+    root
+
+} -setup {
+    set workpath $pwd/work
+    set portpath $pwd
+    set portdbpath $pwd/dbpath
+    set portbuildpath $pwd
+    set destpath $pwd/work/destroot
+    set portvariants {+var1}
+
+    set epoch i386
+    set compiler.cpath /usr/bin/gcc
+    set compiler.library_path /usr/lib
+
+    # destroot setup
+    file mkdir $pwd/$subport
+    set mport [mportopen file://.]
+
+    if {[eval_variants variations] != 0} {
+        mportclose $mport
+        error "Error evaluating variants"
+    }
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # run destroot
+    if {[$workername eval eval_targets destroot] != 0} {
+        return "FAIL: destroot failed"
+    }
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+
+    # hide all output. Deactivate this for debugging!
+    set oldchannels [array get macports::channels]
+    set macports::channels(msg)    {}
+    set macports::channels(notice) {}
+    
+    if {[$workername eval eval_targets install] != 0} {
+        return "FAIL: cannot install port"
+    }
+
+} -body {
+    if {[$workername eval eval_targets uninstall] != 0} {
+        return "FAIL: uninstall failed"
+    }
+    return "Uninstall main successful."
+
+} -cleanup {
+    if {[$workername eval eval_targets clean] != 0} {
+        return "FAIL: clean failed"
+    }
+    
+    file delete -force $pwd/$subport
+    file delete -force $portdbpath
+    file delete -force $pwd/work
+
+} -result "Uninstall main successful."
+
+
+cleanupTests

Deleted: branches/new-help-system/base/src/port1.0/tests/portutil.tcl
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portutil.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/port1.0/tests/portutil.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,217 +0,0 @@
-# Test file for Pextlib's fs-traverse
-# Requires r/w access to /tmp
-# MacPorts must be installed for this to work
-
-source [file join [lindex $argv 0] macports1.0 macports_fastload.tcl]
-package require macports
-mportinit
-
-# load the current copy of portutil instead of the installed one
-source [file dirname [info script]]/../portutil.tcl
-
-# end boilerplate
-
-namespace eval tests {
-
-proc test_delete {} {
-    set root "/tmp/macports-portutil-delete"
-    # use file delete -force to kill the test directory if it already exists
-    # yeah I realize this will fail on 10.3 if it already exists. oh well.
-    file delete -force $root
-    
-    try {
-        mtree $root {
-            a               directory
-            a/a             file
-            a/b             file
-            a/c             directory
-            a/c/a           file
-            a/c/b           {link ../b}
-            a/c/c           {link ../../b}
-            a/c/d           directory
-            a/c/d/a         file
-            a/c/d/b         directory
-            a/c/d/c         file
-            a/d             file
-            b               directory
-            b/a             file
-            b/b             {link q}
-            b/c             directory
-            b/c/a           file
-            b/c/b           file
-            b/d             file
-        }
-        
-        # test deleting a symlink
-        delete $root/a/c/b
-        
-        if {[file exists $root/a/c/b] || ![file exists $root/a/b]} {
-            error "delete (symlink) failed"
-        }
-        
-        # test multiple args
-        delete $root/a $root/b
-        
-        if {[file exists $root/a] || [file exists $root/b]} {
-            error "delete (multiple args) failed"
-        }
-    } finally {
-        file delete -force $root
-    }
-}
-
-proc test_depends_lib-delete {} {
-    # tests depends_lib-delete
-    # actually tests all option-deletes
-    # but the bug was originally documented with depends_lib
-    
-    # depends_lib is intended to work from within a worker thread
-    # so we shall oblige
-    set workername [interp create]
-    macports::worker_init $workername {} {} [macports::getportbuildpath {}] {} {}
-    $workername alias scriptname info script
-    set body {
-        # load the current copy of portutil instead of the installed one
-        source [file dirname [scriptname]]/../portutil.tcl
-        package require port
-        
-        depends_lib port:foo port:bar port:blah
-        depends_lib-delete port:blah port:bar
-        array get PortInfo
-    }
-    if {[catch {$workername eval $body} result]} {
-        interp delete $workername
-        error $result $::errorInfo $::errorCode
-    } else {
-        interp delete $workername
-    }
-    array set temp $result
-    if {$temp(depends_lib) ne "port:foo"} {
-        error "depends_lib-delete did not delete properly"
-    }
-}
-
-proc test_touch {} {
-    set root "/tmp/macports-portutil-touch"
-    file delete -force $root
-    
-    try {
-        touch -c $root
-        if {[file exists $root]} { error "touch failed" }
-    
-        touch $root
-        if {![file exists $root]} { error "touch failed" }
-    
-        touch -a -t 199912010001.01 $root
-        if {[file atime $root] != [clock scan 19991201T000101]} { error "touch failed" }
-        if {[file mtime $root] == [clock scan 19991201T000101]} { error "touch failed" }
-    
-        touch -m -t 200012010001.01 $root
-        if {[file atime $root] == [clock scan 20001201T000101]} { error "touch failed" }
-        if {[file mtime $root] != [clock scan 20001201T000101]} { error "touch failed" }
-    
-        touch -a -m -t 200112010001.01 $root
-        if {[file atime $root] != [clock scan 20011201T000101]} { error "touch failed" }
-        if {[file mtime $root] != [clock scan 20011201T000101]} { error "touch failed" }
-    
-        touch -r ~ $root
-        if {[file atime $root] != [file atime ~]} { error "touch failed" }
-        if {[file mtime $root] != [file mtime ~]} { error "touch failed" }
-    } finally {
-        file delete -force $root
-    }
-}
-
-proc test_ln {} {
-    set root "/tmp/macports-portutil-ln"
-    file delete -force $root
-    
-    file mkdir $root
-    try {
-        close [open $root/a w]
-        ln -s a $root/b
-        if {[catch {file type $root/b}] || [file type $root/b] ne "link"} {
-            set message "ln failed: "
-            if {[catch {file type $root/b}]} {
-                append message "symlink not created"
-            } elseif {[file type $root/b] ne "link"} {
-                append message "created [file type $root/b], expected link"
-            }
-            error $message
-        }
-    
-        close [open $root/c w]
-        if {![catch {ln -s c $root/b}]} { error "ln failed" }
-    
-        ln -s -f c $root/b
-        if {[catch {file type $root/b}] || [file type $root/b] ne "link"} { error "ln failed" }
-    
-        file delete $root/b
-    
-        ln $root/a $root/b
-        if {[catch {file type $root/b}] || [file type $root/b] ne "file"} { error "ln failed" }
-    
-        file delete $root/b
-        file mkdir $root/dir
-        ln -s dir $root/b
-        ln -s a $root/b
-        if {[catch {file type $root/dir/a}] || [file type $root/dir/a] ne "link"} { error "ln failed" }
-        file delete $root/dir/a
-    
-        ln -s -f -h a $root/b
-        if {[catch {file type $root/b}] || [file type $root/b] ne "link" || [file readlink $root/b] ne "a"} { error "ln failed" }
-    
-        cd $root/dir
-        ln -s ../c
-        if {[catch {file type $root/dir/c}] || [file type $root/dir/c] ne "link"} { error "ln failed" }
-    
-        ln -s foobar $root/d
-        if {[catch {file type $root/d}] || [file type $root/d] ne "link" || [file readlink $root/d] ne "foobar"} { error "ln failed" }
-        
-        ln -s -f -h z $root/dir
-        if {[catch {file type $root/dir/z}] || [file type $root/dir/z] ne "link"} { error "ln failed" }
-        
-        # test combined flags
-        ln -sf q $root/dir
-        if {[catch {file type $root/dir/q}] || [file type $root/dir/q] ne "link"} { error "ln failed" }
-    } finally {
-        file delete -force $root
-    }
-}
-
-# Create a filesystem hierarchy based on the given specification
-# The mtree spec consists of name/type pairings, where type can be
-# one of directory, file or link. If type is link, it must be a
-# two-element list containing the path as the second element
-proc mtree {root spec} {
-    foreach {entry typelist} $spec {
-        set type [lindex $typelist 0]
-        set link [lindex $typelist 1]
-        set file [file join $root $entry]
-        switch $type {
-            directory {
-                file mkdir $file
-            }
-            file {
-                # touch
-                close [open $file w]
-            }
-            link {
-                # file link doesn't let you link to files that don't exist
-                # so lets farm out to /bin/ln
-                exec /bin/ln -s $link $file
-            }
-            default {
-                return -code error "Unknown file map type: $typelist"
-            }
-        }
-    }
-}
-
-# run all tests
-foreach proc [info procs test_*] {
-    $proc
-}
-
-# namespace eval tests
-}

Copied: branches/new-help-system/base/src/port1.0/tests/portutil.test (from rev 117083, trunk/base/src/port1.0/tests/portutil.test)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/portutil.test	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/portutil.test	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,856 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+
+package require tcltest 2
+namespace import tcltest::*
+
+source ../../macports1.0/macports_fastload.tcl
+
+set pwd [file dirname [file normalize $argv0]]
+
+source ../port_test_autoconf.tcl
+source $macports::autoconf::macports_tcl_dir/macports1.0/macports_fastload.tcl
+package require macports 1.0
+
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
+
+source ./library.tcl
+macports_worker_init
+
+package require registry 1.0
+package require registry2 2.0
+package require Pextlib 1.0
+package require macports_dlist 1.0
+package require macports_util 1.0
+package require msgcat
+package require porttrace 1.0
+
+proc init {} {
+    global macports::registry.path
+
+    set db_path [file join ${registry.path} registry registry.db]
+    set db_exists [file exists $db_path]
+    #registry::active
+}
+
+proc init_eval_targets {} {
+    global os_platform os_version os_arch macosx_version pwd
+    global version mport portpath portbuildpath
+
+    set os_platform darwin
+    set macosx_version 10.8
+    set os_version 11
+    set os_arch i386
+    set portpath .
+    set portbuildpath ./build
+
+    # vars for target_run
+    global portdbpath usealtworkpath
+    set usealtworkpath no
+    set portdbpath $pwd/
+    set workpath $pwd/work
+    set altprefix ""
+
+
+    set mport [mportopen file://.]
+
+    proc getportbuildpath {id {portname ""}} {
+        global portdbpath
+        regsub {://} $id {.} port_path
+        regsub -all {/} $port_path {_} port_path
+        return [file join $portdbpath build $port_path $portname]
+    }
+
+    proc getportworkpath_from_buildpath {portbuildpath} {
+        return [file join $portbuildpath work]
+    }
+
+    proc getportworkpath_from_portdir {portpath {portname ""}} {
+        return [getportworkpath_from_buildpath [getportbuildpath $portpath $portname]]
+    }
+
+    source $pwd/../portutil.tcl
+    source $pwd/../portmain.tcl
+
+    #variant provides code requires aaa
+}
+
+
+# Create a filesystem hierarchy based on the given specification
+# The mtree spec consists of name/type pairings, where type can be
+# one of directory, file or link. If type is link, it must be a
+# two-element list containing the path as the second element
+proc mtree {root spec} {
+    foreach {entry typelist} $spec {
+        set type [lindex $typelist 0]
+        set link [lindex $typelist 1]
+        set file [file join $root $entry]
+        switch $type {
+            directory {
+                file mkdir $file
+            }
+            file {
+                # touch
+                close [open $file w]
+            }
+            link {
+                # file link doesn't let you link to files that don't exist
+                # so lets farm out to /bin/ln
+                exec /bin/ln -sf $link $file
+            }
+            default {
+                return -code return "Unknown file map type: $typelist"
+            }
+        }
+    }
+}
+
+
+test option {
+    Option unit test. Tcl 'set' functionality.
+} -body {
+    if {[option MP macports] != "macports"} {return "FAIL: var not set correctly"}
+    if {$MP != "macports"} {return "FAIL: var not set"}
+    return "Option successful."
+} -result "Option successful."
+
+
+test exists {
+    Exists unit test. Checks for existance of a Portfile option.
+} -body {
+    set vara a
+    if {[exists vara] != 1} {return "FAIL: option exists but not detected"}
+    if {[exists varb] != 0} {return "FAIL: option detected although missing"}
+    return "Exists successful."
+} -result "Exists successful."
+
+
+test handle_option {
+    Handle_option unit test.
+} -body {
+    if {[handle_option vara a] != "a"} {return "FAIL: unable to set var"}
+    return "Handle_option successful."
+} -result "Handle_option successful."
+
+
+test handle_option-append {
+    Handle_option append unit test.
+} -body {
+    set user_options {vara varb}
+    handle_option-append user_options varc
+    if {[lsearch $user_options varc] < 0} {return "FAIL: var not appended"}
+    if {[lsearch $user_options vard] >= 0} {return "FAIL: unappended var found"}
+    return "Handle_option-append successful."
+} -result "Handle_option-append successful."
+
+
+test handle_option-delete {
+    Handle_option delete unit test.
+} -body {
+    set user_options {vara varb}
+    handle_option-delete user_options varb
+    if {[lsearch $user_options varb] > 0} {return "FAIL: var not deleted"}
+    if {[lsearch $user_options vara] < 0} {return "FAIL: var not found"}
+    return "Handle_option-delete successful."
+} -result "Handle_option-delete successful."
+
+
+test handle_option-strsed {
+    Handle_option strsed unit test.
+} -body {
+    unset user_options
+    array set user_options { opt options }
+    if {[handle_option-strsed opt b] != ""} {return "FAIL: invalid result"}
+    return "Handle_option-strsed successful."
+} -result "Handle_option-strsed successful."
+
+
+# test handle_option-replace # deprecated
+
+
+test options {
+    Options unit test.
+} -body {
+    options date
+    if {[date macports] != "macports"} {return "FAIL: incorect options"}
+    return "Options successful."
+} -result "Options successful."
+
+
+# test options::export #
+# test options_export #
+# test handle_deprecated_option #
+# test get_deprecated_options #
+# test option_deprecate
+# test option_proc
+# test option_proc_trace #
+# test commands
+# test command_string #
+# test command_exec #
+# test default
+# test default_check #
+# test handle_option_string
+# test variant
+# test variant_isset
+# test variant_set
+# test variant_remove_ditem #
+# test variant_exists
+# test load_variant_desc_file
+# test variant_desc
+# test platform
+# test subport
+
+# test parse_environment #
+# test append_to_environment_value #
+# test append_list_to_environment_value #
+# test environment_array_to_string #
+
+
+test getdisttag {
+    Get dist tag unit test.
+} -body {
+    set tag [getdisttag distfile.tar.gz:tag1]
+    if {$tag != "tag1"} {return "FAIL: invalid tag detected"}
+    set tag [getdisttag distfile.tar.gz:tag1:tag2]
+    if {$tag != "tag2"} {return "FAIL: invalid last tag"}
+    set tag [getdisttag distfile.tar.gz]
+    if {$tag != ""} {return "FAIL: detected unexistent tag"}
+    return "Getdisttag successful."
+} -result "Getdisttag successful."
+
+
+test getdistname {
+    Get dist tag unit test.
+} -body {
+    set tag [getdistname distfile.tar.gz:tag1]
+    if {$tag != "distfile.tar.gz"} {return "FAIL: invalid name detected"}
+    set tag [getdistname distfile.gz::tag1]
+    if {$tag != "distfile.gz:"} {return "FAIL: invalid name"}
+    return "Getdistname successful."
+} -result "Getdistname successful."
+
+
+test tbool {
+    Tbool unit test. Check if variable is in calling namespace.
+} -setup {
+    set vara "yes"
+    set varb no
+} -body {
+    if {[tbool vara] == 0} { return "FAIL: var not true" }
+    if {[tbool varb] != 0} { return "FAIL: var not false" }
+    if {[tbool var] != 0} { return "FAIL: var should not be here" }
+    return "tbool successful."
+} -result "tbool successful."
+
+
+test ldelete {
+    Ldelete unit test. Remove one value from list.
+} -setup {
+    set list {a b a}
+    set empty {}
+} -body {
+    if {[ldelete $list b] != {a a}} { return "FAIL: element not deleted" }
+    if {[ldelete $list a] != {b a}} { return "FAIL: first element not removed" }
+    if {[ldelete $empty a] != {}} { return "FAIL: list was empty" }
+    return "ldelete successful."
+} -result "ldelete successful."
+
+
+test reinplace {
+    Reinplace  unit test. "Sed in place" functionality.
+} -setup {
+    global macportsuser
+    set macportsuser macports
+
+    set root "/tmp/macports-portutil-reinplace"
+    file delete -force $root
+
+    set workpath $root
+    set worksrcpath $root
+    set file $root/file
+    source ../port_autoconf.tcl
+
+    file mkdir $root
+    set fs [open $file w+]
+    puts $fs "Macports reinplace unit test?"
+    close $fs
+
+    set second $root/dir
+    file mkdir $second
+    file copy -force $root/file $second/file
+
+} -body {
+    reinplace s/Macports/MacPorts/1 $file
+    catch {set f [open $file r]}
+    set cont [read -nonewline $f]
+    if { $cont != "MacPorts reinplace unit test?" } {
+        return "FAIL: reinplace no args."
+    }
+    close $f
+
+    reinplace -E s/test?/testing/1 $file
+    catch {set f [open $file r]}
+    set cont [read -nonewline $f]
+    if { $cont != "MacPorts reinplace unit testing?" } {
+        return "FAIL: reinplace (-E) extended regex."
+    }
+    close $f
+
+    reinplace -W $second s/Macports/MP/1 file
+    catch {set f [open $second/file r]}
+    set cont [read -nonewline $f]
+    if { $cont != "MP reinplace unit test?" } {
+        return "FAIL: reinplace (-W) relative path."
+    }
+    close $f
+
+    reinplace -n s/unit/testing/1 $file
+    catch {set f [open $file r]}
+    set cont [read -nonewline $f]
+    if { $cont != "" } {
+        return "FAIL: reinplace (-n) suppress output."
+    }
+    close $f
+
+    return "Reinplace successful."
+
+} -cleanup {
+    file delete -force $root
+} -result "Reinplace successful."
+
+
+test delete {
+    Delete unit test.
+} -setup {
+    set root "/tmp/macports-portutil-delete"
+    file delete -force $root
+
+    try {
+        mtree $root {
+            a               directory
+            a/a             file
+            a/b             file
+            a/c             directory
+            a/c/a           file
+            a/c/b           {link ../b}
+            a/c/c           {link ../../b}
+            a/c/d           directory
+            a/c/d/a         file
+            a/c/d/b         directory
+            a/c/d/c         file
+            a/d             file
+            b               directory
+            b/a             file
+            b/b             {link q}
+            b/c             directory
+            b/c/a           file
+            b/c/b           file
+            b/d             file
+        }
+    }
+
+} -body {
+    delete $root/a/c/b
+    if {[file exists $root/a/c/b] || ![file exists $root/a/b]} {
+        return "FAIL: delete with single args."
+    }
+
+    delete $root/a $root/b
+    if {[file exists $root/a] || [file exists $root/b]} {
+        return "FAIL: delete with multiple args.""
+    }
+    return "Files deleted."
+
+} -cleanup {
+    file delete -force $root
+} -result "Files deleted."
+
+
+test touch {
+    Touch unit test.
+} -setup {
+    set root "/tmp/macports-portutil-touch"
+    file delete -force $root
+} -body {
+    touch -c $root
+    if {[file exists $root]} { return "FAIL: touch unsuccessful" }
+
+    touch $root
+    if {![file exists $root]} { return "FAIL: touch unsuccessful" }
+    return "Files successfully touched."
+
+} -cleanup {
+    file delete -force $root
+} -result "Files successfully touched."
+
+
+test ln {
+    ln unit test.
+} -setup {
+    set oldpwd [pwd]
+    set root "/tmp/macports-portutil-ln"
+    file delete -force $root
+    file mkdir $root
+} -body {
+    close [open $root/a w]
+    ln -s a $root/b
+    if {[catch {file type $root/b}]} { return "FAIL: symlink not created." }
+    if {[file type $root/b] ne "link"} { return "FAIL: expected link." }
+
+    close [open $root/c w]
+    if {![catch {ln -s c $root/b}]} { return "FAIL: ln not created." }
+
+    ln -s -f c $root/b
+    if {[catch {file type $root/b}] || [file type $root/b] ne "link"} {
+        return "FAIL: ln failed."
+    }
+    file delete $root/b
+
+    ln $root/a $root/b
+    if {[catch {file type $root/b}] || [file type $root/b] ne "file"} {
+         return "FAIL: ln failed."
+     }
+    file delete $root/b
+
+    file mkdir $root/dir
+    ln -s dir $root/b
+    ln -s a $root/b
+    if {[catch {file type $root/dir/a}] || [file type $root/dir/a] ne "link"} {
+        return "FAIL: directory ln failed."
+    }
+    file delete $root/dir/a
+
+    ln -s -f -h a $root/b
+    if {[catch {file type $root/b}] || [file type $root/b] ne "link" || [file readlink $root/b] ne "a"} {
+        return "FAIL: readlink error."
+    }
+
+    cd $root/dir
+    ln -s ../c
+    if {[catch {file type $root/dir/c}] || [file type $root/dir/c] ne "link"} {
+        return "FAIL: ln failed."
+    }
+
+    ln -s foobar $root/d
+    if {[catch {file type $root/d}] || [file type $root/d] ne "link" || [file readlink $root/d] ne "foobar"} {
+        return "FAIL: readlink error."
+    }
+
+    ln -s -f -h z $root/dir
+    if {[catch {file type $root/dir/z}] || [file type $root/dir/z] ne "link"} {
+        return "FAIL: ln failed."
+    }
+
+    ln -sf q $root/dir
+    if {[catch {file type $root/dir/q}] || [file type $root/dir/q] ne "link"} {
+        return "FAIL: error combined ln flags."
+    }
+    return "Files successfully linked."
+
+} -cleanup {
+    cd $oldpwd
+    file delete -force $root
+} -result "Files successfully linked."
+
+test makeuserproc {
+    Make user proc unit test.
+} -setup {
+    global MP
+    set MP macports
+} -body {
+    makeuserproc test-proc "\{ if \{ \$MP == \"macports\" \} \{return \"works\"\} \}"
+    set res [test-proc]
+    if { $res != "works" } { return "FAIL: global var not set in proc" }
+    return "Make user proc successful."
+
+} -result "Make user proc successful."
+
+
+# test backup -
+# test lipo -
+
+
+test unobscure_maintainers {
+    Unobscure maintainers unit test.
+} -body {
+    set list { port }
+    if { [unobscure_maintainers $list] != "port at macports.org" } {
+        return "FAIL: invalid maintainer name"
+    }
+    set list { google.com:port }
+    if { [unobscure_maintainers $list] != "port at google.com" } {
+        return "FAIL: invalid maintainer name"
+    }
+
+    set list { port at google.com }
+    if { [unobscure_maintainers $list] != "port at google.com" } {
+        return "FAIL: invalid maintainer name"
+    }
+    return "unobscure_maintainers successful."
+} -result "unobscure_maintainers successful."
+
+
+# test target_run
+# test recursive_collect_deps
+
+
+test eval_targets {
+    Evaluate targets unit test.
+} -setup {
+    init_eval_targets
+    set patchfiles {file.diff}
+
+    file mkdir $filespath
+    set fd [open $filespath/file.diff w+]
+    puts $fd "first line should get to the workpath"
+    close $fd
+
+    # sets up PortInfo array
+    if {[eval_variants variations] != 0} {
+        mportclose $mport
+        error "Error evaluating variants"
+    }
+
+    set epoch $PortInfo(epoch)
+    set revision $PortInfo(revision)
+
+    # messy work just to get $version
+    set workername [ditem_key $mport workername]
+
+} -body {
+    if {[$workername eval catch {eval_targets macport}] != 1} {
+        return "FAIL: invalid target detected"
+    }
+    if {[$workername eval eval_targets checksum] != 0} {
+        return "FAIL: valid target not detected"
+    }
+    return "Eval_targets successful."
+
+} -cleanup {
+    mportclose $mport
+    file delete -force $filespath
+    file delete -force work
+
+} -result "Eval_targets successful."
+
+
+test get_statefile_value {
+    Get statefile value unit test.
+    Depends on line in statefile "target: org.macports.fetch".
+} -body {
+    set fd [open $pwd/statefile r]
+
+    set res [catch {get_statefile_value target $fd result}]
+    if {$res != 0 || $result != "org.macports.fetch"} {
+        return "FAIL: invalid value"
+    }
+    return "Get statefile value successful."
+} -result "Get statefile value successful."
+
+
+test check_statefile {
+    Check statefile unit test.
+} -body {
+    set fd [open $pwd/statefile r]
+    set res [check_statefile target org.macports.patch $fd]
+    if {$res != 1} {return "FAIL: target not found"}
+
+    set res [check_statefile target org.macports.port $fd]
+    if {$res != 0} {return "FAIL: invalid target found"}
+    close $fd
+    return "Check_statefile successful."
+} -result "Check_statefile successful."
+
+
+test write_statefile {
+    Write statefile unit test.
+} -body {
+    set fd [open $pwd/test.statefile w+]
+    write_statefile variant universal $fd
+    set res [check_statefile variant universal $fd]
+    if {$res != 1} {return "FAIL: variant not set"}
+    close $fd
+    return "Write_statefile successful."
+
+} -cleanup {
+    file delete -force $pwd/test.statefile
+} -result "Write_statefile successful."
+
+
+test check_statefile_variants {
+    Check statefile unit test.
+} -setup {
+    array set variations {
+    target org.macports.fetch
+    target org.macports.checksum
+    }
+    array set oldvariations {
+    target org.macports.fetch
+    target org.macports.checksum
+    }
+    array set oldvariations_fail {
+    target org.macports.patch
+    }
+    set fd [open $pwd/statefile r]
+
+} -body {
+    set res [check_statefile_variants variations oldvariations $fd]
+    if {$res != 0} {return "FAIL: invalid variant"}
+    set res [check_statefile_variants variations oldvariations_fail $fd]
+    if {$res != 1} {return "FAIL: invalid variant"}
+    close $fd
+    return "Check statefile successful."
+
+} -result "Check statefile successful."
+
+
+test choose_variants {
+    Choose variants unit test.
+} -setup {
+    init_eval_targets
+    array set variations { fondu + }
+    array set variations_neg { fondu - }
+    array set variations_not { fondu a }
+
+} -body {
+    set res [choose_variants $mport variations]
+    if {[lindex $res 1] != "" && [lindex $res 0] != "ditem_1"} {
+        return "FAIL: invalid variations"
+    }
+    set res [choose_variants $mport variations_neg]
+    if {[lindex $res 0] != "" && [lindex $res 1] != "ditem_1"} {
+        return "FAIL: invalid variations"
+    }
+    set res [choose_variants $mport variations_not]
+    if {[lindex $res 0] != "" && [lindex $res 1] != ""} {
+        return "FAIL: invalid variations"
+    }
+    return "Choose variant successful."
+} -result "Choose variant successful."
+
+
+test variant_run {
+    Variant run unit test. Executes proc with same name as variant.
+} -setup {
+    proc variant-var {} { set var test }
+    set ditem [variant_new var]
+    set name [ditem_key $ditem name]
+
+} -body {
+    if {[catch {variant_run $ditem}] != 0} {
+        return "FAIL: unable to run variant name proc"
+    }
+    return "Variant run successful."
+} -cleanup {
+    mportclose $mport
+    file delete -force work
+} -result "Variant run successful."
+
+
+test canonicalize_variants {
+    Canonicalize_variants unit test.
+} -body {
+    set arr {c + b - d +}
+    if {[canonicalize_variants $arr +] != "+c+d"} {
+        return "FAIL: incorrect string"
+    }
+    if {[canonicalize_variants $arr -] != "-b"} {
+        return "FAIL: incorrect string"
+    }
+    return "Canonicalize variants successful."
+} -result "Canonicalize variants successful."
+
+
+# test eval_variants
+# test check_variants
+
+
+test universal_setup {
+    Universal setup unit test.
+} -body {
+    set use_configure 0
+    set ditem [variant_new new-variant]
+
+    if {[catch {universal_setup}] != 0} {
+        return "FAIL: universal variant not set"
+    }
+    return "Universal_setup successful."
+} -result "Universal_setup successful."
+
+
+# Covered by eval_targets.
+# test target_new #
+# test target_provides #
+# test target_requires #
+# test target_uses #
+# test target_deplist #
+# test target_prerun #
+# test target_postrun #
+# test target_runtype #
+# test target_state #
+# test target_init #
+
+
+test variant_new {
+    Variant new unit test.
+} -body {
+    set ditem [variant_new new-variant]
+    if {[ditem_key $ditem name] != "new-variant"} {
+        return "FAIL: error building new variant"
+    }
+    return "Variant new successful."
+} -result "Variant new successful."
+
+
+test handle_default_variants {
+    Handle default variants unit test.
+} -body {
+    array set variations {
+        target.run org.macports.checksum
+    }
+
+    set res [handle_default_variants target set {+org -org2}]
+
+    if {[lindex $PortInfo(vinfo) 0] != "org" || [lindex $PortInfo(vinfo) 1] != "is_default +"} {
+        return "FAIL: default variant not set"
+    }
+    if {[lindex $PortInfo(vinfo) 2] != "org2" || [lindex $PortInfo(vinfo) 3] != "is_default -"} {
+        return "FAIL: nondefault variant not set"
+    }
+
+    return "Handle default variant successful."
+} -result "Handle default variant successful."
+
+
+# test handle_add_users #
+# test adduser #
+# test addgroup #
+
+
+test dirSize {
+    Directory size unit test.
+    This test is dependent on the statefile in the tests dir.
+    Expected file size is 155.
+} -body {
+    global pwd
+    file mkdir $pwd/test.dir
+    file copy -force $pwd/statefile $pwd/test.dir
+    if {[dirSize $pwd/test.dir] != 155} {
+        return "FAIL: wrong dir size"
+    }
+    return "Directory size calculated successfully."
+
+} -cleanup {
+    file delete -force $pwd/test.dir
+} -result "Directory size calculated successfully."
+
+
+test set_ui_prefix {
+    Set_ui unit test. Assumes default: "---> ".
+} -body {
+    set env(UI_PREFIX) MacPorts
+    set_ui_prefix
+    if {$UI_PREFIX != "MacPorts"} {return "FAIL: incorrect prefix"}
+
+    unset env(UI_PREFIX)
+    set_ui_prefix
+    if {$UI_PREFIX != "---> "} {return "FAIL; default prefix not set"}
+    return "Set_ui_prefix successful."
+} -result "Set_ui_prefix successful."
+
+
+# test PortGroup
+
+
+test get_portimage_name {
+    Get portimage name unit test.
+} -body {
+    set os.platform darwin
+    set version 1.0
+    set os.major 10
+    set revision 2
+    set configure.build_arch no
+    set portarchivetype tgz
+    set subport testport
+    set portvariants {var1}
+    set supported_archs {}
+
+    set res [get_portimage_name]
+    if {$res != "testport-1.0_2var1.darwin_10.no.tgz"} {
+        return "FAIL: invalid portimage_name"
+    }
+    return "Get portimage_name successful."
+} -result "Get portimage_name successful."
+
+
+test get_portimage_path {
+    Get portimage path unit test. Calls get_portimage_name.
+} -body {
+    set os.platform darwin
+    set portdbpath dbpath
+    set subport subport
+    set revision 2
+    set portvariants {var1}
+    set supported_archs {}
+
+    set res [get_portimage_path]
+    if {$res != [file normalize "dbpath/software/subport/subport-1.0_2var1.darwin_10.no.tgz"]} {
+        return "FAIL: invalid portimage_path"
+    }
+    return "Get portimage_path successful."
+} -result "Get portimage_path successful."
+
+
+test supportedArchiveTypes {
+    Supported archive types unit test.
+    Only tests xar, zip, cpio.
+} -body {
+    set archives [supportedArchiveTypes]
+
+    foreach archive $archives {
+        if {$archive == "xar" && ![file exists ${portutil::autoconf::xar_path}]} {
+            return "FAIL: xar detected but inexistent"
+        }
+        if {$archive == "zip" && ![file exists ${portutil::autoconf::zip_path}]} {
+            return "FAIL: zip detected but inexistent"
+        }
+        if {$archive == "cpio" && ![file exists ${portutil::autoconf::cpio_path}]} {
+            return "FAIL: cpio detected but inexistent"
+        }
+    }
+    return "Supported archives successful."
+} -result "Supported archives successful."
+
+
+# test find_portarchie_path
+# test archiveTypeIsSupported
+# test extract_archive_metadata
+
+# test merge_lipo
+# test merge_cpp
+# test merge_file
+# test merge
+# test quotemeta
+# test chown
+# test chownAsRoot
+# test fileAttrsAsRoot
+# test elevateToRoot
+# test dropPrivileges
+# test validate_macportsuser
+
+# test _libtest
+# test _bintest
+# test _pathtest
+# test _get_dep_port
+# test get_canonical_archs
+# test get_canonical_archflags
+# test check_supported_archs
+
+
+# test _check_xcode_version
+# test _archive_available
+
+
+cleanupTests

Copied: branches/new-help-system/base/src/port1.0/tests/statefile (from rev 117083, trunk/base/src/port1.0/tests/statefile)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/statefile	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/statefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,6 @@
+version: 3
+target: org.macports.fetch
+target: org.macports.checksum
+target: org.macports.extract
+target: org.macports.patch
+target: org.macports.configure

Copied: branches/new-help-system/base/src/port1.0/tests/test.tcl (from rev 117083, trunk/base/src/port1.0/tests/test.tcl)
===================================================================
--- branches/new-help-system/base/src/port1.0/tests/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/src/port1.0/tests/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,131 @@
+# Global vars
+set arguments ""
+set test_name ""
+set color_out ""
+set tcl ""
+set err ""
+
+# Get tclsh path.
+set autoconf ../../Mk/macports.autoconf.mk
+set fp [open $autoconf r]
+while {[gets $fp line] != -1} {
+    if {[string match "TCLSH*" $line] != 0} {
+        set tcl [lrange [split $line " "] 1 1]
+    }
+}
+
+proc print_help {arg} {
+    if { $arg eq "tests" } {
+        puts "The list of available tests is:"
+	cd tests
+	set test_suite [glob *.test]
+        foreach test $test_suite {
+            puts [puts -nonewline "  "]$test
+        }
+    } else {
+        puts "Usage: tclsh test.tcl \[-debug level\] \[-t test\] \[-l\]\n"
+        puts "  -debug LVL : sets the level of printed debug info \[0-3\]"
+        puts "  -t TEST    : run a specific test"
+        puts "  -nocolor   : disable color output (for automatic testing)"
+        puts "  -l         : print the list of available tests"
+        puts "  -h, -help  : print this message\n"
+    }
+}
+
+# Process args
+foreach arg $argv {
+    if { $arg eq "-h" || $arg eq "-help" } {
+        print_help ""
+        exit 0
+    } elseif { $arg eq "-debug" } {
+        set index [expr {[lsearch $argv $arg] + 1}]
+        set level [lindex $argv $index]
+        if { $level >= 0 && $level <= 3 } {
+            append arguments "-debug " $level
+        } else {
+            puts "Invalid debug level."
+            exit 1
+        }
+    } elseif { $arg eq "-t" } {
+        set index [expr {[lsearch $argv $arg] + 1}]
+        set test_name [lindex $argv $index]
+        set no 0
+	cd tests
+	set test_suite [glob *.test]
+        foreach test $test_suite {
+            if { $test_name != $test } {
+                set no [expr {$no + 1}]
+            }
+        }
+        if { $no == [llength $test_suite] } {
+            print_help tests
+            exit 1
+        }
+    } elseif { $arg eq "-l" } {
+        print_help tests
+        exit 0
+    } elseif { $arg eq "-nocolor" } {
+        set color_out "no"
+    }
+}
+
+
+# Run tests
+if { $test_name ne ""} {
+    set result [eval exec $tcl $test_name $arguments 2>@stderr]
+    puts $result
+
+} else {
+    cd tests
+    set test_suite [glob *.test]
+
+    foreach test $test_suite {
+        set result [eval exec $tcl $test $arguments 2>@stderr]
+	set lastline [lindex [split $result "\n"] end]
+
+	if {[lrange [split $lastline "\t"] 1 1] != "Total"} {
+	    set lastline [lindex [split $result "\n"] end-2]
+	    set errmsg [lindex [split $result "\n"] end]
+	}
+
+	set splitresult [split $lastline "\t"]
+        set total [lindex $splitresult 2]
+        set pass [lindex $splitresult 4]
+        set skip [lindex $splitresult 6]
+        set fail [lindex $splitresult 8]
+
+	# Format output
+	if {$total < 10} { set total "0${total}"}
+	if {$pass < 10} { set pass "0${pass}"}
+	if {$skip < 10} { set skip "0${skip}"}
+	if {$fail < 10} { set fail "0${fail}"}
+
+        # Check for errors.
+        if { $fail != 0 } { set err "yes" }
+
+        set out ""
+        if { ($fail != 0 || $skip != 0) && $color_out eq "" } {
+            # Color failed tests.
+            append out "\x1b\[1;31mTotal:" $total " Passed:" $pass " Failed:" $fail " Skipped:" $skip "  \x1b\[0m" $test
+        } else {
+            append out "Total:" $total " Passed:" $pass " Failed:" $fail " Skipped:" $skip "  " $test
+        }
+
+        # Print results and constrints for auto-skipped tests.
+        puts $out
+        if { $skip != 0 } {
+            set out "    Constraint: "
+            append out [string trim $errmsg "\t {}"]
+            puts $out
+        }
+	if { $fail != 0 } {
+	    set end [expr {[string first $test $result 0] - 1}]
+	    puts [string range $result 0 $end]
+	}
+    }
+}
+
+# Return 1 if errors were found.
+if {$err ne ""} { exit 1 }
+
+return 0

Modified: branches/new-help-system/base/src/programs/daemondo/main.c
===================================================================
--- branches/new-help-system/base/src/programs/daemondo/main.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/programs/daemondo/main.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -116,6 +116,7 @@
 int				    restartWait		   	= 3;      	// Default wait during restart is 3 seconds
 
 
+__printflike(1, 2)
 void
 LogMessage(const char* fmt, ...)
 {
@@ -514,7 +515,7 @@
             LogMessage("Unable to launch process %s.\n", argv[0]);
             _exit(1);
         }
-        break;
+        /*NOTREACHED*/
     
     case -1:
         // error starting child process
@@ -1226,7 +1227,7 @@
         case ':':
             printf("Option error: missing argument for option %s\n", longopts[optindex].name);
             exit(1);
-            break;
+            /*NOTREACHED*/
             
         case 's':
             if (startArgs)
@@ -1326,7 +1327,7 @@
         case 'h':
             DoHelp();
             exit(0);
-            break;
+            /*NOTREACHED*/
             
         case 'l':
             if (label != NULL)

Modified: branches/new-help-system/base/src/registry2.0/portimage.tcl
===================================================================
--- branches/new-help-system/base/src/registry2.0/portimage.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/portimage.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -66,7 +66,7 @@
 
 # takes a composite version spec rather than separate version,revision,variants
 proc activate_composite {name {v ""} {optionslist ""}} {
-    if {$v == ""} {
+    if {$v eq ""} {
         return [activate $name "" "" 0 $optionslist]
     } elseif {[registry::decode_spec $v version revision variants]} {
         return [activate $name $version $revision $variants $optionslist]
@@ -107,19 +107,19 @@
         # if another version of this port is active, deactivate it first
         set current [registry::entry installed $name]
         foreach i $current {
-            if { ![string equal $specifier "[$i version]_[$i revision][$i variants]"] } {
+            if { $specifier ne "[$i version]_[$i revision][$i variants]" } {
                 lappend todeactivate $i
             }
         }
 
         # this shouldn't be possible
-        if { ![string equal [$requested installtype] "image"] } {
+        if { [$requested installtype] ne "image" } {
             return -code error "Image error: ${name} @${specifier} not installed as an image."
         }
         if {![::file isfile $location]} {
             return -code error "Image error: Can't find image file $location"
         }
-        if { [string equal [$requested state] "installed"] } {
+        if {[$requested state] eq "installed"} {
             return -code error "Image error: ${name} @${specifier} is already active."
         }
     }
@@ -137,7 +137,7 @@
 
 # takes a composite version spec rather than separate version,revision,variants
 proc deactivate_composite {name {v ""} {optionslist ""}} {
-    if {$v == ""} {
+    if {$v eq ""} {
         return [deactivate $name "" "" 0 $optionslist]
     } elseif {[registry::decode_spec $v version revision variants]} {
         return [deactivate $name $version $revision $variants $optionslist]
@@ -162,7 +162,7 @@
         set registry_open yes
     }
 
-    if { [string equal $name ""] } {
+    if {$name eq ""} {
         throw registry::image-error "Registry error: Please specify the name of the port."
     }
     set ilist [registry::entry installed $name]
@@ -175,10 +175,10 @@
     set name [$requested name]
     set specifier "[$requested version]_[$requested revision][$requested variants]"
 
-    if {$version != "" && ($version != [$requested version] ||
-        ($revision != "" && ($revision != [$requested revision] || $variants != [$requested variants])))} {
+    if {$version ne "" && ($version != [$requested version] ||
+        ($revision ne "" && ($revision != [$requested revision] || $variants != [$requested variants])))} {
         set v $version
-        if {$revision != ""} {
+        if {$revision ne ""} {
             append v _${revision}${variants}
         }
         return -code error "Active version of $name is not $v but ${specifier}."
@@ -186,11 +186,11 @@
 
     ui_msg "$UI_PREFIX [format [msgcat::mc "Deactivating %s @%s"] $name $specifier]"
 
-    if { ![string equal [$requested installtype] "image"] } {
+    if { [$requested installtype] ne "image" } {
         return -code error "Image error: ${name} @${specifier} not installed as an image."
     }
     # this shouldn't be possible
-    if { [$requested state] != "installed" } {
+    if { [$requested state] ne "installed" } {
         return -code error "Image error: ${name} @${specifier} is not active."
     }
 
@@ -207,12 +207,12 @@
 
     set searchkeys $name
     set composite_spec ""
-    if {$version != ""} {
+    if {$version ne ""} {
         lappend searchkeys $version
         set composite_spec $version
         # restriction imposed by underlying registry API (see entry.c):
         # if a revision is specified, so must variants be
-        if {$revision != ""} {
+        if {$revision ne ""} {
             lappend searchkeys $revision $variants
             append composite_spec _${revision}${variants}
         }
@@ -226,7 +226,7 @@
             set iversion [$i version]
             set irevision [$i revision]
             set ivariants [$i variants]
-            if { [$i state] == "installed" } {
+            if { [$i state] eq "installed" } {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s (active)"] $iname $iversion $irevision $ivariants]"
             } else {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s"] $iname $iversion $irevision $ivariants]"
@@ -236,7 +236,7 @@
     } elseif { [llength $ilist] == 1 } {
         return [lindex $ilist 0]
     }
-    if {$composite_spec != ""} {
+    if {$composite_spec ne ""} {
         set composite_spec " @${composite_spec}"
     }
     throw registry::invalid "Registry error: ${name}${composite_spec} is not installed."
@@ -469,7 +469,7 @@
                     }
                 }
 
-                if {$owner != "replaced"} {
+                if {$owner ne "replaced"} {
                     if { [string is true -strict $force] } {
                         # if we're forcing the activation, then we move any existing
                         # files to a backup file, both in the filesystem and in the
@@ -559,7 +559,7 @@
         }
         # reactivate deactivated ports
         foreach entry [array names todeactivate] {
-            if {[$entry state] == "imaged" && ($noexec || ![registry::run_target $entry activate ""])} {
+            if {[$entry state] eq "imaged" && ($noexec || ![registry::run_target $entry activate ""])} {
                 activate [$entry name] [$entry version] [$entry revision] [$entry variants] [list ports_activate_no-exec $noexec]
             }
         }
@@ -580,10 +580,10 @@
         ui_debug "$dstfile does not exist"
         return
     }
-    if { $filetype == "link" } {
+    if { $filetype eq "link" } {
         ui_debug "deactivating link: $dstfile"
         file delete -- $dstfile
-    } elseif { $filetype == "directory" } {
+    } elseif { $filetype eq "directory" } {
         # 0 item means empty.
         if { [llength [readdir $dstfile]] == 0 } {
             variable precious_dirs
@@ -606,7 +606,7 @@
     set files [list]
 
     foreach file $imagefiles {
-        if { [::file exists $file] || (![catch {::file type $file}] && [::file type $file] == "link") } {
+        if { [::file exists $file] || (![catch {::file type $file}] && [::file type $file] eq "link") } {
             # Normalize the file path to avoid removing the intermediate
             # symlinks (remove the empty directories instead)
             # Remark: paths in the registry may be not normalized.

Modified: branches/new-help-system/base/src/registry2.0/portuninstall.tcl
===================================================================
--- branches/new-help-system/base/src/registry2.0/portuninstall.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/portuninstall.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -43,7 +43,7 @@
 
 # takes a composite version spec rather than separate version,revision,variants
 proc uninstall_composite {portname {v ""} {optionslist ""}} {
-    if {$v == ""} {
+    if {$v eq ""} {
         return [uninstall $portname "" "" 0 $optionslist]
     } elseif {[registry::decode_spec $v version revision variants]} {
         return [uninstall $portname $version $revision $variants $optionslist]
@@ -75,12 +75,12 @@
 
     set searchkeys $portname
     set composite_spec ""
-    if {$version != ""} {
+    if {$version ne ""} {
         lappend searchkeys $version
         set composite_spec $version
         # restriction imposed by underlying registry API (see entry.c):
         # if a revision is specified, so must variants be
-        if {$revision != ""} {
+        if {$revision ne ""} {
             lappend searchkeys $revision $variants
             append composite_spec _${revision}${variants}
         }
@@ -92,7 +92,7 @@
         ui_msg "$UI_PREFIX [msgcat::mc "The following versions of $portname are currently installed:"]"
         foreach i [portlist_sortint $ilist] {
             set ispec "[$i version]_[$i revision][$i variants]"
-            if { [string equal [$i state] installed] } {
+            if {[$i state] eq "installed"} {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s (active)"] [$i name] $ispec]"
             } else {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s"] [$i name] $ispec]"
@@ -106,7 +106,7 @@
         set variants [$port variants]
         set composite_spec "${version}_${revision}${variants}"
     } else {
-        if {$composite_spec != ""} {
+        if {$composite_spec ne ""} {
             set composite_spec " @${composite_spec}"
         }
         throw registry::invalid "Registry error: ${portname}${composite_spec} not registered as installed"
@@ -122,7 +122,7 @@
         }
         foreach depport [$port dependents] {
             # make sure it's still installed, since a previous dep uninstall may have removed it
-            if {[registry::entry exists $depport] && ([$depport state] == "imaged" || [$depport state] == "installed")} {
+            if {[registry::entry exists $depport] && ([$depport state] eq "imaged" || [$depport state] eq "installed")} {
                 if {[info exists options(ports_uninstall_no-exec)] || ![registry::run_target $depport uninstall $optionslist]} {
                     registry_uninstall::uninstall [$depport name] [$depport version] [$depport revision] [$depport variants] $optionslist
                 }
@@ -137,7 +137,7 @@
         registry::check_dependents $port ${uninstall.force} "uninstall"
     }
     # if it's active, deactivate it
-    if { [string equal [$port state] installed] } {
+    if {[$port state] eq "installed"} {
         if {[info exists options(ports_dryrun)] && [string is true -strict $options(ports_dryrun)]} {
             ui_msg "For $portname @${composite_spec}: skipping deactivate (dry run)"
         } else {

Modified: branches/new-help-system/base/src/registry2.0/receipt_flat.tcl
===================================================================
--- branches/new-help-system/base/src/registry2.0/receipt_flat.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/receipt_flat.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -88,7 +88,7 @@
     }
 
     # Might as well bail out early if no file to match
-    if {![string length $matchfile]} {
+    if {$matchfile eq ""} {
 		return ""
     }
 
@@ -117,8 +117,8 @@
 	if { ![::file isdirectory $receipt_path] } {
 		set receipt_file [get_head_entry_receipt_path $name $version]
 		
-		if {![string length $receipt_file]} {
-			if { $version != "" } {
+		if {$receipt_file eq ""} {
+			if { $version ne "" } {
 				return -code error "Registry error: ${name} @${version}_${revision}${variants} not registered as installed."
 			} else {
 				return -code error "Registry error: ${name} not registered as installed."
@@ -126,13 +126,13 @@
 		}
 		
 		# Extract the version from the path.
-		if { $version == "" } {
+		if { $version eq "" } {
 			set theFileName [::file tail $receipt_file]
 			regexp "^$name-(.*)\$" $theFileName match version
 		}
 	} else {
 		# If version wasn't specified, find out the version number.
-		if { $version == "" } {
+		if { $version eq "" } {
 			# xxx: We really should have had the 
 			# version given to us.  How should we handle this?
 			set x [glob -nocomplain -directory ${receipt_path} *]
@@ -451,9 +451,9 @@
 
 	set query_path [::file join ${macports::registry.path} receipts]
 	
-	if { $name == "" } {
+	if { $name eq "" } {
 		set query_path [::file join ${query_path} *]
-		if { $version == "" } {
+		if { $version eq "" } {
 			set query_path [::file join ${query_path} *]
 		}
 		# [PG] Huh?
@@ -472,7 +472,7 @@
 	        }
 	    }
 		set query_path [::file join ${query_path} ${name}]
-		if { $version != "" } {
+		if { $version ne "" } {
 			set query_path [::file join ${query_path} ${version}]
 		} else {
 			set query_path [::file join ${query_path} *]
@@ -495,7 +495,7 @@
 	}
 
 	# append the ports in old HEAD format.
-	if { $name == "" } {
+	if { $name eq "" } {
 		set query_path [::file join ${macports::registry.path} receipts *]
 	} else {
 		set query_path [::file join ${macports::registry.path} receipts ${name}-*]
@@ -506,7 +506,7 @@
 
     	# Remark: these regexes do not always work.
    		set theName ""
-    	if { $name == "" } {
+    	if { $name eq "" } {
 			regexp {^(.*)-(.*)$} $theFileName match theName version
     	} else {
 			regexp "^($name)-(.*)\$" $theFileName match theName version
@@ -662,7 +662,7 @@
 
 	open_file_map
 
-	if { [::file type $file] == "link" } {
+	if { [::file type $file] eq "link" } {
 		ui_debug "Adding link to file_map: $file for: $port"
 	} else {
 		ui_debug "Adding file to file_map: $file for: $port"
@@ -684,7 +684,7 @@
 
 	foreach f $files {
 		set file [lindex $f 0]
-		if { [::file type $file] == "link" } {
+		if { [::file type $file] eq "link" } {
 			ui_debug "Adding link to file_map: $file for: $port"
 		} else {
 			ui_debug "Adding file to file_map: $file for: $port"
@@ -828,7 +828,7 @@
     set dep_map $new_map
     
     set newlen [llength $dep_map]
-    set diff [expr $oldlen - $newlen]
+    set diff [expr {$oldlen - $newlen}]
     ui_debug "New dep_map has $newlen entries"
     ui_info "Removed $diff duplicate entries from the dependency map"
 }

Modified: branches/new-help-system/base/src/registry2.0/receipt_sqlite.tcl
===================================================================
--- branches/new-help-system/base/src/registry2.0/receipt_sqlite.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/receipt_sqlite.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -44,7 +44,7 @@
 
 # return list of active ports, or active version of port 'name' if specified
 proc active {name} {
-    if {$name != ""} {
+    if {$name ne ""} {
         set ports [registry::entry installed $name]
     } else {
         set ports [registry::entry installed]
@@ -87,7 +87,7 @@
 #
 proc file_registered {file} {
     set port [registry::entry owner $file]
-	if {$port != ""} {
+	if {$port ne ""} {
 		return [$port name]
 	} else {
 		return 0
@@ -164,9 +164,9 @@
 # version for example, so we don't attempt to split up the composite version
 # into its components, we just compare the whole thing.
 proc installed {{name ""} {version ""}} {
-	if { $name == "" && $version == "" } {
+	if { $name eq "" && $version eq "" } {
 	    set ports [registry::entry imaged]
-	} elseif { $name != "" && $version == ""} {
+	} elseif { $name ne "" && $version eq ""} {
 	    set ports [registry::entry imaged $name]
 	} else {
 	    set ports {}
@@ -197,7 +197,7 @@
 	set rlist [list]
 	set searchcmd "registry::entry search"
     foreach key {name version revision} {
-        if {[set $key] != ""} {
+        if {[set $key] ne ""} {
             append searchcmd " $key [set $key]"
         }
     }
@@ -221,7 +221,7 @@
 	set rlist [list]
 	set searchcmd "registry::entry search"
     foreach key {name version revision} {
-        if {[set $key] != ""} {
+        if {[set $key] ne ""} {
             append searchcmd " $key [set $key]"
         }
     }
@@ -251,9 +251,9 @@
         $regref location $props(location)
         $regref state $props(state)
         $regref installtype $props(installtype)
-        if {$props(installtype) == "image"} {
+        if {$props(installtype) eq "image"} {
             $regref map $props(imagefiles)
-            if {$props(state) == "installed"} {
+            if {$props(state) eq "installed"} {
                 if {[llength $props(imagefiles)] != [llength $props(files)]} {
                     # deal with this mess, just drop the extras...
                     set i 0


Property changes on: branches/new-help-system/base/src/registry2.0/receipt_sqlite.tcl
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/registry1.0/receipt_sqlite.tcl:37343-46937
/branches/gsoc09-logging/base/src/registry1.0/receipt_sqlite.tcl:51231-60371
/branches/gsoc11-rev-upgrade/base/src/registry2.0/receipt_sqlite.tcl:78828-88375
/branches/universal-sanity/base/src/registry1.0/receipt_sqlite.tcl:51872-52323
/branches/variant-descs-14482/base/src/registry1.0/receipt_sqlite.tcl:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/registry2.0/receipt_sqlite.tcl:57889-90355
/users/perry/base-bugs_and_notes/src/registry1.0/receipt_sqlite.tcl:45682-46060
/users/perry/base-select/src/registry1.0/receipt_sqlite.tcl:44044-44692
   + /branches/gsoc08-privileges/base/src/registry1.0/receipt_sqlite.tcl:37343-46937
/branches/gsoc09-logging/base/src/registry1.0/receipt_sqlite.tcl:51231-60371
/branches/gsoc11-rev-upgrade/base/src/registry2.0/receipt_sqlite.tcl:78828-88375
/branches/gsoc13-tests/src/registry2.0/receipt_sqlite.tcl:106692-111324
/branches/universal-sanity/base/src/registry1.0/receipt_sqlite.tcl:51872-52323
/branches/variant-descs-14482/base/src/registry1.0/receipt_sqlite.tcl:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/registry2.0/receipt_sqlite.tcl:57889-117083
/users/perry/base-bugs_and_notes/src/registry1.0/receipt_sqlite.tcl:45682-46060
/users/perry/base-select/src/registry1.0/receipt_sqlite.tcl:44044-44692

Modified: branches/new-help-system/base/src/registry2.0/registry.tcl
===================================================================
--- branches/new-help-system/base/src/registry2.0/registry.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/registry.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -156,10 +156,10 @@
     }
     
     if { [llength $rlist] < 1 } {
-        if { $name == "" } {
+        if { $name eq "" } {
             return -code error "Registry error: No ports registered as installed."
         } else {
-            if { $version == "" } {
+            if { $version eq "" } {
                 return -code error "Registry error: $name not registered as installed."
             } else {
                 return -code error "Registry error: $name $version not registered as installed."
@@ -196,7 +196,7 @@
     }
 	
 	if { [llength $rlist] < 1 } {
-		if { $name == "" } {
+		if { $name eq "" } {
 			return -code error "Registry error: No ports registered as active."
 		} else {
 			return -code error "Registry error: $name not registered as installed & active."
@@ -320,7 +320,7 @@
     # (we won't store the md5 of the target of links since it's meaningless
     # and $statvar(mode) tells us that links are links).
     if {![catch {file lstat $fname statvar}]} {
-	if {[::file isfile $fname] && [::file type $fname] != "link"} {
+	if {[::file isfile $fname] && [::file type $fname] ne "link"} {
 	    if {[catch {md5 file $fname} md5sum] == 0} {
 		# Create a line that matches md5(1)'s output
 		# for backwards compatibility
@@ -346,7 +346,7 @@
 
 	set rval [list]
 	foreach file $flist {
-		if {[string index $file 0] != "/"} {
+		if {[string index $file 0] ne "/"} {
 			set file [::file join $prefix $file]
 		}
 		lappend rval [fileinfo_for_file $file]
@@ -405,10 +405,10 @@
         set lockfd [::open $lockpath w]
     }
     if {[catch {flock $lockfd -exclusive -noblock} result]} {
-        if {$result == "EAGAIN"} {
+        if {$result eq "EAGAIN"} {
             ui_msg "Waiting for lock on $lockpath"
             flock $lockfd -exclusive
-        } elseif {$result == "EOPNOTSUPP"} {
+        } elseif {$result eq "EOPNOTSUPP"} {
             # Locking not supported, just return
             ui_debug "flock not supported, not locking registry"
         } else {
@@ -457,7 +457,7 @@
         set installtype [receipt_flat::property_retrieve $iref installtype]
         lappend proplist installtype $installtype
         set location [receipt_flat::property_retrieve $iref location]
-        if {$location == "0"} {
+        if {$location == 0} {
             set location [receipt_flat::property_retrieve $iref imagedir]
         }
         set contents [receipt_flat::property_retrieve $iref contents]
@@ -466,7 +466,7 @@
         foreach f $contents {
             set fullpath [lindex $f 0]
             # strip image dir from start
-            if {[string range $fullpath 0 [expr $idlen - 1]] == $location} {
+            if {[string range $fullpath 0 [expr {$idlen - 1}]] == $location} {
                 set path [string range $fullpath $idlen [string length $fullpath]]
             } else {
                 set path $fullpath

Modified: branches/new-help-system/base/src/registry2.0/registry_util.tcl
===================================================================
--- branches/new-help-system/base/src/registry2.0/registry_util.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/registry_util.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -63,14 +63,14 @@
 ## @param [in] force if true, continue even if there are dependents
 proc check_dependents {port force {action "uninstall/deactivate"}} {
     global UI_PREFIX
-    if {[$port state] == "installed" || [llength [registry::entry imaged [$port name]]] == 1} {
+    if {[$port state] eq "installed" || [llength [registry::entry imaged [$port name]]] == 1} {
         # Check if any installed ports depend on this one
         set deplist [$port dependents]
-        if {$action == "deactivate"} {
+        if {$action eq "deactivate"} {
             set active_deplist {}
             # Check if any active ports depend on this one
             foreach p $deplist {
-                if {[$p state] == "installed"} {
+                if {[$p state] eq "installed"} {
                     lappend active_deplist $p
                 }
             }
@@ -94,7 +94,7 @@
 ## @return   true if successful, false otherwise
 proc run_target {port target options} {
     set portspec "[$port name] @[$port version]_[$port revision][$port variants]"
-    if {[$port portfile] == ""} {
+    if {[$port portfile] eq ""} {
         ui_debug "no portfile in registry for $portspec"
         return 0
     }
@@ -107,12 +107,12 @@
             ui_warn "Failed to execute portfile from registry for $portspec"
             switch $target {
                 activate {
-                    if {[$port state] == "installed"} {
+                    if {[$port state] eq "installed"} {
                         return 1
                     }
                 }
                 deactivate {
-                    if {[$port state] == "imaged"} {
+                    if {[$port state] eq "imaged"} {
                         return 1
                     }
                 }
@@ -124,7 +124,7 @@
             }
         } else {
             global macports::keeplogs
-            if {(![info exists keeplogs] || !$keeplogs) && $target != "activate"} {
+            if {(![info exists keeplogs] || !$keeplogs) && $target ne "activate"} {
                 catch {mportexec $mport clean}
             }
             mportclose_installed $mport

Modified: branches/new-help-system/base/src/registry2.0/tests/entry.tcl
===================================================================
--- branches/new-help-system/base/src/registry2.0/tests/entry.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/tests/entry.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -7,11 +7,12 @@
     load $pextlibname
 
     # totally lame that file delete won't do it
-	eval exec rm -f [glob -nocomplain test.db*]
+    eval exec rm -f [glob -nocomplain test.db*]
 
     # can't create registry in some brain-dead place or in protected place
     test_throws {registry::open /some/brain/dead/place} registry::cannot-init
-    test_throws {registry::open /etc/macports_test_prot~} registry::cannot-init
+    # This would actually work when testing with sudo :(
+    #test_throws {registry::open /etc/macports_test_prot~} registry::cannot-init
 
     # can't use registry before it's opened
     test_throws {registry::write {}} registry::misuse

Modified: branches/new-help-system/base/src/registry2.0/util.c
===================================================================
--- branches/new-help-system/base/src/registry2.0/util.c	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/registry2.0/util.c	2014-02-15 14:35:04 UTC (rev 117084)
@@ -49,7 +49,7 @@
  * objects of a similar nature.
  */
 char* unique_name(Tcl_Interp* interp, char* prefix, int* lower_bound) {
-    int result_size = strlen(prefix) + TCL_INTEGER_SPACE + 1;
+    size_t result_size = strlen(prefix) + TCL_INTEGER_SPACE + 1;
     char* result = malloc(result_size);
     Tcl_CmdInfo info;
     int i;
@@ -243,7 +243,7 @@
 int recast(void* userdata, cast_function* fn, void* castcalldata,
         free_function* del, void*** outv, void** inv, int inc,
         reg_error* errPtr) {
-    void** result = malloc(inc*sizeof(void*));
+    void** result = malloc((size_t)inc*sizeof(void*));
     int i;
     if (!result) {
         return 0;

Modified: branches/new-help-system/base/src/upgrade_sources_conf_default.tcl
===================================================================
--- branches/new-help-system/base/src/upgrade_sources_conf_default.tcl	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/src/upgrade_sources_conf_default.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -58,7 +58,7 @@
                      }
                   }
                }
-               if {$svnCmd == ""} {
+               if {$svnCmd eq ""} {
                   puts "WARNING: Unable to check svn URL for '$filepath' because no svn command could be found; please manually verify $sourcesConf!"
                   continue
                }

Deleted: branches/new-help-system/base/tests/Makefile
===================================================================
--- branches/new-help-system/base/tests/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,86 +0,0 @@
-include ../Mk/macports.autoconf.mk
-
-TESTS?=checksums-1 svn-and-patchsites envvariables site-tags trace universal universal-2 xcodeversion dependencies-c dependencies-d dependencies-e case-insensitive-deactivate variants statefile-version1 statefile-version1-outdated statefile-version2 statefile-version2-outdated statefile-version2-invalid statefile-unknown-version
-
-PWD=$(shell pwd)
-
-.PHONY: all clean install test PortIndex
-
-all::
-
-/tmp/macports-tests/opt/local/etc/macports/sources.conf: sources.conf
-	@echo setting up test installation
-	rm -rf /tmp/macports-tests/
-	mkdir -p /tmp/macports-tests/ports
-	mkdir -p /tmp/macports-tests/opt/local/etc/macports/
-	mkdir -p /tmp/macports-tests/opt/local/share/
-	mkdir -p /tmp/macports-tests/opt/local/var/macports/receipts/
-	mkdir -p /tmp/macports-tests/opt/local/var/macports/registry/
-	mkdir -p /tmp/macports-tests/opt/local/var/macports/build/
-	ln -s $(datadir)/macports /tmp/macports-tests/opt/local/share/
-	ln -s $(PWD)/test /tmp/macports-tests/ports/
-	cp sources.conf /tmp/macports-tests/opt/local/etc/macports/
-
-/tmp/macports-tests/ports/PortIndex: /tmp/macports-tests/opt/local/etc/macports/sources.conf PortIndex
-	cp PortIndex PortIndex.quick /tmp/macports-tests/ports/
-
-PortIndex:
-	$(bindir)/portindex
-
-clean::
-	rm -rf /tmp/macports-tests/
-	rm -f PortIndex PortIndex.quick
-	for testname in $(TESTS); do \
-		rm -f test/$$testname/{output,output.sed,difference,work}; \
-	done
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running these tests"
-	@exit 1
-
-# Run all tests
-# Use TESTS to choose which tests to run
-# For example: make test TESTS="checkums-1 universal"
-test:: clean /tmp/macports-tests/ports/PortIndex /tmp/macports-tests/opt/local/etc/macports/sources.conf
-	@num=0; \
-	success=0; \
-	for testname in $(TESTS); do\
-		subdir=test/$$testname; \
-		echo ===\> test ${DIRPRFX}$$subdir; \
-		if [ -e $$subdir/Makefile ]; then \
-			( cd $$subdir && \
-				$(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ PORTSRC=$(PWD)/test-macports.conf test) && \
-			success=$$(( success + 1 )); \
-		else \
-			( cd $$subdir && \
-				PORTSRC=$(PWD)/test-macports.conf $(bindir)/port clean > /dev/null && \
-				PORTSRC=$(PWD)/test-macports.conf $(bindir)/port test > output 2>&1 \
-					|| ([ -e error_expected ] || (cat output; exit 1)) && \
-			sed -e "s|${PWD}|PWD|g" < output > output.sed && \
-			diff -u master output.sed 2>&1 | tee difference && \
-			if [ -s difference ]; then \
-				exit 1; \
-			else \
-				rm -f difference output.sed; \
-			fi) && \
-			success=$$(( success + 1 )); \
-			if [ -n "`PORTSRC=$(PWD)/test-macports.conf $(bindir)/port -q echo installed`" ]; then \
-			    PORTSRC=$(PWD)/test-macports.conf $(bindir)/port -f clean --all installed > /dev/null && \
-			    PORTSRC=$(PWD)/test-macports.conf $(bindir)/port -f uninstall installed > /dev/null; \
-			fi; \
-		fi; \
-		num=$$(( num + 1 )); \
-	done; \
-	echo ===\> $$success of $$num tests passed.
-	@rm -rf /tmp/macports-tests/
-	@rm -f PortIndex PortIndex.quick
-
-# Run specific test
-# Prepend the directory name with "test-" and use it as target
-# For example: make test-checksums-1
-test-%:
-	$(MAKE) TESTS="$(@:test-%=%)" test
-
-install::
-
-distclean:: clean

Copied: branches/new-help-system/base/tests/Makefile (from rev 117083, trunk/base/tests/Makefile)
===================================================================
--- branches/new-help-system/base/tests/Makefile	                        (rev 0)
+++ branches/new-help-system/base/tests/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,14 @@
+include ../Mk/macports.autoconf.mk
+
+all:: ../Mk/macports.autoconf.mk
+
+install::
+
+# Run all regression tests
+# tclsh test.tcl -h for more options.
+test::
+	$(TCLSH) test.tcl -nocolor
+
+clean::
+
+distclean:: clean

Copied: branches/new-help-system/base/tests/test/case-insensitive-deactivate/DESCRIPTION (from rev 117083, trunk/base/tests/test/case-insensitive-deactivate/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/case-insensitive-deactivate/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/case-insensitive-deactivate/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,10 @@
+This test checks for case-insensitive port names. From Portfile.in it
+generates a Portfile which is installed with a lowercase name (casesensitive)
+and uninstalled with a CamelCase name (CaseSensitivE). The install/uninstall
+is verified by the existance/absence of the '/tmp/macports-tests/opt/local/var/test/case'
+file.
+
+There are 2 test cases. One to install a port and the other to uninstall.
+
+See ticket #11759,
+https://trac.macports.org/ticket/11759

Deleted: branches/new-help-system/base/tests/test/case-insensitive-deactivate/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/case-insensitive-deactivate/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/case-insensitive-deactivate/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,31 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-# see test-macports.conf for the value of prefix
-TESTFILE=/tmp/macports-tests/opt/local/var/test/case
-TESTPORT1=casesensitive
-TESTPORT2=CaseSensitivE
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@echo port install $(TESTPORT1)
-	@sed 's/@name@/$(TESTPORT1)/' Portfile.in > Portfile
-	@PORTSRC=$(PORTSRC) $(bindir)/port install > output 2>&1 || (cat output; exit 1)
-	@if [ ! -f $(TESTFILE) ]; then \
-		echo "FAILED: File should exist after install: $(TESTFILE)" && exit 1; \
-	fi
-	@echo port uninstall $(TESTPORT2)
-	@sed 's/@name@/$(TESTPORT2)/' Portfile.in > Portfile
-	@PORTSRC=$(PORTSRC) $(bindir)/port uninstall > output 2>&1 || (cat output; exit 1)
-	@if [ -f $(TESTFILE) ]; then \
-		rm $(TESTFILE); \
-		echo "FAILED: File should NOT exist after uninstall: $(TESTFILE)" && exit 1; \
-	else \
-		echo "SUCCESS!"; \
-	fi
-	rm Portfile
-	rm output

Copied: branches/new-help-system/base/tests/test/case-insensitive-deactivate/test.tcl (from rev 117083, trunk/base/tests/test/case-insensitive-deactivate/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/case-insensitive-deactivate/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/case-insensitive-deactivate/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,61 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" "Portfile"
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+set testfile "/tmp/macports-tests/opt/local/var/test/case"
+set testport1 "casesensitive"
+set testport2 "CaseSensitivE"
+
+load_variables $path
+set_dir
+port_index
+
+proc test_exists {} {
+    global path testfile testport1
+
+    exec sed "s/@name@/$testport1/" $path/Portfile.in > Portfile
+    port_install
+
+    if {[file exists $testfile]} {
+        return "Port installed."
+    } else {
+        return "File missing."
+    }
+}
+
+proc test_not_exists {} {
+    global path testfile testport2
+
+    exec sed "s/@name@/$testport2/" $path/Portfile.in > Portfile
+    port_uninstall
+
+    if {[file exists $testfile]} {
+        return "File still exists."
+    } else {
+        return "Port uninstalled."
+    }
+}
+
+
+# Test cases.
+test file_installed {
+    Regression test for file installed correctly.
+} -body {
+    test_exists
+} -result "Port installed."
+
+test file_uninstalled {
+    Regression test for file uninstalled correctly.
+} -body {
+    test_not_exists
+} -result "Port uninstalled."
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/checksums-1/DESCRIPTION (from rev 117083, trunk/base/tests/test/checksums-1/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/checksums-1/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/checksums-1/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,7 @@
+This test evaluates the checksum values of an empty file against the expected
+ones. These are taken from the output of the 'port -d test' command, by
+searching a line that beging with the string "debug: calculated".
+
+There are 3 test cases, one for each checksum used. The port command must
+return the calculated checksums in debug mode, with the form: "DEBUG:
+Calculated (_checksum-name_) " for the test to work.

Modified: branches/new-help-system/base/tests/test/checksums-1/Portfile
===================================================================
--- branches/new-help-system/base/tests/test/checksums-1/Portfile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/checksums-1/Portfile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -32,4 +32,4 @@
 
 test {
 	# test is actually running checksum target
-}
\ No newline at end of file
+}

Deleted: branches/new-help-system/base/tests/test/checksums-1/master
===================================================================
--- branches/new-help-system/base/tests/test/checksums-1/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/checksums-1/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,6 +0,0 @@
---->  Fetching distfiles for checksum
---->  Verifying checksums for checksum
---->  Extracting checksum
---->  Configuring checksum
---->  Building checksum
---->  Testing checksum

Copied: branches/new-help-system/base/tests/test/checksums-1/test.tcl (from rev 117083, trunk/base/tests/test/checksums-1/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/checksums-1/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/checksums-1/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,46 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+initial_setup
+
+proc get_checksum {type} {
+    global path output_file
+
+    append string "debug: calculated (" $type ")*"
+    set line [get_line $path/$output_file $string]
+    set result [lrange [split $line " "] 4 4]
+
+    return $result
+}
+
+
+# Test cases
+test md5_checksum {
+    Regression test for MD5 Checksum.
+} -body {
+    get_checksum md5
+} -result "d41d8cd98f00b204e9800998ecf8427e"
+
+
+test sha1_checksum {
+    Regression test for SHA1 Checksum.
+} -body {
+    get_checksum sha1
+} -result "da39a3ee5e6b4b0d3255bfef95601890afd80709"
+
+
+test rmd160_checksum {
+    Regression test for RMD160 Checksum.
+} -body {
+    get_checksum rmd160
+} -result "9c1185a5c5e9fc54612808977ee8f548b2258d31"
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/dependencies-a/DESCRIPTION (from rev 117083, trunk/base/tests/test/dependencies-a/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-a/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-a/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test makes sure a dependency added in a variant block
+(this is selected as default variant) is considered.
+
+There is 1 test case.

Copied: branches/new-help-system/base/tests/test/dependencies-a/test.tcl (from rev 117083, trunk/base/tests/test/dependencies-a/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-a/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-a/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,27 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+proc dep-a {} {
+    global path output_file
+
+    initial_setup
+
+    set err "error*"
+    set line [get_line $output_file $err]
+    return $line
+}
+
+test dependencies-a {
+    Regression test for dependencies-a.
+} -body {
+    dep-a
+} -result -1
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/dependencies-b/DESCRIPTION (from rev 117083, trunk/base/tests/test/dependencies-b/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-b/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-b/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test does nothing. (or: ensures a port without dependencies really
+doesn't have any)
+
+There is 1 test case.

Copied: branches/new-help-system/base/tests/test/dependencies-b/test.tcl (from rev 117083, trunk/base/tests/test/dependencies-b/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-b/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-b/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,28 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+proc dep-b {} {
+    global path output_file
+
+    initial_setup
+
+    set err "error*"
+    set line [get_line $output_file $err]
+    return $line
+}
+
+test dependencies-b {
+    Regression test for dependencies-b.
+} -body {
+    dep-b
+} -result -1
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/dependencies-c/DESCRIPTION (from rev 117083, trunk/base/tests/test/dependencies-c/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-c/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-c/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test does the same as dependencies-a, but due to the transitive
+nature of dependencies, also tests what dependencies-a has already tested.
+
+There is 1 test case.

Deleted: branches/new-help-system/base/tests/test/dependencies-c/master
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-c/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/dependencies-c/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,26 +0,0 @@
---->  Computing dependencies for dependencies-c
---->  Dependencies to be installed: dependencies-a dependencies-b
---->  Fetching distfiles for dependencies-b
---->  Verifying checksums for dependencies-b
---->  Extracting dependencies-b
---->  Configuring dependencies-b
---->  Building dependencies-b
---->  Staging dependencies-b into destroot
---->  Installing dependencies-b @1_0
---->  Activating dependencies-b @1_0
---->  Cleaning dependencies-b
---->  Fetching distfiles for dependencies-a
---->  Verifying checksums for dependencies-a
---->  Extracting dependencies-a
---->  Configuring dependencies-a
---->  Building dependencies-a
---->  Staging dependencies-a into destroot
---->  Installing dependencies-a @1_0+i_want_b
---->  Activating dependencies-a @1_0+i_want_b
---->  Cleaning dependencies-a
---->  Fetching distfiles for dependencies-c
---->  Verifying checksums for dependencies-c
---->  Extracting dependencies-c
---->  Configuring dependencies-c
---->  Building dependencies-c
---->  Testing dependencies-c

Copied: branches/new-help-system/base/tests/test/dependencies-c/test.tcl (from rev 117083, trunk/base/tests/test/dependencies-c/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-c/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-c/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,28 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+proc dep-c {} {
+    global path output_file
+
+    initial_setup
+
+    set err "error*"
+    set line [get_line $output_file $err]
+    return $line
+}
+
+test dependencies-c {
+    Regression test for dependencies-c.
+} -body {
+    dep-c
+} -result -1
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/dependencies-d/DESCRIPTION (from rev 117083, trunk/base/tests/test/dependencies-d/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-d/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-d/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks for an invalid dependency specification. The "depends" option
+tested in this test apparently was never implemented.
+
+There is 1 test case.

Deleted: branches/new-help-system/base/tests/test/dependencies-d/master
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-d/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/dependencies-d/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,28 +0,0 @@
-Warning: depends option is not handled yet
-Warning: depends option is not handled yet
---->  Computing dependencies for dependencies-d
---->  Dependencies to be installed: dependencies-a dependencies-b
---->  Fetching distfiles for dependencies-b
---->  Verifying checksums for dependencies-b
---->  Extracting dependencies-b
---->  Configuring dependencies-b
---->  Building dependencies-b
---->  Staging dependencies-b into destroot
---->  Installing dependencies-b @1_0
---->  Activating dependencies-b @1_0
---->  Cleaning dependencies-b
---->  Fetching distfiles for dependencies-a
---->  Verifying checksums for dependencies-a
---->  Extracting dependencies-a
---->  Configuring dependencies-a
---->  Building dependencies-a
---->  Staging dependencies-a into destroot
---->  Installing dependencies-a @1_0+i_want_b
---->  Activating dependencies-a @1_0+i_want_b
---->  Cleaning dependencies-a
---->  Fetching distfiles for dependencies-d
---->  Verifying checksums for dependencies-d
---->  Extracting dependencies-d
---->  Configuring dependencies-d
---->  Building dependencies-d
---->  Testing dependencies-d

Copied: branches/new-help-system/base/tests/test/dependencies-d/test.tcl (from rev 117083, trunk/base/tests/test/dependencies-d/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-d/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-d/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,28 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+proc dep-d {} {
+    global path output_file
+
+    initial_setup
+
+    set err "error*"
+    set line [get_line $output_file $err]
+    return $line
+}
+
+test dependencies-d {
+    Regression test for dependencies-d.
+} -body {
+    dep-d
+} -result -1
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/dependencies-e/DESCRIPTION (from rev 117083, trunk/base/tests/test/dependencies-e/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-e/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-e/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks whether unknown dependencies correctly fail. There should be
+an error saying that the requested dependencies do not exist.
+
+There is 1 test case.

Deleted: branches/new-help-system/base/tests/test/dependencies-e/error_expected
===================================================================
Deleted: branches/new-help-system/base/tests/test/dependencies-e/master
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-e/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/dependencies-e/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,5 +0,0 @@
---->  Computing dependencies for dependencies-e
-Error: Dependency 'docbook-xml-4.1.2' not found.
-To report a bug, follow the instructions in the guide:
-    http://guide.macports.org/#project.tickets
-Error: Processing of port dependencies-e failed

Copied: branches/new-help-system/base/tests/test/dependencies-e/test.tcl (from rev 117083, trunk/base/tests/test/dependencies-e/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/dependencies-e/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/dependencies-e/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,28 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+proc dep-e {} {
+    global path output_file
+
+    initial_setup
+
+    set err "error: dependency 'docbook-xml-4.1.2' not found*"
+    set line [get_line $output_file $err]
+    return $line
+}
+
+test dependencies-e {
+    Regression test for dependencies-e.
+} -body {
+    dep-e
+} -result "error: dependency 'docbook-xml-4.1.2' not found."
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/envvariables/DESCRIPTION (from rev 117083, trunk/base/tests/test/envvariables/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/envvariables/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/envvariables/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,3 @@
+This test ensures that variables set in the environment are available in the
+Portfile. The test runs an 'exec sh' command that exports two variables (ENVA
+and ENVB) and checks weather they get in the output file or not.

Deleted: branches/new-help-system/base/tests/test/envvariables/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/envvariables/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/envvariables/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,18 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean > /dev/null
-	@sh -c "export ENVA=A ; export ENVB=B; \
-		export PORTSRC=$(PORTSRC); $(bindir)/port test" > output 2>&1 || (cat output; exit 1)
-	@diff -u master output 2>&1 | tee difference
-	@if [ -s difference ]; then \
-		exit 1; \
-	else \
-		rm -f difference; \
-	fi

Deleted: branches/new-help-system/base/tests/test/envvariables/master
===================================================================
--- branches/new-help-system/base/tests/test/envvariables/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/envvariables/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,8 +0,0 @@
---->  Fetching distfiles for envvariables
---->  Verifying checksums for envvariables
---->  Extracting envvariables
---->  Configuring envvariables
---->  Building envvariables
---->  Testing envvariables
-A
-B

Copied: branches/new-help-system/base/tests/test/envvariables/test.tcl (from rev 117083, trunk/base/tests/test/envvariables/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/envvariables/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/envvariables/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,39 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+port_clean $path
+
+proc envvar_test {} {
+    global output_file path portsrc bindir
+
+    # Build helping string
+    set string "export ENVA=A; export ENVB=B; "
+    append string "export PORTSRC=${portsrc}; "
+    append string "${bindir}/port test"
+
+    exec sh -c $string > output
+    set line [get_line $path/$output_file "a"]
+    set line2 [get_line $path/$output_file "b"]
+    return $line$line2
+}
+
+test envvariables {
+    Regression test for Environment Variables.
+} -body {
+    envvar_test
+} -result "ab"
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/library.tcl (from rev 117083, trunk/base/tests/test/library.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/library.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/library.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,172 @@
+set autoconf [file dirname $argv0]/../../../Mk/macports.autoconf.mk
+eval ::tcltest::configure $::argv
+
+set output_file "output"
+set work_dir "work"
+
+# Set of procs used for testing.
+
+# Sets $bindir variable from macports.autoconf.mk
+# autogenerated file.
+proc load_variables {pwd} {
+    global autoconf bindir datadir portsrc cpwd
+
+    if { ![file exists $autoconf] } {
+        puts "ERROR: $autoconf does not exist."
+        exit 1
+    }
+
+    set cpwd [file dirname [file dirname $pwd]]
+
+    set line [get_line $autoconf "prefix*"]
+    set prefix [lrange [split $line " "] 1 1]
+
+    set line [get_line $autoconf "bindir*"]
+    set bin [lrange [split $line "/"] 1 1]
+
+    set bindir ${prefix}/${bin}
+    set datadir ${prefix}/share
+    set portsrc ${cpwd}/test-macports.conf
+
+}
+
+proc cleanup {} {
+    global cpwd
+
+    file delete -force /tmp/macports-tests
+    file delete -force ${cpwd}/PortIndex ${cpwd}/PortIndex.quick
+}
+
+# Sets initial directories
+proc set_dir {} {
+    global datadir cpwd
+
+    cleanup
+
+    file mkdir /tmp/macports-tests/ports \
+               /tmp/macports-tests/opt/local/etc/macports \
+               /tmp/macports-tests/opt/local/share \
+               /tmp/macports-tests/opt/local/var/macports/receipts \
+               /tmp/macports-tests/opt/local/var/macports/registry \
+               /tmp/macports-tests/opt/local/var/macports/build
+
+    file link -symbolic /tmp/macports-tests/opt/local/share/macports $datadir/macports
+    file link -symbolic /tmp/macports-tests/ports/test $cpwd/test
+}
+
+# Run portindex
+proc port_index {} {
+    global bindir datadir cpwd
+
+    # Move up 2 level to run portindex.
+    set path [pwd]
+    cd ../..
+    # Avoid warning about ports tree being old
+    exec sh -c {touch */*/Portfile}
+
+    exec ${bindir}/portindex 2>@1
+
+    file copy ${cpwd}/sources.conf /tmp/macports-tests/opt/local/etc/macports/
+    file copy ${cpwd}/PortIndex ${cpwd}/PortIndex.quick /tmp/macports-tests/ports/
+
+    cd $path
+}
+
+# Executes port clean.
+proc port_clean {pwd} {
+    global bindir datadir portsrc
+
+    set back [pwd]
+    cd $pwd
+
+    catch {exec env PORTSRC=${portsrc} ${bindir}/port clean 2>@1}
+    cd $back
+}
+
+# Runs the portfile.
+proc port_run {pwd} {
+    global bindir datadir portsrc
+
+    set back [pwd]
+    cd $pwd
+
+    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port -d test >&output} ]
+    cd $back
+    return $result
+}
+
+# Runs port trace.
+proc port_trace {pwd} {
+    global bindir datadir portsrc
+
+    set back [pwd]
+    cd $pwd
+
+    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port -t test >&output 2>@1} ]
+    cd $back
+    return $result
+}
+
+# Installs new portfile.
+proc port_install {} {
+    global bindir portsrc
+
+    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port install > output 2>@1} ]
+}
+
+# Run configure command.
+proc port_config {pwd} {
+    global path bindir portsrc
+
+    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port configure 2>@1} ]
+}
+
+# Run desroot command.
+proc port_desroot {pwd} {
+    global path bindir portsrc work_dir output_file
+
+    file copy -force ${path}/statefile ${work_dir}/.macports.statefile-unknown-version.state
+    if { [exec id -u] == 0 } {
+        exec chown macports ${work_dir}/.macports.statefile-unknown-version.state
+    }
+    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port destroot >$output_file 2>@1} ]
+}
+
+# Uninstalls portfile.
+proc port_uninstall {} {
+    global bindir portsrc
+
+    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port uninstall > output 2>@1} ]
+}
+
+# Returns the line containint a given string
+# from a given file, or -1 if nothing is found.
+proc get_line {filename lookup} {
+    set fp [open $filename r]
+
+    while {[gets $fp line] != -1} {
+        set line [string tolower $line]
+
+        if {[string match $lookup $line] != 0} {
+            close $fp
+            return $line
+        }
+    }
+    return -1
+}
+
+# This proc contains all the steps necesary
+# to install a port and save the output to a file.
+# Needed for the majority of regression tests.
+proc initial_setup {} {
+    global output_file work_dir path
+
+    makeFile "" $output_file
+    makeDirectory $work_dir
+
+    load_variables $path
+    set_dir
+    port_index
+    port_clean $path
+    port_run $path
+}

Copied: branches/new-help-system/base/tests/test/site-tags/DESCRIPTION (from rev 117083, trunk/base/tests/test/site-tags/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/site-tags/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/site-tags/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks if MacPorts can fetch files from different URLs for the
+specified tags.
+
+There is 1 test case that looks for errors in the output file.

Deleted: branches/new-help-system/base/tests/test/site-tags/master
===================================================================
--- branches/new-help-system/base/tests/test/site-tags/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/site-tags/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,8 +0,0 @@
---->  Fetching distfiles for site-tags
---->  Attempting to fetch app-bm.tar.gz from http://www.douglas.stebila.ca/files/code/vim/app/
---->  Attempting to fetch doc.tar.gz from http://www.douglas.stebila.ca/files/code/vim/doc/
---->  Verifying checksums for site-tags
---->  Extracting site-tags
---->  Configuring site-tags
---->  Building site-tags
---->  Testing site-tags

Copied: branches/new-help-system/base/tests/test/site-tags/test.tcl (from rev 117083, trunk/base/tests/test/site-tags/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/site-tags/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/site-tags/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,32 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+proc sitetag {} {
+    global output_file path
+
+    initial_setup
+
+    set err "error*"
+    set line [get_line $output_file $err]
+    if {$line == -1} {
+        return "No errors found."
+    } else {
+        return "Errors found in the output file."
+    }
+}
+
+test site-tags {
+    Regression test for site-tags.
+} -body {
+    sitetag
+} -result "No errors found."
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/statefile-unknown-version/DESCRIPTION (from rev 117083, trunk/base/tests/test/statefile-unknown-version/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-unknown-version/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-unknown-version/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,5 @@
+This test checks that version 3 is not accepted. MacPorts keeps track 
+of the build process (and which steps have been completed) in a statefile.
+
+There are 2 test cases, one for the warnings and another that checks for the
+staging into destroot.

Deleted: branches/new-help-system/base/tests/test/statefile-unknown-version/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/statefile-unknown-version/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-unknown-version/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,15 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port configure >/dev/null 2>&1
-	@cp statefile work/.macports.statefile-unknown-version.state
-	@PORTSRC=$(PORTSRC) $(bindir)/port destroot >output 2>&1 || (cat output; exit 1)
-	@diff -u master output || (echo "statfile version 3 was accepted, although it shouldn't (this is a hacky test, which might also fail if you change the number of pahses)"; exit 1)
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean >/dev/null 2>&1
-	@rm output

Deleted: branches/new-help-system/base/tests/test/statefile-unknown-version/master
===================================================================
--- branches/new-help-system/base/tests/test/statefile-unknown-version/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-unknown-version/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,18 +0,0 @@
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
---->  Building statefile-unknown-version
-Warning: Unsupported statefile version '3'
-Warning: Please run 'port selfupdate' to update to the latest version of MacPorts
---->  Staging statefile-unknown-version into destroot

Copied: branches/new-help-system/base/tests/test/statefile-unknown-version/test.tcl (from rev 117083, trunk/base/tests/test/statefile-unknown-version/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-unknown-version/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-unknown-version/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,45 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+set path [file dirname [file normalize $argv0]]
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+port_config $path
+port_desroot $path
+port_clean $path
+
+proc state_unknown {warn} {
+    global path output_file
+
+    if {$warn ne "no"} {
+        set msg "warning*"
+    } else {
+        set msg "*staging*destroot*"
+    }
+
+    set line [get_line $path/$output_file $msg]
+    return $line
+}
+
+test warning_check {
+    Regression test for statefile-unknown warnings.
+} -body {
+    state_unknown yes
+} -result "warning: unsupported statefile version '3'"
+
+test output_check {
+    Regression test for statefile-unknown output.
+} -body {
+    state_unknown no
+} -result "--->  staging statefile-unknown-version into destroot"
+
+removeFile $work_dir
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/statefile-version1/DESCRIPTION (from rev 117083, trunk/base/tests/test/statefile-version1/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version1/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,5 @@
+This test checks that a non-outdated statefile version doesn't trigger a
+rebuild.
+
+There are 2 test cases, one that makes sure the statefile doesn't get
+discarded and another that looks for staging into destroot.

Deleted: branches/new-help-system/base/tests/test/statefile-version1/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version1/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,15 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port configure >/dev/null 2>&1
-	@cp statefile work/.macports.statefile-version1.state
-	@PORTSRC=$(PORTSRC) $(bindir)/port destroot >output 2>&1 || (cat output; exit 1)
-	@diff -u master output || (echo "statefile version 1 wasn't outdated but still triggered a rebuild"; exit 1)
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean >/dev/null 2>&1
-	@rm output

Deleted: branches/new-help-system/base/tests/test/statefile-version1/master
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version1/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,2 +0,0 @@
---->  Building statefile-version1
---->  Staging statefile-version1 into destroot

Copied: branches/new-help-system/base/tests/test/statefile-version1/test.tcl (from rev 117083, trunk/base/tests/test/statefile-version1/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version1/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,45 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+port_config $path
+port_desroot $path
+port_clean $path
+
+proc statefile_v1 {warn} {
+    global path output_file
+
+    if {$warn ne "no"} {
+        set msg "*discarding previous state*"
+    } else {
+        set msg "*staging*destroot*"
+    }
+    set line [get_line $path/$output_file $msg]
+    return $line
+}
+
+test warning_check {
+    Regression test for statefile-version1.
+} -body {
+    statefile_v1 yes
+} -result "-1"
+
+test output_check {
+    Regression test for statefile-version1.
+} -body {
+    statefile_v1 no
+} -result "--->  staging statefile-version1 into destroot"
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/statefile-version1-outdated/DESCRIPTION (from rev 117083, trunk/base/tests/test/statefile-version1-outdated/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1-outdated/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version1-outdated/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks that an outdated statefile will cause a fresh build.
+
+There are 2 test cases, one that ensures the statefile gets discarded and another
+that ensures staging into destroot.

Deleted: branches/new-help-system/base/tests/test/statefile-version1-outdated/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1-outdated/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version1-outdated/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,16 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port configure >/dev/null 2>&1
-	@cp statefile work/.macports.statefile-version1-outdated.state
-	@touch -t 197001010000.09 work/.macports.statefile-version1-outdated.state
-	@PORTSRC=$(PORTSRC) $(bindir)/port destroot >output 2>&1 || (cat output; exit 1)
-	@diff -u master output || (echo "statfile version 1 was outdated but didn't cause a fresh build"; exit 1)
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean >/dev/null 2>&1
-	@rm output

Deleted: branches/new-help-system/base/tests/test/statefile-version1-outdated/master
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1-outdated/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version1-outdated/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,7 +0,0 @@
-Portfile changed since last build; discarding previous state.
---->  Fetching distfiles for statefile-version1-outdated
---->  Verifying checksums for statefile-version1-outdated
---->  Extracting statefile-version1-outdated
---->  Configuring statefile-version1-outdated
---->  Building statefile-version1-outdated
---->  Staging statefile-version1-outdated into destroot

Copied: branches/new-help-system/base/tests/test/statefile-version1-outdated/test.tcl (from rev 117083, trunk/base/tests/test/statefile-version1-outdated/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version1-outdated/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version1-outdated/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,47 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+set path [file dirname [file normalize $argv0]]
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+port_config $path
+file copy -force $path/statefile $work_dir/.macports.statefile-version1-outdated.state
+exec touch -t 197001010000.09 $work_dir/.macports.statefile-version1-outdated.state
+port_desroot $path
+port_clean $path
+
+proc state_v1 {warn} {
+    global path output_file
+
+    if {$warn ne "no"} {
+        set msg "*discarding previous state*"
+    } else {
+        set msg "*staging*destroot*"
+    }
+
+    set line [get_line $path/$output_file $msg]
+    return $line
+}
+
+test warning_check {
+    Regression test for statefile-v1-outdated discard prev version.
+} -body {
+    state_v1 yes
+} -result "portfile changed since last build; discarding previous state."
+
+test output_check {
+    Regression test for statefile-v1-outdated output.
+} -body {
+    state_v1 no
+} -result "--->  staging statefile-version1-outdated into destroot"
+
+removeDirectory $work_dir
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/statefile-version2/DESCRIPTION (from rev 117083, trunk/base/tests/test/statefile-version2/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version2/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,5 @@
+This test checks that a non-outdated statefile version doesn't trigger a
+rebuild.
+
+There are 2 test cases, one that makes sure the statefile doesn't get
+discarded and another that looks for staging into destroot.

Deleted: branches/new-help-system/base/tests/test/statefile-version2/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version2/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,16 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port configure >/dev/null 2>&1
-	@cp statefile work/.macports.statefile-version2.state
-	@sed -i'' -E "s/@CHECKSUM@/`openssl dgst -sha256 Portfile | awk '{print $$2}'`/" work/.macports.statefile-version2.state
-	@PORTSRC=$(PORTSRC) $(bindir)/port destroot >output 2>&1 || (cat output; exit 1)
-	@diff -u master output || (echo "statefile version 2 wasn't outdated, but still triggered a rebuild"; exit 1)
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean >/dev/null 2>&1
-	@rm output

Deleted: branches/new-help-system/base/tests/test/statefile-version2/master
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version2/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,2 +0,0 @@
---->  Building statefile-version2
---->  Staging statefile-version2 into destroot

Copied: branches/new-help-system/base/tests/test/statefile-version2/test.tcl (from rev 117083, trunk/base/tests/test/statefile-version2/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version2/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,48 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+port_config $path
+file copy -force $path/statefile $work_dir/.macports.statefile-version2.state
+exec sed -i'' -E "s/@CHECKSUM@/`openssl dgst -sha256 Portfile | \
+    awk '{print \$\$2}'`/" $work_dir/.macports.statefile-version2.state
+port_desroot $path
+port_clean $path
+
+proc statefile_v2 {arg} {
+    global path output_file
+
+    if {$arg ne "no"} {
+        set msg "*discarding previous state*"
+    } else {
+        set msg "*staging*destroot*"
+    }
+    set line [get_line $path/$output_file $msg]
+    return $line
+}
+
+test statefile-v2-discard {
+    Regression test for statefile-version2 no discard.
+} -body {
+    statefile_v2 yes
+} -result "-1"
+
+test statefile-v2 {
+    Regression test for statefile-version2.
+} -body {
+    statefile_v2 no
+} -result "--->  staging statefile-version2 into destroot"
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/statefile-version2-invalid/DESCRIPTION (from rev 117083, trunk/base/tests/test/statefile-version2-invalid/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-invalid/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version2-invalid/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,5 @@
+This test checks that statefile version 2 without checksum field will cause a
+warning message. MacPorts should never deal with a broken statefile.
+
+There are 2 test cases, one that ensures a warning message gets thrown and
+another that ensures staging into destroot.

Deleted: branches/new-help-system/base/tests/test/statefile-version2-invalid/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-invalid/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version2-invalid/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,15 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port configure >/dev/null 2>&1
-	@cp statefile work/.macports.statefile-version2-invalid.state
-	@PORTSRC=$(PORTSRC) $(bindir)/port destroot >output 2>&1 || (cat output; exit 1)
-	@diff -u master output || (echo "statefile version 2 without checksum field didn't cause a warning"; exit 1)
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean >/dev/null 2>&1
-	@rm output

Deleted: branches/new-help-system/base/tests/test/statefile-version2-invalid/master
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-invalid/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version2-invalid/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,8 +0,0 @@
-Warning: Statefile has version 2 but didn't contain a checksum
-Portfile changed since last build; discarding previous state.
---->  Fetching distfiles for statefile-version2-invalid
---->  Verifying checksums for statefile-version2-invalid
---->  Extracting statefile-version2-invalid
---->  Configuring statefile-version2-invalid
---->  Building statefile-version2-invalid
---->  Staging statefile-version2-invalid into destroot

Copied: branches/new-help-system/base/tests/test/statefile-version2-invalid/test.tcl (from rev 117083, trunk/base/tests/test/statefile-version2-invalid/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-invalid/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version2-invalid/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,46 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+set path [file dirname [file normalize $argv0]]
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+port_config $path
+file copy -force $path/statefile $work_dir/.macports.statefile-version2-invalid.state
+port_desroot $path
+port_clean $path
+
+proc state_v2_invalid {warn} {
+    global path output_file
+
+    if {$warn ne "no"} {
+        set msg "*warning*checksum*"
+    } else {
+        set msg "*staging*destroot*"
+    }
+
+    set line [get_line $path/$output_file $msg]
+    return $line
+}
+
+test warning_check {
+    Regression test for statefile-v2-invalid discard prev version.
+} -body {
+    state_v2_invalid yes
+} -result "warning: statefile has version 2 but didn't contain a checksum"
+
+test output_check {
+    Regression test for statefile-v2-invalid output.
+} -body {
+    state_v2_invalid no
+} -result "--->  staging statefile-version2-invalid into destroot"
+
+removeDirectory $work_dir
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/statefile-version2-outdated/DESCRIPTION (from rev 117083, trunk/base/tests/test/statefile-version2-outdated/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-outdated/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version2-outdated/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks that an outdated statefile will cause a fresh build.
+
+There are 2 test cases, one that ensures the statefile gets discarded and another
+that ensures staging into destroot.

Deleted: branches/new-help-system/base/tests/test/statefile-version2-outdated/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-outdated/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version2-outdated/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,15 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port configure >/dev/null 2>&1
-	@cp statefile work/.macports.statefile-version2-outdated.state
-	@PORTSRC=$(PORTSRC) $(bindir)/port destroot >output 2>&1 || (cat output; exit 1)
-	@diff -u master output || (echo "statefile version 2 was outdated but didn't cause a fresh build"; exit 1)
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean >/dev/null 2>&1
-	@rm output

Deleted: branches/new-help-system/base/tests/test/statefile-version2-outdated/master
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-outdated/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/statefile-version2-outdated/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,7 +0,0 @@
-Portfile changed since last build; discarding previous state.
---->  Fetching distfiles for statefile-version2-outdated
---->  Verifying checksums for statefile-version2-outdated
---->  Extracting statefile-version2-outdated
---->  Configuring statefile-version2-outdated
---->  Building statefile-version2-outdated
---->  Staging statefile-version2-outdated into destroot

Copied: branches/new-help-system/base/tests/test/statefile-version2-outdated/test.tcl (from rev 117083, trunk/base/tests/test/statefile-version2-outdated/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/statefile-version2-outdated/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/statefile-version2-outdated/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,46 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+set path [file dirname [file normalize $argv0]]
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+port_config $path
+file copy -force $path/statefile $work_dir/.macports.statefile-version2-outdated.state
+port_desroot $path
+port_clean $path
+
+proc state_v2_out {warn} {
+    global path output_file
+
+    if {$warn ne "no" } {
+        set msg "*discarding previous state*"
+    } else {
+        set msg "*staging*destroot*"
+    }
+
+    set line [get_line $path/$output_file $msg]
+    return $line
+}
+
+test warning_check {
+    Regression test for statefile-v2-outdated discard prev version.
+} -body {
+    state_v2_out yes
+} -result "portfile changed since last build; discarding previous state."
+
+test output_check {
+    Regression test for statefile-v2-outdated output.
+} -body {
+    state_v2_out no
+} -result "--->  staging statefile-version2-outdated into destroot"
+
+removeDirectory $work_dir
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/svn-and-patchsites/DESCRIPTION (from rev 117083, trunk/base/tests/test/svn-and-patchsites/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/svn-and-patchsites/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/svn-and-patchsites/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks fetching using svn and downloading of patchfiles from
+the URL given by patch_sites.
+
+There is 1 test case which looks for errors in the output file.

Deleted: branches/new-help-system/base/tests/test/svn-and-patchsites/master
===================================================================
--- branches/new-help-system/base/tests/test/svn-and-patchsites/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/svn-and-patchsites/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,7 +0,0 @@
---->  Fetching distfiles for svn-and-patchsites
---->  Attempting to fetch patch-1.5.14.dgc.xlabel_ext.9 from http://home.uchicago.edu/~dgc/sw/mutt/
---->  Verifying checksums for svn-and-patchsites
---->  Extracting svn-and-patchsites
---->  Configuring svn-and-patchsites
---->  Building svn-and-patchsites
---->  Testing svn-and-patchsites

Copied: branches/new-help-system/base/tests/test/svn-and-patchsites/test.tcl (from rev 117083, trunk/base/tests/test/svn-and-patchsites/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/svn-and-patchsites/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/svn-and-patchsites/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,29 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+set path [file dirname [file normalize $argv0]]
+
+initial_setup
+
+proc svn-patch {} {
+    global output_file path
+
+    set svn "error*"
+    set line [get_line $path/$output_file $svn]
+    if {$line == -1} {
+        return "No error found."
+    } else {
+        return "Errors found in output file."
+    }
+}
+
+test svn-patchsites {
+    Regression test for svn-and-patchsites.
+} -body {
+    svn-patch
+} -result "No error found."
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/trace/DESCRIPTION (from rev 117083, trunk/base/tests/test/trace/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/trace/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/trace/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks the 'port -t' command which creates a virtual sandbox by a 
+mechanism known from Linux as library LD_PRELOADing.
+
+There is 1 test case, which looks for errors in the output file.

Copied: branches/new-help-system/base/tests/test/trace/test.tcl (from rev 117083, trunk/base/tests/test/trace/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/trace/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/trace/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,57 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+load_variables $path
+
+proc test_trace {} {
+    global path autoconf output_file
+
+    set line [get_line $autoconf "runusr*"]
+    set user [lrange [split $line " "] 1 1]
+
+    set_dir
+    port_index
+    port_clean $path
+
+
+    makeDirectory ../tracetesttmp
+    file attributes ../tracetesttmp -owner $user
+    exec sudo -u $user touch  ../tracetesttmp/delete-trace
+    exec sudo -u $user touch ../tracetesttmp/rename-trace
+    exec sudo -u $user mkdir ../tracetesttmp/rmdir-trace
+    file delete -force /tmp/hello-trace
+    file attributes /usr/include/unistd.h -owner $user
+    file link -symbolic /tmp/link-trace2 /usr/include/unistd.h
+    exec chown -h $user /tmp/link-trace2
+
+    port_trace $path
+    
+    #file delete -force /tmp/link-trace2
+    file delete -force /tmp/hello-trace
+
+    set err "error*"
+    set line [get_line $path/$output_file $err]
+    if { $line == -1 } {
+        return "No errors found."
+    } else {
+        return $line
+    }
+}
+
+test trace {
+    Regression test for trace.
+} -constraints {
+    root
+} -body {
+    test_trace
+} -result "No errors found."
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/universal/DESCRIPTION (from rev 117083, trunk/base/tests/test/universal/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/universal/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/universal/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,7 @@
+This test checks the handling of the universal variant in MacPorts base.
+Every port should have an universal variant unless 'universal_variant no' is
+specified.
+
+There are 2 test cases. One for universal variant set and another for no
+universal variant. For each test a specific Portfile is generated from the
+Port.in file.

Deleted: branches/new-help-system/base/tests/test/universal/Makefile
===================================================================
--- branches/new-help-system/base/tests/test/universal/Makefile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/universal/Makefile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,17 +0,0 @@
-include ../../../Mk/macports.autoconf.mk
-
-.PHONY: test
-
-$(bindir)/port:
-	@echo "Please install MacPorts before running this test"
-	@exit 1
-
-test:
-	@PORTSRC=$(PORTSRC) $(bindir)/port clean > /dev/null
-	@sh -c "export PORTSRC=$(PORTSRC); $(bindir)/port info --variants" > output 2>&1 || (cat output; exit 1)
-	@diff -u master output 2>&1 | tee difference
-	@if [ -s difference ]; then \
-		exit 1; \
-	else \
-		rm -f difference; \
-	fi

Deleted: branches/new-help-system/base/tests/test/universal/Portfile
===================================================================
--- branches/new-help-system/base/tests/test/universal/Portfile	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/universal/Portfile	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,23 +0,0 @@
-# $Id$
-
-PortSystem 1.0
-name		universal
-version		1
-categories	test
-maintainers	pguyot at kallisys.net
-description	Test port for universal variant
-homepage	http://www.macports.org/
-platforms	darwin
-
-long_description ${description}
-
-distfiles
-configure	{}
-build		{}
-destroot	{
-	system "touch ${destroot}${prefix}/lib/${name}"
-}
-
-test		{}
-
-default_variants +universal

Copied: branches/new-help-system/base/tests/test/universal/Portfile.in (from rev 117083, trunk/base/tests/test/universal/Portfile.in)
===================================================================
--- branches/new-help-system/base/tests/test/universal/Portfile.in	                        (rev 0)
+++ branches/new-help-system/base/tests/test/universal/Portfile.in	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,18 @@
+# $Id$
+PortSystem 1.0
+name            universal
+version         1
+categories      test
+maintainers     pguyot at kallisys.net
+description     Test port for universal variant
+homepage        http://www.macports.org/
+platforms       darwin
+long_description ${description}
+distfiles
+configure       {}
+build           {}
+destroot        {
+        system "touch ${destroot}${prefix}/lib/${name}"
+}
+test            {}
+ at option@

Deleted: branches/new-help-system/base/tests/test/universal/master
===================================================================
--- branches/new-help-system/base/tests/test/universal/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/universal/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1 +0,0 @@
-variants: universal

Copied: branches/new-help-system/base/tests/test/universal/test.tcl (from rev 117083, trunk/base/tests/test/universal/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/universal/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/universal/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,53 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+
+makeFile "" "Portfile"
+makeFile "" $output_file
+makeDirectory $work_dir
+set path [file dirname [file normalize $argv0]]
+
+# Initial setup
+load_variables $path
+set_dir
+port_index
+
+proc univ_test {opt} {
+    global output_file path portsrc bindir
+
+    # Modify Porfile.in for variants.
+    if {$opt ne "yes"} {
+        # No universal variant
+        exec sed "s/@option@/universal_variant\ no/" $path/Portfile.in > Portfile
+    } else {
+        # Add universal variant
+        exec sed "s/@option@/default_variants\ +universal/" $path/Portfile.in > Portfile
+    }
+    port_clean $path
+
+    # Build helping string
+    set string "export PORTSRC=${portsrc} ; ${bindir}/port info --variants"
+
+    exec sh -c $string > output 2>@1
+    set var "variants:*"
+    set line [get_line $path/$output_file $var]
+    return $line
+}
+
+
+test universal {
+    Regression test for universal variant.
+} -body {
+    univ_test "yes"
+} -result "variants: universal"
+
+test nouniversal {
+    Regression test for no universal variant.
+} -body {
+    univ_test "no"
+} -result "variants: "
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/variants/DESCRIPTION (from rev 117083, trunk/base/tests/test/variants/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/variants/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/variants/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,3 @@
+This test checks the variants feature in general.
+
+There is 1 test case.

Deleted: branches/new-help-system/base/tests/test/variants/master
===================================================================
--- branches/new-help-system/base/tests/test/variants/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/variants/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,8 +0,0 @@
-Utopia variant -- 2
-Utopia variant -- 2
---->  Fetching distfiles for variants
---->  Verifying checksums for variants
---->  Extracting variants
---->  Configuring variants
---->  Building variants
---->  Testing variants

Copied: branches/new-help-system/base/tests/test/variants/test.tcl (from rev 117083, trunk/base/tests/test/variants/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/variants/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/variants/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,26 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+set path [file dirname [file normalize $argv0]]
+
+initial_setup
+
+proc var_check {} {
+    global output_file path
+
+    set var "utopia variant*"
+    set line [get_line $path/$output_file $var]
+    return $line
+}
+
+
+test variants {
+    Regression test for variants.
+} -body {
+    var_check
+} -result "utopia variant -- 2"
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test/xcodeversion/DESCRIPTION (from rev 117083, trunk/base/tests/test/xcodeversion/DESCRIPTION)
===================================================================
--- branches/new-help-system/base/tests/test/xcodeversion/DESCRIPTION	                        (rev 0)
+++ branches/new-help-system/base/tests/test/xcodeversion/DESCRIPTION	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,4 @@
+This test checks the Xcode version. MacPorts needs at least Xcode 2.1.
+
+There are 2 test cases, one for the Xcode version and another to check the
+xcodebuild path.

Deleted: branches/new-help-system/base/tests/test/xcodeversion/master
===================================================================
--- branches/new-help-system/base/tests/test/xcodeversion/master	2014-02-15 12:19:10 UTC (rev 117083)
+++ branches/new-help-system/base/tests/test/xcodeversion/master	2014-02-15 14:35:04 UTC (rev 117084)
@@ -1,8 +0,0 @@
---->  Fetching distfiles for xcodeversion
---->  Verifying checksums for xcodeversion
---->  Extracting xcodeversion
---->  Configuring xcodeversion
---->  Building xcodeversion
---->  Testing xcodeversion
-xcodeversion >= 2.1
-xcodebuildcmd = /usr/bin/xcodebuild

Copied: branches/new-help-system/base/tests/test/xcodeversion/test.tcl (from rev 117083, trunk/base/tests/test/xcodeversion/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test/xcodeversion/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test/xcodeversion/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,39 @@
+package require tcltest 2
+namespace import tcltest::*
+
+source [file dirname $argv0]/../library.tcl
+set path [file dirname [file normalize $argv0]]
+
+initial_setup
+
+proc xcode_ver {} {
+    global output_file path
+
+    set xcode "xcodeversion*"
+    set line [get_line $path/$output_file $xcode]
+    return $line
+}
+
+proc xcode_binpath {} {
+    global output_file path
+
+    set xcode "xcodebuildcmd*"
+    set line [get_line $path/$output_file $xcode]
+    return $line
+}
+
+test envvariables {
+    Regression test for XCode version.
+} -body {
+    xcode_ver
+} -result "xcodeversion >= 2.1"
+
+test xcode_path {
+    Regression test for XCode path.
+} -body {
+    xcode_binpath
+} -result "xcodebuildcmd = /usr/bin/xcodebuild"
+
+
+cleanup
+cleanupTests

Copied: branches/new-help-system/base/tests/test.tcl (from rev 117083, trunk/base/tests/test.tcl)
===================================================================
--- branches/new-help-system/base/tests/test.tcl	                        (rev 0)
+++ branches/new-help-system/base/tests/test.tcl	2014-02-15 14:35:04 UTC (rev 117084)
@@ -0,0 +1,143 @@
+set test_suite {
+    case-insensitive-deactivate
+    checksums-1
+    dependencies-a
+    dependencies-b
+    dependencies-c
+    dependencies-d
+    dependencies-e
+    envvariables
+    site-tags
+    statefile-unknown-version
+    statefile-version1
+    statefile-version1-outdated
+    statefile-version2
+    statefile-version2-invalid
+    statefile-version2-outdated
+    svn-and-patchsites
+    trace
+    universal
+    variants
+    xcodeversion
+}
+set arguments ""
+set test_name ""
+set color_out ""
+set tcl ""
+set err ""
+
+# Get tclsh path.
+set autoconf ../Mk/macports.autoconf.mk
+set fp [open $autoconf r]
+while {[gets $fp line] != -1} {
+    if {[string match "TCLSH*" $line] != 0} {
+        set tcl [lrange [split $line " "] 1 1]
+    }
+}
+
+proc print_help {arg} {
+    if { $arg eq "tests" } {
+        puts "The list of available tests is:"
+        foreach test $::test_suite {
+            puts [puts -nonewline "  "]$test
+        }
+    } else {
+        puts "Usage: tclsh test.tcl \[-debug level\] \[-t test\] \[-l\]\n"
+        puts "  -debug LVL : sets the level of printed debug info \[0-3\]"
+        puts "  -t TEST    : run a specific test"
+        puts "  -nocolor   : disable color output (for automatic testing)"
+        puts "  -l         : print the list of available tests"
+        puts "  -h, -help  : print this message\n"
+    }
+}
+
+# Process args
+foreach arg $argv {
+    if { $arg eq "-h" || $arg eq "-help" } {
+        print_help ""
+        exit 0
+    } elseif { $arg eq "-debug" } {
+        set index [expr {[lsearch $argv $arg] + 1}]
+        set level [lindex $argv $index]
+        if { $level >= 0 && $level <= 3 } {
+            append arguments "-debug " $level
+        } else {
+            puts "Invalid debug level."
+            exit 1
+        }
+    } elseif { $arg eq "-t" } {
+        set index [expr {[lsearch $argv $arg] + 1}]
+        set test_name [lindex $argv $index]
+        set no 0
+        foreach test $test_suite {
+            if { $test_name != $test } {
+                set no [expr {$no + 1}]
+            }
+        }
+        if { $no == [llength $test_suite] } {
+            print_help tests
+            exit 1
+        }
+    } elseif { $arg eq "-l" } {
+        print_help tests
+        exit 0
+    } elseif { $arg eq "-nocolor" } {
+        set color_out "no"
+    }
+}
+
+
+# Run tests
+if {$test_name ne ""} {
+    cd test/$test_name
+
+    set result [eval exec $tcl test.tcl $arguments 2>@stderr]
+    puts $result
+
+} else {
+    foreach test $test_suite {
+        cd test/$test
+    
+        set result [eval exec $tcl test.tcl $arguments 2>@stderr]
+        set lastline [lindex [split $result "\n"] end]
+
+        if {[lrange [split $lastline "\t"] 1 1] != "Total"} {
+            set lastline [lindex [split $result "\n"] end-2]
+            set errmsg [lindex [split $result "\n"] end]
+        }
+
+        set splitresult [split $lastline "\t"]
+        set total [lindex $splitresult 2]
+        set pass [lindex $splitresult 4]
+        set skip [lindex $splitresult 6]
+        set fail [lindex $splitresult 8]
+
+        # Check for errors.
+        if { $fail != 0 } { set err "yes" }
+
+        set out ""
+        if { ($fail != 0 || $skip != 0) && $color_out eq "" } {
+            # Color failed tests.
+            append out "\x1b\[1;31mTotal:" $total " Passed:" $pass " Failed:" $fail " Skipped:" $skip "  \x1b\[0m" $test
+        } else {
+            append out "Total:" $total " Passed:" $pass " Failed:" $fail " Skipped:" $skip "  " $test
+        }
+
+        # Print results and constrints for auto-skipped tests.
+        puts $out
+        if { $skip != 0 } {
+            set out "    Constraint: "
+            append out [string trim $errmsg "\t {}"]
+            puts $out
+        }
+    
+        cd ../..
+    }
+}
+
+# Return 1 if errors were found.
+if {$err ne ""} {
+    exit 1
+}
+
+return 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140215/89dab61a/attachment-0001.html>


More information about the macports-changes mailing list