[Pkg-virtualbox-commits] [kbuild] 01/05: Imported Upstream version 0.1.9998svn2733+dfsg

Gianfranco Costamagna locutusofborg-guest at moszumanska.debian.org
Wed Oct 22 16:04:31 UTC 2014


This is an automated email from the git hooks/post-receive script.

locutusofborg-guest pushed a commit to branch master
in repository kbuild.

commit 38898bd0fa478197564066037fcc87f1020da3a7
Author: Gianfranco Costamagna <costamagnagianfranco at yahoo.it>
Date:   Wed Oct 22 17:16:55 2014 +0200

    Imported Upstream version 0.1.9998svn2733+dfsg
---
 Config.kmk                                |   19 +-
 VSlickMacros/kdev.e                       |   26 +-
 kBuild/doc/QuickReference-kmk.html        |    2 +-
 kBuild/footer-inherit-uses-tools.kmk      |    4 +-
 kBuild/footer-misc.kmk                    |    4 +-
 kBuild/footer-pass1.kmk                   |    4 +-
 kBuild/footer-pass2-compiling-targets.kmk |    4 +-
 kBuild/footer-pass2-fetches.kmk           |    4 +-
 kBuild/footer-pass2-installs.kmk          |    4 +-
 kBuild/footer-pass2-patches.kmk           |    4 +-
 kBuild/footer-passes.kmk                  |    4 +-
 kBuild/footer.kmk                         |    4 +-
 kBuild/header.kmk                         |   57 +-
 kBuild/rules.kmk                          |    4 +-
 kBuild/subfooter.kmk                      |    4 +-
 kBuild/subheader.kmk                      |    4 +-
 kBuild/tools/ALP.kmk                      |    6 +-
 kBuild/tools/JWASM.kmk                    |    8 +-
 kBuild/tools/MASM510.kmk                  |   22 +-
 kBuild/tools/MASM600.kmk                  |   10 +-
 kBuild/tools/MASM610.kmk                  |    8 +-
 kBuild/tools/MASM6PLUS.kmk                |   10 +-
 kBuild/tools/MASM710.kmk                  |   10 +-
 kBuild/tools/MINGW32.kmk                  |   10 +-
 kBuild/tools/MINGWW64.kmk                 |   10 +-
 kBuild/tools/MSLINK510.kmk                |   18 +-
 kBuild/tools/NASM.kmk                     |    6 +-
 kBuild/tools/OPENWATCOM-16.kmk            |    8 +-
 kBuild/tools/OPENWATCOM.kmk               |   42 +-
 kBuild/tools/TAR.kmk                      |    8 +-
 kBuild/tools/VAC308.kmk                   |   12 +-
 kBuild/tools/VCC100.kmk                   |   12 +-
 kBuild/tools/VCC100AMD64.kmk              |   10 +-
 kBuild/tools/VCC100X86.kmk                |   12 +-
 kBuild/tools/VCC70.kmk                    |   10 +-
 kBuild/tools/VCC80.kmk                    |   12 +-
 kBuild/tools/VCC80AMD64.kmk               |   10 +-
 kBuild/tools/VCC80X86.kmk                 |   12 +-
 kBuild/tools/WATCOMC11C-16.kmk            |    8 +-
 kBuild/tools/WATCOMC11C.kmk               |   22 +-
 kBuild/tools/WGET.kmk                     |    8 +-
 kBuild/tools/XGCCAMD64LINUX.kmk           |   10 +-
 kBuild/tools/YASM.kmk                     |    6 +-
 kBuild/tools/ZIP.kmk                      |   16 +-
 kBuild/units/dtrace.kmk                   |    4 +-
 kBuild/units/lex.kmk                      |    4 +-
 kBuild/units/qt3.kmk                      |    4 +-
 kBuild/units/qt4.kmk                      |    4 +-
 kBuild/units/yacc.kmk                     |    4 +-
 kBuild/up.kmk                             |    4 +-
 src/ash/Makefile                          |   79 --
 src/ash/Makefile.kmk                      |  192 ---
 src/ash/TOUR                              |  357 ------
 src/ash/alias.c                           |  275 ----
 src/ash/alias.h                           |   50 -
 src/ash/arith.y                           |  202 ---
 src/ash/arith_lex.l                       |  105 --
 src/ash/bltin/bltin.h                     |   94 --
 src/ash/bltin/echo.1                      |  109 --
 src/ash/bltin/echo.c                      |  116 --
 src/ash/bltin/kill.c                      |  266 ----
 src/ash/bltin/printf.c                    |  664 ----------
 src/ash/bltin/test.c                      |  509 --------
 src/ash/builtins.def                      |   92 --
 src/ash/cd.c                              |  448 -------
 src/ash/cd.h                              |   43 -
 src/ash/error.c                           |  370 ------
 src/ash/error.h                           |  117 --
 src/ash/eval.c                            | 1285 -------------------
 src/ash/eval.h                            |   64 -
 src/ash/exec.c                            | 1199 ------------------
 src/ash/exec.h                            |   79 --
 src/ash/expand.c                          | 1569 -----------------------
 src/ash/expand.h                          |   72 --
 src/ash/funcs/cmv                         |   50 -
 src/ash/funcs/dirs                        |   74 --
 src/ash/funcs/kill                        |   50 -
 src/ash/funcs/login                       |   39 -
 src/ash/funcs/newgrp                      |   38 -
 src/ash/funcs/popd                        |   74 --
 src/ash/funcs/pushd                       |   74 --
 src/ash/funcs/suspend                     |   42 -
 src/ash/generated/arith.c                 |  666 ----------
 src/ash/generated/arith.h                 |   25 -
 src/ash/generated/arith_lex.c             | 1724 -------------------------
 src/ash/generated/builtins.c              |   63 -
 src/ash/generated/builtins.h              |   57 -
 src/ash/generated/init.c                  |  314 -----
 src/ash/generated/nodes.c                 |  347 -----
 src/ash/generated/nodes.h                 |  159 ---
 src/ash/generated/token.h                 |  112 --
 src/ash/histedit.c                        |  550 --------
 src/ash/init.h                            |   39 -
 src/ash/input.c                           |  536 --------
 src/ash/input.h                           |   62 -
 src/ash/jobs.c                            | 1484 ----------------------
 src/ash/jobs.h                            |  106 --
 src/ash/machdep.h                         |   47 -
 src/ash/mail.c                            |  122 --
 src/ash/mail.h                            |   37 -
 src/ash/main.c                            |  441 -------
 src/ash/main.h                            |   43 -
 src/ash/memalloc.c                        |  309 -----
 src/ash/memalloc.h                        |   77 --
 src/ash/miscbltin.c                       |  461 -------
 src/ash/miscbltin.h                       |   31 -
 src/ash/mkbuiltins                        |  138 --
 src/ash/mkinit.sh                         |  197 ---
 src/ash/mknodes.sh                        |  217 ----
 src/ash/mktokens                          |   98 --
 src/ash/myhistedit.h                      |   49 -
 src/ash/mystring.c                        |  135 --
 src/ash/mystring.h                        |   45 -
 src/ash/nodes.c.pat                       |  166 ---
 src/ash/nodetypes                         |  143 ---
 src/ash/options.c                         |  533 --------
 src/ash/options.h                         |  133 --
 src/ash/output.c                          |  518 --------
 src/ash/output.h                          |   81 --
 src/ash/parser.c                          | 1656 ------------------------
 src/ash/parser.h                          |   82 --
 src/ash/redir.c                           |  390 ------
 src/ash/redir.h                           |   48 -
 src/ash/setmode.c                         |  501 --------
 src/ash/sh.1                              | 1949 -----------------------------
 src/ash/shell.h                           |   85 --
 src/ash/show.c                            |  456 -------
 src/ash/show.h                            |   45 -
 src/ash/strlcpy.c                         |   70 --
 src/ash/syntax.c                          |  206 ---
 src/ash/syntax.h                          |   93 --
 src/ash/sys_signame.c                     |  121 --
 src/ash/trap.c                            |  468 -------
 src/ash/trap.h                            |   46 -
 src/ash/var.c                             |  933 --------------
 src/ash/var.h                             |  143 ---
 src/ash/win/dirent.c                      |  206 ---
 src/ash/win/err.c                         |   85 --
 src/ash/win/err.h                         |   35 -
 src/ash/win/getopt.h                      |  133 --
 src/ash/win/mscfakes.c                    |  340 -----
 src/ash/win/mscfakes.h                    |  203 ---
 src/ash/win/paths.h                       |    2 -
 src/ash/win/pwd.h                         |   23 -
 src/ash/win/strings.h                     |    4 -
 src/ash/win/sys/cdefs.h                   |    9 -
 src/ash/win/sys/fcntl.h                   |    1 -
 src/ash/win/sys/ioctl.h                   |    1 -
 src/ash/win/sys/param.h                   |    2 -
 src/ash/win/sys/resource.h                |  143 ---
 src/ash/win/sys/time.h                    |    1 -
 src/ash/win/sys/times.h                   |   15 -
 src/ash/win/sys/wait.h                    |   25 -
 src/ash/win/termios.h                     |    1 -
 src/ash/win/unistd.h                      |    9 -
 src/kmk/Makefile.am                       |    2 +-
 src/kmk/Makefile.kmk                      |    5 +-
 src/kmk/config.h.win                      |   21 +-
 src/kmk/dir.c                             |   53 +-
 src/kmk/function.c                        |   53 +-
 src/kmk/glob/glob.c                       |   25 +-
 src/kmk/glob/glob.h                       |    4 +
 src/kmk/kbuild-object.c                   | 1407 +++++++++++++++++++++
 src/kmk/kbuild-read.c                     |  511 --------
 src/kmk/kbuild.h                          |   42 +-
 src/kmk/kmkbuiltin/cp.c                   |    2 +-
 src/kmk/kmkbuiltin/fts.c                  |   96 +-
 src/kmk/kmkbuiltin/mscfakes.c             |   92 +-
 src/kmk/kmkbuiltin/mscfakes.h             |   45 +-
 src/kmk/kmkbuiltin/redirect.c             |   48 +-
 src/kmk/kmkbuiltin/rm.c                   |   48 +-
 src/kmk/main.c                            |    5 +-
 src/kmk/read.c                            |   29 +-
 src/kmk/testcase-kBuild-define.kmk        |  115 +-
 src/kmk/variable.c                        |  332 ++++-
 src/kmk/variable.h                        |   17 +
 src/kmk/w32/include/dirent.h              |    7 +
 src/lib/Makefile.kmk                      |   21 +-
 src/lib/nt/Makefile.kup                   |    0
 src/lib/nt/ntdir.c                        |  364 ++++++
 src/lib/nt/ntdir.h                        |  115 ++
 src/lib/nt/nthlp.h                        |   70 ++
 src/lib/nt/nthlpcore.c                    |  450 +++++++
 src/lib/nt/nthlpfs.c                      |  306 +++++
 src/lib/nt/ntstat.c                       |  613 +++++++++
 src/lib/nt/ntstat.h                       |  130 ++
 src/lib/nt/ntstuff.h                      |  385 ++++++
 src/lib/nt/nttypes.h                      |   49 +
 src/lib/nt/ntunlink.c                     |  171 +++
 src/lib/nt/ntunlink.h                     |   44 +
 src/lib/nt/tstNtStat.c                    |  156 +++
 src/sed/lib/getline.c                     |    2 +
 src/sed/lib/regex_internal.c              |    2 +-
 193 files changed, 5383 insertions(+), 28558 deletions(-)

diff --git a/Config.kmk b/Config.kmk
index 23b75cc..8da05f6 100644
--- a/Config.kmk
+++ b/Config.kmk
@@ -1,4 +1,4 @@
-# $Id: Config.kmk 2668 2012-11-25 19:53:45Z bird $
+# $Id: Config.kmk 2722 2014-02-19 15:28:22Z bird $
 ## @file
 # Build Configuration.
 #
@@ -59,7 +59,7 @@ $(PATH_OBJ)/SvnInfo.ts +| $(KBUILD_SVN_INFO_KMK): $(wildcard $(PATH_ROOT)/.svn $
 	@$(MKDIR) -p $(@D)
 	@$(REDIRECT) -o $@.tmp -E 'LC_ALL=C' -- svn info $(DEPTH)
 	@$(SED) \
-		-e 's/URL: */KBUILD_SVN_URL := /' \
+		-e 's/^URL: */KBUILD_SVN_URL := /' \
 		-e 's/Revision: */KBUILD_SVN_REV := /' \
 		-e '/KBUILD_SVN_/!d' \
 		--append $@ \
@@ -91,6 +91,14 @@ include $(KBUILD_SVN_INFO_KMK)
 
 
 #
+# Local config, optional.
+#
+ifneq ($(wildcard $(PATH_ROOT)/LocalConfig.kmk),)
+ include $(PATH_ROOT)/LocalConfig.kmk
+endif
+
+
+#
 # Where to fine the GNU Make stuff (for FreeBSD and Windows).
 #
 PATH_GNUMAKE_SRC ?= $(PATH_ROOT)/src/kmk
@@ -229,7 +237,12 @@ ifeq ($(KBUILD_TARGET),darwin)
   TOOL_GCC4MACHO_SUFFIX	        = -4.2
   TOOL_GXX4MACHO_SUFFIX		= -4.2
  endif
- KBUILD_MACOSX_SDK             ?= /Developer/SDKs/MacOSX10.$(KBUILD_MACOSX_TARGET_VERSION)$(if-expr $(KBUILD_MACOSX_TARGET_VERSION)==4,u,).sdk
+ ifndef KBUILD_MACOSX_SDK
+  KBUILD_MACOSX_SDK            := /Developer/SDKs/MacOSX10.$(KBUILD_MACOSX_TARGET_VERSION)$(if-expr $(KBUILD_MACOSX_TARGET_VERSION)==4,u,).sdk
+  ifeq ($(wildcard $(KBUILD_MACOSX_SDK)),)
+   KBUILD_MACOSX_SDK           := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform$(KBUILD_MACOSX_SDK)
+  endif
+ endif
  TEMPLATE_BIN_TOOL              = GCC4MACHO
  TEMPLATE_BIN_CFLAGS            = -g -mmacosx-version-min=10.$(KBUILD_MACOSX_TARGET_VERSION) -isysroot $(KBUILD_MACOSX_SDK)
  ifeq ($(USER),bird)
diff --git a/VSlickMacros/kdev.e b/VSlickMacros/kdev.e
index bfb805a..e1247a0 100644
--- a/VSlickMacros/kdev.e
+++ b/VSlickMacros/kdev.e
@@ -1,4 +1,4 @@
-/* $Id: kdev.e 2685 2013-07-04 19:50:01Z bird $  -*- tab-width: 4 c-indent-level: 4 -*- */
+/* $Id: kdev.e 2701 2013-11-06 19:58:56Z bird $  -*- tab-width: 4 c-indent-level: 4 -*- */
 /** @file
  * Visual SlickEdit Documentation Macros.
  */
@@ -90,6 +90,10 @@ def  'C-S-L' = k_style_load
 /*#else: Version 4.0 (OS/2) */
 #endif
 
+#ifndef __MACOSX__
+ #define KDEV_WITH_MENU
+#endif
+
 /* Remeber to change these! */
 static _str skUserInitials  = "bird";
 static _str skUserName      = "knut st. osmundsen";
@@ -2984,7 +2988,10 @@ _command int k_calc()
 /*******************************************************************************
 *   Menu and Menu commands                                                     *
 *******************************************************************************/
+#ifdef KDEV_WITH_MENU
+#if __VERSION__ < 18.0 /* Something with timers are busted, so excusing my code. */
 static int  iTimer = 0;
+#endif
 static int  mhkDev = 0;
 static int  mhCode = 0;
 static int  mhDoc = 0;
@@ -2996,8 +3003,10 @@ static int  mhPre = 0;
  */
 static k_menu_create()
 {
+# if __VERSION__ < 18.0 /* Something with timers are busted, so excusing my code. */
     if (arg(1) == 'timer')
         _kill_timer(iTimer);
+# endif
     menu_handle = _mdi.p_menu_handle;
     menu_index  = find_index(_cur_mdi_menu,oi2type(OI_MENU));
 
@@ -3259,6 +3268,9 @@ _command k_menu_settings()
 */
 
 
+#endif /* KDEV_WITH_MENU */
+
+
 /*******************************************************************************
 *   Dialogs                                                                    *
 *******************************************************************************/
@@ -3579,8 +3591,14 @@ _command void kdev_load_settings()
             }
             idxExt = name_match('def-lang-for-ext-', 0, MISC_TYPE);
         }
-        replace_def_data('def-encoding-' :+ sLangId, '+futf8 ');
+        //replace_def_data('def-encoding-' :+ sLangId, '+futf8 ');
+        idxLangEncoding = find_index('def-encoding-' :+ sLangId, MISC_TYPE);
+        if (idxLangEncoding != 0)
+            delete_name(idxLangEncoding);
+
     }
+    replace_def_data('def-encoding', '+futf8 ');
+
     LanguageSettings.setIndentWithTabs('mak', true);
     LanguageSettings.setLexerName('mak', 'kmk');
     LanguageSettings.setSyntaxIndent('mak', 8);
@@ -3659,8 +3677,12 @@ definit()
 
     /* do init */
     k_styles_create();
+#ifdef KDEV_WITH_MENU
     k_menu_create();
+# if __VERSION__ < 18.0 /* Something with timers are busted, so excusing my code. */
     iTimer = _set_timer(1000, k_menu_create, "timer");
+# endif
     /* createMyColorSchemeAndUseIt();*/
+#endif
 }
 
diff --git a/kBuild/doc/QuickReference-kmk.html b/kBuild/doc/QuickReference-kmk.html
index b6241b5..e7529a6 100644
--- a/kBuild/doc/QuickReference-kmk.html
+++ b/kBuild/doc/QuickReference-kmk.html
@@ -10,7 +10,7 @@
 /*
 :Author: David Goodger
 :Contact: goodger at users.sourceforge.net
-:Date: $Date: 2009-04-18 08:05:47 -0400 (Sat, 18 Apr 2009) $
+:Date: $Date: 2009-04-18 14:05:47 +0200 (sab, 18 apr 2009) $
 :Revision: $Revision: 2340 $
 :Copyright: This stylesheet has been placed in the public domain.
 
diff --git a/kBuild/footer-inherit-uses-tools.kmk b/kBuild/footer-inherit-uses-tools.kmk
index 55b7056..9bc5ad5 100644
--- a/kBuild/footer-inherit-uses-tools.kmk
+++ b/kBuild/footer-inherit-uses-tools.kmk
@@ -1,10 +1,10 @@
-# $Id: footer-inherit-uses-tools.kmk 2521 2011-07-26 18:18:19Z bird $
+# $Id: footer-inherit-uses-tools.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 2 - Template & Target Inheritance, Uses and Tools.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer-misc.kmk b/kBuild/footer-misc.kmk
index 8dda2a5..7e4cda3 100644
--- a/kBuild/footer-misc.kmk
+++ b/kBuild/footer-misc.kmk
@@ -1,10 +1,10 @@
-# $Id: footer-misc.kmk 2523 2011-07-31 23:45:20Z bird $
+# $Id: footer-misc.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 2 - Misc.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer-pass1.kmk b/kBuild/footer-pass1.kmk
index 34144e9..d77c59e 100644
--- a/kBuild/footer-pass1.kmk
+++ b/kBuild/footer-pass1.kmk
@@ -1,4 +1,4 @@
-# $Id: footer-pass1.kmk 2551 2011-11-09 13:28:02Z bird $
+# $Id: footer-pass1.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 1.
 #
@@ -7,7 +7,7 @@
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer-pass2-compiling-targets.kmk b/kBuild/footer-pass2-compiling-targets.kmk
index 9796a9e..98f2866 100644
--- a/kBuild/footer-pass2-compiling-targets.kmk
+++ b/kBuild/footer-pass2-compiling-targets.kmk
@@ -1,10 +1,10 @@
-# $Id: footer-pass2-compiling-targets.kmk 2551 2011-11-09 13:28:02Z bird $
+# $Id: footer-pass2-compiling-targets.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 2 - Compiling Targets.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer-pass2-fetches.kmk b/kBuild/footer-pass2-fetches.kmk
index fda024b..dcd19e8 100644
--- a/kBuild/footer-pass2-fetches.kmk
+++ b/kBuild/footer-pass2-fetches.kmk
@@ -1,10 +1,10 @@
-# $Id: footer-pass2-fetches.kmk 2521 2011-07-26 18:18:19Z bird $
+# $Id: footer-pass2-fetches.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 2 - Fetches.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer-pass2-installs.kmk b/kBuild/footer-pass2-installs.kmk
index b8d67c4..f6a31b4 100644
--- a/kBuild/footer-pass2-installs.kmk
+++ b/kBuild/footer-pass2-installs.kmk
@@ -1,10 +1,10 @@
-# $Id: footer-pass2-installs.kmk 2537 2011-08-02 19:44:43Z bird $
+# $Id: footer-pass2-installs.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 2 - Installs.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer-pass2-patches.kmk b/kBuild/footer-pass2-patches.kmk
index 7c20527..af98751 100644
--- a/kBuild/footer-pass2-patches.kmk
+++ b/kBuild/footer-pass2-patches.kmk
@@ -1,10 +1,10 @@
-# $Id: footer-pass2-patches.kmk 2521 2011-07-26 18:18:19Z bird $
+# $Id: footer-pass2-patches.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 2 - Patches.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer-passes.kmk b/kBuild/footer-passes.kmk
index 935d3f3..fe2dbf1 100644
--- a/kBuild/footer-passes.kmk
+++ b/kBuild/footer-passes.kmk
@@ -1,10 +1,10 @@
-# $Id: footer-passes.kmk 2521 2011-07-26 18:18:19Z bird $
+# $Id: footer-passes.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - Footer - Target lists - Pass 2 - Passes.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/footer.kmk b/kBuild/footer.kmk
index a632144..ca732ad 100644
--- a/kBuild/footer.kmk
+++ b/kBuild/footer.kmk
@@ -1,10 +1,10 @@
-# $Id: footer.kmk 2537 2011-08-02 19:44:43Z bird $
+# $Id: footer.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - File included at bottom of a makefile.
 #
 
 #
-# Copyright (c) 2004-2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/header.kmk b/kBuild/header.kmk
index 852c1a6..d2774f1 100644
--- a/kBuild/header.kmk
+++ b/kBuild/header.kmk
@@ -1,10 +1,10 @@
-# $Id: header.kmk 2689 2013-07-11 21:31:43Z bird $
+# $Id: header.kmk 2729 2014-03-16 00:21:49Z bird $
 ## @file
 # kBuild - File included at top of a makefile.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -79,7 +79,7 @@ endif
 # The revision in which this file was last modified.
 # This can be useful when using development versions of kBuild.
 #
-KMK_REVISION := $(patsubst %:,,  $Rev: 2689 $  )
+KMK_REVISION := $(patsubst %:,,  $Rev: 2729 $  )
 
 
 #
@@ -471,42 +471,54 @@ PATH_SYS = $(error kBuild: PATH_SYS is obsoleted in kBuild 0.1.2. Use PATH_STAGE
 PATH_DOC = $(error kBuild: PATH_DOC is obsoleted in kBuild 0.1.2. Use PATH_STAGE_DOC or PATH_INST_DOC instead)
 
 # Development tool tree.
-KBUILD_DEVTOOLS      = $(if $(PATH_DEVTOOLS),$(PATH_DEVTOOLS),$(PATH_ROOT)/tools)
-KBUILD_DEVTOOLS_TRG  = $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)
-KBUILD_DEVTOOLS_HST  = $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)
+ifndef KBUILD_DEVTOOLS
+ ifeq ($(PATH_DEVTOOLS),)
+  KBUILD_DEVTOOLS    = $(PATH_ROOT)/tools
+ else  
+  KBUILD_DEVTOOLS   := $(PATH_DEVTOOLS)
+ endif 
+endif 
+KBUILD_DEVTOOLS_TRG ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)
+KBUILD_DEVTOOLS_HST ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).$(KBUILD_HOST_ARCH)
 
 if1of ($(KBUILD_TARGET_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
  ifeq ($(KBUILD_TARGET_ARCH),amd64)
-  KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).x86
+  KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).x86
  else ifeq ($(KBUILD_TARGET_ARCH),hppa64)
-  KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).hppa32
+  KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).hppa32
  else ifeq ($(KBUILD_TARGET_ARCH),mips64)
-  KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).mips32
+  KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).mips32
  else ifeq ($(KBUILD_TARGET_ARCH),ppc64)
-  KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).ppc32
+  KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).ppc32
  else ifeq ($(KBUILD_TARGET_ARCH),s390x)
-  KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).s390
+  KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).s390
  else ifeq ($(KBUILD_TARGET_ARCH),sparc64)
-  KBUILD_DEVTOOLS_TRG_ALT = $(PATH_DEVTOOLS)/$(KBUILD_TARGET).sparc32
+  KBUILD_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_TARGET).sparc32
  endif
 endif
 
 if1of ($(KBUILD_HOST_ARCH), amd64 hppa64 mips64 ppc64 s390x sparc64)
  ifeq ($(KBUILD_HOST_ARCH),amd64)
-  KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).x86
+  KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).x86
  else ifeq ($(KBUILD_HOST_ARCH),hppa64)
-  KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).hppa32
+  KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).hppa32
  else ifeq ($(KBUILD_HOST_ARCH),mips64)
-  KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).mips32
+  KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).mips32
  else ifeq ($(KBUILD_HOST_ARCH),ppc64)
-  KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).ppc32
+  KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).ppc32
  else ifeq ($(KBUILD_HOST_ARCH),s390x)
-  KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).s390
+  KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).s390
  else ifeq ($(KBUILD_HOST_ARCH),sparc64)
-  KBUILD_DEVTOOLS_HST_ALT = $(PATH_DEVTOOLS)/$(KBUILD_HOST).sparc32
+  KBUILD_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS)/$(KBUILD_HOST).sparc32
  endif
 endif
 
+# Deprecated legacy names.
+PATH_DEVTOOLS         ?= $(KBUILD_DEVTOOLS)
+PATH_DEVTOOLS_TRG     ?= $(KBUILD_DEVTOOLS_TRG)
+PATH_DEVTOOLS_TRG_ALT ?= $(KBUILD_DEVTOOLS_TRG_ALT)
+PATH_DEVTOOLS_HST     ?= $(KBUILD_DEVTOOLS_HST)
+PATH_DEVTOOLS_HST_ALT ?= $(KBUILD_DEVTOOLS_HST_ALT)
 
 # KBUILD_PATH / PATH_KBUILD is determined by kmk.
 ifndef KBUILD_PATH
@@ -1399,6 +1411,14 @@ PATH_$(y)_$(x) := $(val)
 endef
 $(foreach y, INST STAGE, $(foreach x, $(KBUILD_INST_PATHS), $(evalcall def_kbuild_finalize_inst)))
 
+# No abspath for devtools since they might've been referenced already and we
+# don't want conflicting variable expansions.
+KBUILD_DEVTOOLS         := $(KBUILD_DEVTOOLS)
+KBUILD_DEVTOOLS_TRG     := $(KBUILD_DEVTOOLS_TRG)
+KBUILD_DEVTOOLS_TRG_ALT := $(KBUILD_DEVTOOLS_TRG_ALT)
+KBUILD_DEVTOOLS_HST     := $(KBUILD_DEVTOOLS_HST)
+KBUILD_DEVTOOLS_HST_ALT := $(KBUILD_DEVTOOLS_HST_ALT)
+
 
 #
 # Setup the message style. The default one is inlined.
@@ -1571,4 +1591,3 @@ endif
 __header_kmk__ := 1
 endif # !__header_kmk__
 
-
diff --git a/kBuild/rules.kmk b/kBuild/rules.kmk
index 6d5ecf6..e07f733 100644
--- a/kBuild/rules.kmk
+++ b/kBuild/rules.kmk
@@ -1,10 +1,10 @@
-# $Id: rules.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: rules.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - File included at top of makefile.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/subfooter.kmk b/kBuild/subfooter.kmk
index ad7abd1..c87dfd0 100644
--- a/kBuild/subfooter.kmk
+++ b/kBuild/subfooter.kmk
@@ -1,10 +1,10 @@
-# $Id: subfooter.kmk 2443 2011-07-06 12:19:50Z bird $
+# $Id: subfooter.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - File included at bottom of a makefile or sub-makefile.
 #
 
 #
-# Copyright (c) 2006-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2006-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/subheader.kmk b/kBuild/subheader.kmk
index 8131aa6..830e3ce 100644
--- a/kBuild/subheader.kmk
+++ b/kBuild/subheader.kmk
@@ -1,10 +1,10 @@
-# $Id: subheader.kmk 2434 2011-01-09 17:45:08Z bird $
+# $Id: subheader.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - File included at top of a makefile or sub-makefile.
 #
 
 #
-# Copyright (c) 2006-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2006-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/tools/ALP.kmk b/kBuild/tools/ALP.kmk
index b9f1cbe..82971cd 100644
--- a/kBuild/tools/ALP.kmk
+++ b/kBuild/tools/ALP.kmk
@@ -1,10 +1,10 @@
-# $Id: ALP.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: ALP.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - ALP or later.
 #
 
 #
-# Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2005-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,7 +35,7 @@ TOOL_ALP := The IBM Assembly Language Processor
 
 # Tool Specific Properties
 ifndef PATH_TOOL_ALP
- PATH_TOOL_ALP := $(sort $(wildcard $(PATH_DEVTOOLS_BLD)/alp/v*.*))
+ PATH_TOOL_ALP := $(sort $(wildcard $(KBUILD_DEVTOOLS_BLD)/alp/v*.*))
  ifneq ($(PATH_TOOL_ALP),)
   PATH_TOOL_ALP := $(call lastword,$(PATH_TOOL_ALP))
  endif
diff --git a/kBuild/tools/JWASM.kmk b/kBuild/tools/JWASM.kmk
index 748b7d2..5e99194 100644
--- a/kBuild/tools/JWASM.kmk
+++ b/kBuild/tools/JWASM.kmk
@@ -1,10 +1,10 @@
-# $Id: JWASM.kmk 2578 2012-06-07 00:08:22Z bird $
+# $Id: JWASM.kmk 2730 2014-03-16 20:30:59Z bird $
 ## @file
 # kBuild Tool Config - JWasm
 #
 
 #
-# Copyright (c) 2012 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2012-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -36,9 +36,9 @@ TOOL_JWASM := JWasm - MASM clone based on the Open Watcom assembler.
 
 # Tool Specific Properties
 ifndef TOOL_JWASM_AS
- TOOL_JWASM_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_BLD)/jwasm/*/jwasm$(HOSTSUFF_EXE))))
+ TOOL_JWASM_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_BLD)/jwasm/*/jwasm$(HOSTSUFF_EXE))))
  ifeq ($(TOOL_JWASM_AS),)
-  TOOL_JWASM_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_TRG)/jwasm/*/jwasm$(HOSTSUFF_EXE))))
+  TOOL_JWASM_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_TRG)/jwasm/*/jwasm$(HOSTSUFF_EXE))))
  endif
 endif
 ifeq ($(TOOL_JWASM_AS),)
diff --git a/kBuild/tools/MASM510.kmk b/kBuild/tools/MASM510.kmk
index 4cba932..91778e8 100644
--- a/kBuild/tools/MASM510.kmk
+++ b/kBuild/tools/MASM510.kmk
@@ -1,10 +1,10 @@
-# $Id: MASM510.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: MASM510.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - MASM v5.10
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,21 +35,21 @@ TOOL_MASM510 := Microsoft Macro Assembler v5.10
 
 # Tool Specific Properties
 ifndef TOOL_MASM510_AS
- TOOL_MASM510_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_BLD)/masm/v5.10*/masm$(HOSTSUFF_EXE))))
+ TOOL_MASM510_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_BLD)/masm/v5.10*/masm$(HOSTSUFF_EXE))))
  ifeq ($(TOOL_MASM510_AS),)
-  TOOL_MASM510_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_TRG)/masm/v5.10*/masm$(HOSTSUFF_EXE))))
+  TOOL_MASM510_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_TRG)/masm/v5.10*/masm$(HOSTSUFF_EXE))))
  endif
  ifeq ($(TOOL_MASM510_AS),)
-  TOOL_MASM510_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS)/os2.x86/ddk/*/base/tools/masm$(HOSTSUFF_EXE))))
+  TOOL_MASM510_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS)/os2.x86/ddk/*/base/tools/masm$(HOSTSUFF_EXE))))
  endif
  ifeq ($(TOOL_MASM510_AS),)
   TOOL_MASM510_AS := $(firstword $(rsort $(wildcard \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/video/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/bin/masm$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/print/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/wpshell/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/mme/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/video/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/bin/masm$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/print/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/wpshell/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/mme/tools/os2.386/lx.386/bin/masm$(HOSTSUFF_EXE) \
 	)))
  endif
  ifneq ($(TOOL_MASM510_AS),)
diff --git a/kBuild/tools/MASM600.kmk b/kBuild/tools/MASM600.kmk
index 07215df..d8ea283 100644
--- a/kBuild/tools/MASM600.kmk
+++ b/kBuild/tools/MASM600.kmk
@@ -1,10 +1,10 @@
-# $Id: MASM600.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: MASM600.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - MASM v6.00
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,12 +35,12 @@ TOOL_MASM600 := Microsoft Macro Assembler v6.00
 
 # Tool Specific Properties
 ifndef TOOL_MASM600_AS
- TOOL_MASM600_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_BLD)/masm/v6.00*/binp/ml$(HOSTSUFF_EXE))))
+ TOOL_MASM600_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_BLD)/masm/v6.00*/binp/ml$(HOSTSUFF_EXE))))
  ifeq ($(TOOL_MASM600_AS),)
-  TOOL_MASM600_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_TRG)/masm/v6.00*/binp/ml$(HOSTSUFF_EXE))))
+  TOOL_MASM600_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_TRG)/masm/v6.00*/binp/ml$(HOSTSUFF_EXE))))
  endif
  ifeq ($(TOOL_MASM600_AS),)
-  TOOL_MASM600_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS)/os2.x86/ddk/*/toolkits/masm60/binp/ml$(HOSTSUFF_EXE))))
+  TOOL_MASM600_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS)/os2.x86/ddk/*/toolkits/masm60/binp/ml$(HOSTSUFF_EXE))))
  endif
  ifeq ($(TOOL_MASM600_AS),)
   if1of ($(USER) $(USERNAME) $(LOGNAME), bird)
diff --git a/kBuild/tools/MASM610.kmk b/kBuild/tools/MASM610.kmk
index bf83373..d07636f 100644
--- a/kBuild/tools/MASM610.kmk
+++ b/kBuild/tools/MASM610.kmk
@@ -1,10 +1,10 @@
-# $Id: MASM610.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: MASM610.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - MASM v6.10
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,9 +35,9 @@ TOOL_MASM610 := Microsoft Macro Assembler v6.10
 
 # Tool Specific Properties
 ifndef TOOL_MASM610_AS
- TOOL_MASM610_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_BLD)/masm/v6.10*/binp/ml$(HOSTSUFF_EXE))))
+ TOOL_MASM610_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_BLD)/masm/v6.10*/binp/ml$(HOSTSUFF_EXE))))
  ifeq ($(TOOL_MASM610_AS),)
-  TOOL_MASM610_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_TRG)/masm/v6.10*/binp/ml$(HOSTSUFF_EXE))))
+  TOOL_MASM610_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_TRG)/masm/v6.10*/binp/ml$(HOSTSUFF_EXE))))
  endif
 endif
 ifeq ($(TOOL_MASM610_AS),)
diff --git a/kBuild/tools/MASM6PLUS.kmk b/kBuild/tools/MASM6PLUS.kmk
index 3377b98..a155876 100644
--- a/kBuild/tools/MASM6PLUS.kmk
+++ b/kBuild/tools/MASM6PLUS.kmk
@@ -1,10 +1,10 @@
-# $Id: MASM6PLUS.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: MASM6PLUS.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - MASM v6 and later.
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -36,16 +36,16 @@ TOOL_MASM6PLUS := Microsoft Macro Assembler v6 and later.
 # Tool Specific Properties
 ifndef TOOL_MASM6PLUS_AS
  TOOL_MASM6PLUS_AS := $(firstword $(rsort $(wildcard \
-	$(PATH_DEVTOOLS_BLD)/masm/*/bin$(if $(eq $(KBUILD_HOST),os2),p,)/ml$(HOSTSUFF_EXE)\
+	$(KBUILD_DEVTOOLS_BLD)/masm/*/bin$(if $(eq $(KBUILD_HOST),os2),p,)/ml$(HOSTSUFF_EXE)\
 	)))
  ifeq ($(TOOL_MASM6PLUS_AS),)
   TOOL_MASM6PLUS_AS := $(firstword $(rsort $(wildcard \
-	$(PATH_DEVTOOLS_BLD)/vcc/*/bin/ml$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS_BLD)/vcc/*/bin/ml$(HOSTSUFF_EXE) \
 	)))
  endif
  ifeq ($(TOOL_MASM6PLUS_AS),)
   TOOL_MASM6PLUS_AS := $(firstword $(rsort $(wildcard \
-	$(PATH_DEVTOOLS)/win.x86/vcc/*/bin/ml$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/win.x86/vcc/*/bin/ml$(HOSTSUFF_EXE) \
 	)))
  endif
 endif
diff --git a/kBuild/tools/MASM710.kmk b/kBuild/tools/MASM710.kmk
index 7410907..877c38e 100644
--- a/kBuild/tools/MASM710.kmk
+++ b/kBuild/tools/MASM710.kmk
@@ -1,10 +1,10 @@
-# $Id: MASM710.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: MASM710.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - MASM v7.10
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,12 +35,12 @@ TOOL_MASM710 := Microsoft Macro Assembler v7.10
 
 # Tool Specific Properties
 ifndef TOOL_MASM710_AS
- TOOL_MASM710_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_BLD)/masm/v7.10*/binp/ml$(HOSTSUFF_EXE))))
+ TOOL_MASM710_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_BLD)/masm/v7.10*/binp/ml$(HOSTSUFF_EXE))))
  ifeq ($(TOOL_MASM710_AS),)
-  TOOL_MASM710_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS_TRG)/masm/v7.10*/binp/ml$(HOSTSUFF_EXE))))
+  TOOL_MASM710_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS_TRG)/masm/v7.10*/binp/ml$(HOSTSUFF_EXE))))
  endif
  ifeq ($(TOOL_MASM710_AS),)
-  TOOL_MASM710_AS := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v7*/bin/ml$(HOSTSUFF_EXE))))
+  TOOL_MASM710_AS := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v7*/bin/ml$(HOSTSUFF_EXE))))
  endif
 endif
 ifeq ($(TOOL_MASM710_AS),)
diff --git a/kBuild/tools/MINGW32.kmk b/kBuild/tools/MINGW32.kmk
index c3104ae..e28e0f3 100644
--- a/kBuild/tools/MINGW32.kmk
+++ b/kBuild/tools/MINGW32.kmk
@@ -1,10 +1,10 @@
-# $Id: MINGW32.kmk 2487 2011-07-21 20:01:27Z bird $
+# $Id: MINGW32.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - MinGW32 GCC v3.3+.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -38,12 +38,12 @@ TOOL_MINGW32 := MinGW32 GCC v3.3+.
 
 # Tool Specific Properties
 ifndef PATH_TOOL_MINGW32
- PATH_TOOL_MINGW32 := $(wildcard $(PATH_DEVTOOLS_BLD)/mingw32/v*.*)
+ PATH_TOOL_MINGW32 := $(wildcard $(KBUILD_DEVTOOLS_BLD)/mingw32/v*.*)
  ifeq ($(PATH_TOOL_MINGW32),)
-  PATH_TOOL_MINGW32 := $(wildcard $(PATH_DEVTOOLS)/win.x86/mingw32/v*.*)
+  PATH_TOOL_MINGW32 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/mingw32/v*.*)
  endif
  ifeq ($(PATH_TOOL_MINGW32),)
-  PATH_TOOL_MINGW32 := $(wildcard $(PATH_DEVTOOLS)/x86.win32/mingw32/v*.*)
+  PATH_TOOL_MINGW32 := $(wildcard $(KBUILD_DEVTOOLS)/x86.win32/mingw32/v*.*)
  endif
  ifneq ($(PATH_TOOL_MINGW32),)
   PATH_TOOL_MINGW32 := $(lastword $(sort $(PATH_TOOL_MINGW32)))
diff --git a/kBuild/tools/MINGWW64.kmk b/kBuild/tools/MINGWW64.kmk
index b838812..c6143fe 100644
--- a/kBuild/tools/MINGWW64.kmk
+++ b/kBuild/tools/MINGWW64.kmk
@@ -1,10 +1,10 @@
-# $Id: MINGWW64.kmk 2695 2013-07-26 12:42:25Z bird $
+# $Id: MINGWW64.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - MinGW-W64.
 #
 
 #
-# Copyright (c) 2004-2012 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -38,12 +38,12 @@ TOOL_MINGWW64 := MinGW-W64 - The incomprehensible 64-bit GCC port to Windows.
 
 # Tool Specific Properties
 ifndef PATH_TOOL_MINGWW64
- PATH_TOOL_MINGWW64 := $(wildcard $(PATH_DEVTOOLS_BLD)/mingw-w64/r*)
+ PATH_TOOL_MINGWW64 := $(wildcard $(KBUILD_DEVTOOLS_BLD)/mingw-w64/r*)
  ifeq ($(PATH_TOOL_MINGWW64),)
-  PATH_TOOL_MINGWW64 := $(wildcard $(PATH_DEVTOOLS)/win.amd64/mingw-w64/r*)
+  PATH_TOOL_MINGWW64 := $(wildcard $(KBUILD_DEVTOOLS)/win.amd64/mingw-w64/r*)
  endif
  ifeq ($(PATH_TOOL_MINGWW64),)
-  PATH_TOOL_MINGWW64 := $(wildcard $(PATH_DEVTOOLS)/win.x86/mingw-w64/r*)
+  PATH_TOOL_MINGWW64 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/mingw-w64/r*)
  endif
  ifneq ($(PATH_TOOL_MINGWW64),)
   PATH_TOOL_MINGWW64 := $(lastword $(sort $(PATH_TOOL_MINGWW64)))
diff --git a/kBuild/tools/MSLINK510.kmk b/kBuild/tools/MSLINK510.kmk
index fe66aef..eeed5a7 100644
--- a/kBuild/tools/MSLINK510.kmk
+++ b/kBuild/tools/MSLINK510.kmk
@@ -1,10 +1,10 @@
-# $Id: MSLINK510.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: MSLINK510.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Microsoft Link v5.10
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,15 +35,15 @@ TOOL_MSLINK510 := Microsoft Segmented-Executable Linker  Version 5.10
 
 # Tool Specific Properties
 ifndef TOOL_MSLINK510_LD
- TOOL_MSLINK510_LD := $(firstword $(rsort $(wildcard $(PATH_DEVTOOLS)/os2.x86/ddk/*/base/tools/link$(HOSTSUFF_EXE))))
+ TOOL_MSLINK510_LD := $(firstword $(rsort $(wildcard $(KBUILD_DEVTOOLS)/os2.x86/ddk/*/base/tools/link$(HOSTSUFF_EXE))))
  ifeq ($(TOOL_MSLINK510_LD),)
   TOOL_MSLINK510_LD := $(firstword $(rsort $(wildcard \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/video/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/bin/link$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/print/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/wpshell/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
-	$(PATH_DEVTOOLS)/os2.x86/ddk/*/mme/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/video/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/bin/link$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/base32/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/print/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/wpshell/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
+	$(KBUILD_DEVTOOLS)/os2.x86/ddk/*/mme/tools/os2.386/lx.386/bin/link$(HOSTSUFF_EXE) \
 	)))
  endif
  ifneq ($(TOOL_MSLINK510_LD),)
diff --git a/kBuild/tools/NASM.kmk b/kBuild/tools/NASM.kmk
index 83d2970..660ce59 100644
--- a/kBuild/tools/NASM.kmk
+++ b/kBuild/tools/NASM.kmk
@@ -1,10 +1,10 @@
-# $Id: NASM.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: NASM.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Netwide Assembler v0.98+.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,7 +35,7 @@ TOOL_NASM := Netwide Assembler v0.98+
 
 # Tool Specific Properties
 ifndef PATH_TOOL_NASM
- PATH_TOOL_NASM := $(sort $(wildcard $(PATH_DEVTOOLS_BLD)/nasm/v*.*))
+ PATH_TOOL_NASM := $(sort $(wildcard $(KBUILD_DEVTOOLS_BLD)/nasm/v*.*))
  ifneq ($(PATH_TOOL_NASM),)
   PATH_TOOL_NASM := $(call lastword,$(PATH_TOOL_NASM))
  endif
diff --git a/kBuild/tools/OPENWATCOM-16.kmk b/kBuild/tools/OPENWATCOM-16.kmk
index a9c141f..830a760 100644
--- a/kBuild/tools/OPENWATCOM-16.kmk
+++ b/kBuild/tools/OPENWATCOM-16.kmk
@@ -1,4 +1,4 @@
-# $Id: OPENWATCOM-16.kmk 2572 2012-04-27 13:19:55Z bird $
+# $Id: OPENWATCOM-16.kmk 2731 2014-06-28 14:58:12Z bird $
 ## @file
 # kBuild Tool Config - Open Watcom v1.4 and later, 16-bit targets.
 #
@@ -112,7 +112,7 @@ TOOL_OPENWATCOM-16_LINK_PROGRAM_OUTPUT_MAYBE = $(outbase).sym
 TOOL_OPENWATCOM-16_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_OPENWATCOM-16_LINK_PROGRAM_DEPORD =
 define TOOL_OPENWATCOM-16_LINK_PROGRAM_CMDS
-	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_OPENWATCOM_LD16) \
 		$(flags) \
 		-fe=$(call TOOL_OPENWATCOM_FIX_SLASHES,$(out)) \
@@ -132,7 +132,7 @@ TOOL_OPENWATCOM-16_LINK_DLL_OUTPUT_MAYBE = $(outbase).sym
 TOOL_OPENWATCOM-16_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_OPENWATCOM-16_LINK_DLL_DEPORD =
 define TOOL_OPENWATCOM-16_LINK_DLL_CMDS
-	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_OPENWATCOM_LD16) \
 		$(flags) \
 		-fe=$(call TOOL_OPENWATCOM_FIX_SLASHES,$(out)) \
@@ -152,7 +152,7 @@ TOOL_OPENWATCOM-16_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).sym
 TOOL_OPENWATCOM-16_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_OPENWATCOM-16_LINK_SYSMOD_DEPORD =
 define TOOL_OPENWATCOM-16_LINK_SYSMOD_CMDS
-	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_OPENWATCOM_LD16) \
 		$(flags) \
 		-fe=$(call TOOL_OPENWATCOM_FIX_SLASHES,$(out)) \
diff --git a/kBuild/tools/OPENWATCOM.kmk b/kBuild/tools/OPENWATCOM.kmk
index bbfdc46..2ced379 100644
--- a/kBuild/tools/OPENWATCOM.kmk
+++ b/kBuild/tools/OPENWATCOM.kmk
@@ -1,10 +1,10 @@
-# $Id: OPENWATCOM.kmk 2663 2012-10-15 13:13:45Z bird $
+# $Id: OPENWATCOM.kmk 2732 2014-06-28 16:02:41Z bird $
 ## @file
 # kBuild Tool Config - Open Watcom v1.4 and later.
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,13 +35,13 @@ TOOL_OPENWATCOM = Open Watcom v1.4 and later (generic)
 
 ifeq ($(PATH_TOOL_OPENWATCOM),)
  ifeq ($(PATH_TOOL_OPENWATCOM),)
-  PATH_TOOL_OPENWATCOM := $(wildcard $(PATH_DEVTOOLS_BLD)/openwatcom/v*)
+  PATH_TOOL_OPENWATCOM := $(wildcard $(KBUILD_DEVTOOLS_BLD)/openwatcom/v*)
  endif
  ifeq ($(PATH_TOOL_OPENWATCOM),)
-  PATH_TOOL_OPENWATCOM := $(wildcard $(PATH_DEVTOOLS_TRG)/openwatcom/v*)
+  PATH_TOOL_OPENWATCOM := $(wildcard $(KBUILD_DEVTOOLS_TRG)/openwatcom/v*)
  endif
  ifeq ($(PATH_TOOL_OPENWATCOM),)
-  PATH_TOOL_OPENWATCOM := $(wildcard $(PATH_DEVTOOLS)/common/openwatcom/v*)
+  PATH_TOOL_OPENWATCOM := $(wildcard $(KBUILD_DEVTOOLS)/common/openwatcom/v*)
  endif
  ifeq ($(PATH_TOOL_OPENWATCOM)$(KBUILD_HOST),os2)
   if1of ($(USER) $(USERNAME) $(LOGNAME), bird)
@@ -66,7 +66,7 @@ ifneq ($(PATH_TOOL_OPENWATCOM),)
  	-E 'EDPATH=$(PATH_TOOL_OPENWATCOM)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  else ifeq ($(KBUILD_HOST),freebsd)
   PATH_TOOL_OPENWATCOM_BIN   = $(PATH_TOOL_OPENWATCOM)/binfbsd
   TOOL_OPENWATCOM_ENV_SETUP ?= $(REDIRECT) \
@@ -75,7 +75,7 @@ ifneq ($(PATH_TOOL_OPENWATCOM),)
  	-E 'EDPATH=$(PATH_TOOL_OPENWATCOM)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  else ifeq ($(KBUILD_HOST),linux)
   PATH_TOOL_OPENWATCOM_BIN   = $(PATH_TOOL_OPENWATCOM)/binl
   TOOL_OPENWATCOM_ENV_SETUP ?= $(REDIRECT) \
@@ -84,7 +84,7 @@ ifneq ($(PATH_TOOL_OPENWATCOM),)
  	-E 'EDPATH=$(PATH_TOOL_OPENWATCOM)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  else ifeq ($(KBUILD_HOST),os2)
   PATH_TOOL_OPENWATCOM_BIN   = $(PATH_TOOL_OPENWATCOM)/binp
   TOOL_OPENWATCOM_ENV_SETUP ?= $(REDIRECT) \
@@ -95,7 +95,7 @@ ifneq ($(PATH_TOOL_OPENWATCOM),)
  	-E 'EDPATH=$(PATH_TOOL_OPENWATCOM)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  else ifeq ($(KBUILD_HOST),solaris)
   PATH_TOOL_OPENWATCOM_BIN   = $(PATH_TOOL_OPENWATCOM)/binsol
   TOOL_OPENWATCOM_ENV_SETUP ?= $(REDIRECT) \
@@ -104,7 +104,7 @@ ifneq ($(PATH_TOOL_OPENWATCOM),)
  	-E 'EDPATH=$(PATH_TOOL_OPENWATCOM)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  else
   PATH_TOOL_OPENWATCOM_BIN   = $(PATH_TOOL_OPENWATCOM)/binnt
   TOOL_OPENWATCOM_ENV_SETUP ?= $(REDIRECT) \
@@ -113,7 +113,7 @@ ifneq ($(PATH_TOOL_OPENWATCOM),)
  	-E 'EDPATH=$(PATH_TOOL_OPENWATCOM)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  endif
 
  TOOL_OPENWATCOM_CC    ?= $(PATH_TOOL_OPENWATCOM_BIN)/wcc386$(HOSTSUFF_EXE)
@@ -133,7 +133,7 @@ else
  TOOL_OPENWATCOM_ENV_SETUP ?= $(REDIRECT) \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  TOOL_OPENWATCOM_CC    ?= wcc386$(HOSTSUFF_EXE)
  TOOL_OPENWATCOM_CC16  ?= wcc$(HOSTSUFF_EXE)
  TOOL_OPENWATCOM_CXX   ?= wpp386$(HOSTSUFF_EXE)
@@ -261,7 +261,17 @@ TOOL_OPENWATCOM_LINK_LIBRARY_OUTPUT = ## @todo $(outbase).rsp
 TOOL_OPENWATCOM_LINK_LIBRARY_DEPEND = $(othersrc)
 TOOL_OPENWATCOM_LINK_LIBRARY_DEPORD =
 define TOOL_OPENWATCOM_LINK_LIBRARY_CMDS
-	$(QUIET)$(APPEND) -tn $(outbase).rsp $(foreach obj,$(call TOOL_OPENWATCOM_FIX_SLASHES,$(objs) $(othersrc)),'+"$(obj)"')
+	$(QUIET)$(APPEND) -tn $(outbase).rsp $(foreach obj,$(call TOOL_OPENWATCOM_FIX_SLASHES,$(objs) $(filter-out %.imp,$(othersrc))),'+"$(obj)"')
+	$(if $(filter %.imp,$(othersrc)),$(SED) \
+		-e 's/;.*$(DOLLAR)$(DOLLAR)//g' \
+		-e 's/^[[:space:]][[:space:]]*//g' \
+		-e 's/[[:space:]][[:space:]]*$(DOLLAR)$(DOLLAR)//g' \
+		-e '/^[[:space:]]*$(DOLLAR)$(DOLLAR)/d' \
+		-e 's/[[:space:]][[:space:]]*/ /g' \
+		-e 's/\([^ ][^ ]*\) \([^ ][^ ]*\) \([^ ][^ ]*\) \([^ ][^ ]*\).*/++\1.\2.\3/' \
+       	$(filter %.imp,$(othersrc)) \
+               --append $(outbase).rsp \
+	)
 	$(QUIET)$(TOOL_OPENWATCOM_ENV_SETUP) $(TOOL_OPENWATCOM_AR) $(flags) $(call TOOL_OPENWATCOM_FIX_SLASHES,$(out)) @$(outbase).rsp
 endef
 
@@ -269,7 +279,7 @@ TOOL_OPENWATCOM_LINK_PROGRAM_OUTPUT = $(outbase).map
 TOOL_OPENWATCOM_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_OPENWATCOM_LINK_PROGRAM_DEPORD =
 define TOOL_OPENWATCOM_LINK_PROGRAM_CMDS
-	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_OPENWATCOM_LD) \
 		$(flags) \
 		-fe=$(call TOOL_OPENWATCOM_FIX_SLASHES,$(out)) \
@@ -288,7 +298,7 @@ TOOL_OPENWATCOM_LINK_DLL_OUTPUT = $(outbase).map
 TOOL_OPENWATCOM_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_OPENWATCOM_LINK_DLL_DEPORD =
 define TOOL_OPENWATCOM_LINK_DLL_CMDS
-	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_OPENWATCOM_LD) \
 		$(flags) \
 		-fe=$(call TOOL_OPENWATCOM_FIX_SLASHES,$(out)) \
@@ -307,7 +317,7 @@ TOOL_OPENWATCOM_LINK_SYSMOD_OUTPUT = $(outbase).map
 TOOL_OPENWATCOM_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_OPENWATCOM_LINK_SYSMOD_DEPORD =
 define TOOL_OPENWATCOM_LINK_SYSMOD_CMDS
-	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_OPENWATCOM_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_OPENWATCOM_LD) \
 		$(flags) \
 		-fe=$(call TOOL_OPENWATCOM_FIX_SLASHES,$(out)) \
diff --git a/kBuild/tools/TAR.kmk b/kBuild/tools/TAR.kmk
index 5d1f653..825daed 100644
--- a/kBuild/tools/TAR.kmk
+++ b/kBuild/tools/TAR.kmk
@@ -1,10 +1,10 @@
-# $Id: TAR.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: TAR.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - tar unpacker.
 #
 
 #
-# Copyright (c) 2006-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2006-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,9 +35,9 @@ TOOL_TAR := tar unpacker.
 
 # Tool Specific Properties
 ifndef TOOL_TAR_TAR
- TOOL_TAR_TAR := $(wildcard $(PATH_DEVTOOLS_BLD)/tar/v*/tar$(HOSTSUFF_EXE))
+ TOOL_TAR_TAR := $(wildcard $(KBUILD_DEVTOOLS_BLD)/tar/v*/tar$(HOSTSUFF_EXE))
  ifeq ($(TOOL_TAR_TAR),)
-  TOOL_TAR_TAR := $(wildcard $(PATH_DEVTOOLS_BLD)/bin/tar$(HOSTSUFF_EXE))
+  TOOL_TAR_TAR := $(wildcard $(KBUILD_DEVTOOLS_BLD)/bin/tar$(HOSTSUFF_EXE))
  endif
  ifneq ($(TOOL_TAR_TAR),)
   TOOL_TAR_TAR := $(lastword $(sort $(TOOL_TAR_TAR)))
diff --git a/kBuild/tools/VAC308.kmk b/kBuild/tools/VAC308.kmk
index 79a9a8a..fad15b2 100644
--- a/kBuild/tools/VAC308.kmk
+++ b/kBuild/tools/VAC308.kmk
@@ -1,10 +1,10 @@
-# $Id: VAC308.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: VAC308.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - VisualAge for C++ v3.08.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,14 +35,14 @@ TOOL_VAC308 := VisualAge for C++ v3.08
 
 # Determin VAC308 location.
 ifndef PATH_TOOL_VAC308
- PATH_TOOL_VAC308 := $(wildcard $(PATH_DEVTOOLS_BLD)/vac/v3.0.8*)
+ PATH_TOOL_VAC308 := $(wildcard $(KBUILD_DEVTOOLS_BLD)/vac/v3.0.8*)
  ifeq ($(PATH_TOOL_VAC308),)
-  PATH_TOOL_VAC308 := $(wildcard $(PATH_DEVTOOLS_BLD)/vac/v308*)
+  PATH_TOOL_VAC308 := $(wildcard $(KBUILD_DEVTOOLS_BLD)/vac/v308*)
  endif
  ifeq ($(PATH_TOOL_VAC308),)
-  PATH_TOOL_VAC308 := $(wildcard $(PATH_DEVTOOLS_TRG)/vac/v3.0.8*)
+  PATH_TOOL_VAC308 := $(wildcard $(KBUILD_DEVTOOLS_TRG)/vac/v3.0.8*)
   ifeq ($(PATH_TOOL_VAC308),)
-   PATH_TOOL_VAC308 := $(wildcard $(PATH_DEVTOOLS_TRG)/vac/v308*)
+   PATH_TOOL_VAC308 := $(wildcard $(KBUILD_DEVTOOLS_TRG)/vac/v308*)
   endif
  endif
  ifeq ($(PATH_TOOL_VAC308),)
diff --git a/kBuild/tools/VCC100.kmk b/kBuild/tools/VCC100.kmk
index fdacfa1..85a1b47 100644
--- a/kBuild/tools/VCC100.kmk
+++ b/kBuild/tools/VCC100.kmk
@@ -1,10 +1,10 @@
-# $Id: VCC100.kmk 2677 2013-02-01 15:04:53Z bird $
+# $Id: VCC100.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Visual C++ 10.0 (aka Visual 2010 and MSC v16), targeting $(KBUILD_TARGET).
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,15 +35,15 @@ TOOL_VCC100 := Visual C++ 10.0 (aka Visual 2010 and MSC v16), targeting $(KBUILD
 
 # Tool Specific Properties
 ifndef PATH_TOOL_VCC100
- PATH_TOOL_VCC100 := $(wildcard $(PATH_DEVTOOLS_TRG)/vcc/v10*)
+ PATH_TOOL_VCC100 := $(wildcard $(KBUILD_DEVTOOLS_TRG)/vcc/v10*)
  ifeq ($(PATH_TOOL_VCC100),)
-  PATH_TOOL_VCC100 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v10*)
+  PATH_TOOL_VCC100 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v10*)
  endif
  ifeq ($(PATH_TOOL_VCC100),)
-  PATH_TOOL_VCC100 := $(wildcard $(PATH_DEVTOOLS)/x86.win32/vcc/v10*)
+  PATH_TOOL_VCC100 := $(wildcard $(KBUILD_DEVTOOLS)/x86.win32/vcc/v10*)
  endif
  ifeq ($(PATH_TOOL_VCC100),)
-  PATH_TOOL_VCC100 := $(wildcard $(PATH_DEVTOOLS)/win.amd64/vcc/v10*)
+  PATH_TOOL_VCC100 := $(wildcard $(KBUILD_DEVTOOLS)/win.amd64/vcc/v10*)
  endif
  ifeq ($(PATH_TOOL_VCC100),)
   PATH_TOOL_VCC100 := $(lastword $(sort $(PATH_TOOL_VCC100)))
diff --git a/kBuild/tools/VCC100AMD64.kmk b/kBuild/tools/VCC100AMD64.kmk
index 0a06a4d..5e8c8f0 100644
--- a/kBuild/tools/VCC100AMD64.kmk
+++ b/kBuild/tools/VCC100AMD64.kmk
@@ -1,10 +1,10 @@
-# $Id: VCC100AMD64.kmk 2625 2012-08-07 20:26:48Z bird $
+# $Id: VCC100AMD64.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Visual C++ 10.0 (aka Visual 2010 and MSC v16), targeting AMD64.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,7 +35,7 @@ TOOL_VCC100AMD64 := Visual C++ 10.0 (aka Visual 2010 and MSC v16), targeting AMD
 
 # Tool Specific Properties
 ifndef PATH_TOOL_VCC100AMD64
- PATH_TOOL_VCC100AMD64 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v10*)
+ PATH_TOOL_VCC100AMD64 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v10*)
  ifeq ($(PATH_TOOL_VCC100AMD64),)
   PATH_TOOL_VCC100AMD64 := $(PATH_TOOL_VCC100)
  endif
@@ -43,13 +43,13 @@ ifndef PATH_TOOL_VCC100AMD64
   PATH_TOOL_VCC100AMD64 := $(PATH_TOOL_VCC100X86)
  endif
  ifeq ($(PATH_TOOL_VCC100AMD64),)
-  PATH_TOOL_VCC100AMD64 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v10*)
+  PATH_TOOL_VCC100AMD64 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v10*)
  endif
  ifneq ($(PATH_TOOL_VCC100AMD64),)
   PATH_TOOL_VCC100AMD64 := $(lastword $(sort $(PATH_TOOL_VCC100AMD64)))
  else
   $(warning kBuild: PATH_TOOL_VCC100AMD64 cannot be determined!)
-  PATH_TOOL_VCC100AMD64 := $(PATH_DEVTOOLS)/win.x86/vcc/v10
+  PATH_TOOL_VCC100AMD64 := $(KBUILD_DEVTOOLS)/win.x86/vcc/v10
  endif
 else
  # Resolve any fancy stuff once and for all.
diff --git a/kBuild/tools/VCC100X86.kmk b/kBuild/tools/VCC100X86.kmk
index 3aa31cd..e593c66 100644
--- a/kBuild/tools/VCC100X86.kmk
+++ b/kBuild/tools/VCC100X86.kmk
@@ -1,10 +1,10 @@
-# $Id: VCC100X86.kmk 2625 2012-08-07 20:26:48Z bird $
+# $Id: VCC100X86.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Visual C++ 10.0 (aka Visual 2010 and MSC v16), targeting x86.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,7 +35,7 @@ TOOL_VCC100X86 := Visual C++ 10.0 (aka Visual 2010 and MSC v16), targeting x86.
 
 # Tool Specific Properties
 ifndef PATH_TOOL_VCC100X86
- PATH_TOOL_VCC100X86 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v10*)
+ PATH_TOOL_VCC100X86 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v10*)
  ifeq ($(PATH_TOOL_VCC100X86),)
   PATH_TOOL_VCC100X86 := $(PATH_TOOL_VCC100)
  endif
@@ -43,16 +43,16 @@ ifndef PATH_TOOL_VCC100X86
   PATH_TOOL_VCC100X86 := $(PATH_TOOL_VCC100AMD64)
  endif
  ifeq ($(PATH_TOOL_VCC100X86),)
-  PATH_TOOL_VCC100X86 := $(wildcard $(PATH_DEVTOOLS)/x86.win32/vcc/v10*)
+  PATH_TOOL_VCC100X86 := $(wildcard $(KBUILD_DEVTOOLS)/x86.win32/vcc/v10*)
  endif
  ifeq ($(PATH_TOOL_VCC100X86),)
-  PATH_TOOL_VCC100X86 := $(wildcard $(PATH_DEVTOOLS)/win.amd64/vcc/v10*)
+  PATH_TOOL_VCC100X86 := $(wildcard $(KBUILD_DEVTOOLS)/win.amd64/vcc/v10*)
  endif
  ifneq ($(PATH_TOOL_VCC100X86),)
   PATH_TOOL_VCC100X86 := $(lastword $(sort $(PATH_TOOL_VCC100X86)))
  else
   $(warning kBuild: PATH_TOOL_VCC100X86 cannot be determined!)
-  PATH_TOOL_VCC100X86 := $(PATH_DEVTOOLS)/x86.win/vcc/v10
+  PATH_TOOL_VCC100X86 := $(KBUILD_DEVTOOLS)/x86.win/vcc/v10
  endif
 else
  # Resolve any fancy stuff once and for all.
diff --git a/kBuild/tools/VCC70.kmk b/kBuild/tools/VCC70.kmk
index ae79a67..de04bf7 100644
--- a/kBuild/tools/VCC70.kmk
+++ b/kBuild/tools/VCC70.kmk
@@ -1,10 +1,10 @@
-# $Id: VCC70.kmk 2557 2011-12-13 12:48:32Z bird $
+# $Id: VCC70.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Visual C++ 7.0 (aka Visual Studio .NET), targeting x86.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -36,9 +36,9 @@ TOOL_VCC70 := Visual C++ 7.0 (aka Visual Studio .NET), targeting x86.
 # Tool Specific Properties
 ifndef PATH_TOOL_VCC70
  PATH_TOOL_VCC70 := $(firstword $(wildcard \
-	$(PATH_DEVTOOLS)/win.x86/vcc/v7 \
-	$(PATH_DEVTOOLS)/x86.win32/vcc/v7 \
-	$(PATH_DEVTOOLS)/x86.win32/vcc70) )
+	$(KBUILD_DEVTOOLS)/win.x86/vcc/v7 \
+	$(KBUILD_DEVTOOLS)/x86.win32/vcc/v7 \
+	$(KBUILD_DEVTOOLS)/x86.win32/vcc70) )
  # if not found, we'll enter 'pathless' mode.
 else
  # Resolve any fancy stuff once and for all.
diff --git a/kBuild/tools/VCC80.kmk b/kBuild/tools/VCC80.kmk
index 3f2fdf0..437b17e 100644
--- a/kBuild/tools/VCC80.kmk
+++ b/kBuild/tools/VCC80.kmk
@@ -1,10 +1,10 @@
-# $Id: VCC80.kmk 2557 2011-12-13 12:48:32Z bird $
+# $Id: VCC80.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Visual C++ 8.0 (aka Visual .NET 2005, or MSC v14), targeting $(KBUILD_TARGET).
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,15 +35,15 @@ TOOL_VCC80 := Visual C++ 8.0 (aka Visual .NET 2005, or MSC v14), targeting $(KBU
 
 # Tool Specific Properties
 ifndef PATH_TOOL_VCC80
- PATH_TOOL_VCC80 := $(wildcard $(PATH_DEVTOOLS_TRG)/vcc/v8*)
+ PATH_TOOL_VCC80 := $(wildcard $(KBUILD_DEVTOOLS_TRG)/vcc/v8*)
  ifeq ($(PATH_TOOL_VCC80),)
-  PATH_TOOL_VCC80 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v8*)
+  PATH_TOOL_VCC80 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v8*)
  endif
  ifeq ($(PATH_TOOL_VCC80),)
-  PATH_TOOL_VCC80 := $(wildcard $(PATH_DEVTOOLS)/x86.win32/vcc/v8*)
+  PATH_TOOL_VCC80 := $(wildcard $(KBUILD_DEVTOOLS)/x86.win32/vcc/v8*)
  endif
  ifeq ($(PATH_TOOL_VCC80),)
-  PATH_TOOL_VCC80 := $(wildcard $(PATH_DEVTOOLS)/win.amd64/vcc/v8*)
+  PATH_TOOL_VCC80 := $(wildcard $(KBUILD_DEVTOOLS)/win.amd64/vcc/v8*)
  endif
  ifeq ($(PATH_TOOL_VCC80),)
   PATH_TOOL_VCC80 := $(lastword $(sort $(PATH_TOOL_VCC80)))
diff --git a/kBuild/tools/VCC80AMD64.kmk b/kBuild/tools/VCC80AMD64.kmk
index 2c07f05..f97d494 100644
--- a/kBuild/tools/VCC80AMD64.kmk
+++ b/kBuild/tools/VCC80AMD64.kmk
@@ -1,10 +1,10 @@
-# $Id: VCC80AMD64.kmk 2557 2011-12-13 12:48:32Z bird $
+# $Id: VCC80AMD64.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Visual C++ 8.0 (aka Visual .NET 2005, or MSC v14), targeting AMD64.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,7 +35,7 @@ TOOL_VCC80AMD64 := Visual C++ 8.0 (aka Visual .NET 2005, or MSC v14), targeting
 
 # Tool Specific Properties
 ifndef PATH_TOOL_VCC80AMD64
- PATH_TOOL_VCC80AMD64 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v8*)
+ PATH_TOOL_VCC80AMD64 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v8*)
  ifeq ($(PATH_TOOL_VCC80AMD64),)
   PATH_TOOL_VCC80AMD64 := $(PATH_TOOL_VCC80)
  endif
@@ -43,13 +43,13 @@ ifndef PATH_TOOL_VCC80AMD64
   PATH_TOOL_VCC80AMD64 := $(PATH_TOOL_VCC80X86)
  endif
  ifeq ($(PATH_TOOL_VCC80AMD64),)
-  PATH_TOOL_VCC80AMD64 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v8*)
+  PATH_TOOL_VCC80AMD64 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v8*)
  endif
  ifneq ($(PATH_TOOL_VCC80AMD64),)
   PATH_TOOL_VCC80AMD64 := $(lastword $(sort $(PATH_TOOL_VCC80AMD64)))
  else
   $(warning kBuild: PATH_TOOL_VCC80AMD64 cannot be determined!)
-  PATH_TOOL_VCC80AMD64 := $(PATH_DEVTOOLS)/win.x86/vcc/v8
+  PATH_TOOL_VCC80AMD64 := $(KBUILD_DEVTOOLS)/win.x86/vcc/v8
  endif
 else
  # Resolve any fancy stuff once and for all.
diff --git a/kBuild/tools/VCC80X86.kmk b/kBuild/tools/VCC80X86.kmk
index e2d736d..1df549f 100644
--- a/kBuild/tools/VCC80X86.kmk
+++ b/kBuild/tools/VCC80X86.kmk
@@ -1,10 +1,10 @@
-# $Id: VCC80X86.kmk 2557 2011-12-13 12:48:32Z bird $
+# $Id: VCC80X86.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - Visual C++ 8.0 (aka Visual .NET 2005, or MSC v14), targeting x86.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,7 +35,7 @@ TOOL_VCC80X86 := Visual C++ 8.0 (aka Visual .NET 2005, or MSC v14), targeting x8
 
 # Tool Specific Properties
 ifndef PATH_TOOL_VCC80X86
- PATH_TOOL_VCC80X86 := $(wildcard $(PATH_DEVTOOLS)/win.x86/vcc/v8*)
+ PATH_TOOL_VCC80X86 := $(wildcard $(KBUILD_DEVTOOLS)/win.x86/vcc/v8*)
  ifeq ($(PATH_TOOL_VCC80X86),)
   PATH_TOOL_VCC80X86 := $(PATH_TOOL_VCC80)
  endif
@@ -43,16 +43,16 @@ ifndef PATH_TOOL_VCC80X86
   PATH_TOOL_VCC80X86 := $(PATH_TOOL_VCC80AMD64)
  endif
  ifeq ($(PATH_TOOL_VCC80X86),)
-  PATH_TOOL_VCC80X86 := $(wildcard $(PATH_DEVTOOLS)/x86.win32/vcc/v8*)
+  PATH_TOOL_VCC80X86 := $(wildcard $(KBUILD_DEVTOOLS)/x86.win32/vcc/v8*)
  endif
  ifeq ($(PATH_TOOL_VCC80X86),)
-  PATH_TOOL_VCC80X86 := $(wildcard $(PATH_DEVTOOLS)/win.amd64/vcc/v8*)
+  PATH_TOOL_VCC80X86 := $(wildcard $(KBUILD_DEVTOOLS)/win.amd64/vcc/v8*)
  endif
  ifneq ($(PATH_TOOL_VCC80X86),)
   PATH_TOOL_VCC80X86 := $(lastword $(sort $(PATH_TOOL_VCC80X86)))
  else
   $(warning kBuild: PATH_TOOL_VCC80X86 cannot be determined!)
-  PATH_TOOL_VCC80X86 := $(PATH_DEVTOOLS)/x86.win/vcc/v8
+  PATH_TOOL_VCC80X86 := $(KBUILD_DEVTOOLS)/x86.win/vcc/v8
  endif
 else
  # Resolve any fancy stuff once and for all.
diff --git a/kBuild/tools/WATCOMC11C-16.kmk b/kBuild/tools/WATCOMC11C-16.kmk
index 175e5f5..be907ec 100644
--- a/kBuild/tools/WATCOMC11C-16.kmk
+++ b/kBuild/tools/WATCOMC11C-16.kmk
@@ -1,4 +1,4 @@
-# $Id: WATCOMC11C-16.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: WATCOMC11C-16.kmk 2731 2014-06-28 14:58:12Z bird $
 ## @file
 # kBuild Tool Config - Watcom C v11.0c, 16-bit targets.
 #
@@ -95,7 +95,7 @@ TOOL_WATCOMC11C-16_LINK_PROGRAM_OUTPUT = $(outbase).map
 TOOL_WATCOMC11C-16_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_WATCOMC11C-16_LINK_PROGRAM_DEPORD =
 define TOOL_WATCOMC11C-16_LINK_PROGRAM_CMDS
-	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_WATCOMC11C_LD16) \
 		$(flags) \
 		-fe=$(subst /,\\,$(out)) \
@@ -114,7 +114,7 @@ TOOL_WATCOMC11C-16_LINK_DLL_OUTPUT = $(outbase).map
 TOOL_WATCOMC11C-16_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_WATCOMC11C-16_LINK_DLL_DEPORD =
 define TOOL_WATCOMC11C-16_LINK_DLL_CMDS
-	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_WATCOMC11C_LD16) \
 		$(flags) \
 		-fe=$(subst /,\\,$(out)) \
@@ -133,7 +133,7 @@ TOOL_WATCOMC11C-16_LINK_SYSMOD_OUTPUT = $(outbase).map
 TOOL_WATCOMC11C-16_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_WATCOMC11C-16_LINK_SYSMOD_DEPORD =
 define TOOL_WATCOMC11C-16_LINK_SYSMOD_CMDS
-	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_WATCOMC11C_LD16) \
 		$(flags) \
 		-fe=$(subst /,\\,$(out)) \
diff --git a/kBuild/tools/WATCOMC11C.kmk b/kBuild/tools/WATCOMC11C.kmk
index e3328e7..44bb885 100644
--- a/kBuild/tools/WATCOMC11C.kmk
+++ b/kBuild/tools/WATCOMC11C.kmk
@@ -1,10 +1,10 @@
-# $Id: WATCOMC11C.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: WATCOMC11C.kmk 2731 2014-06-28 14:58:12Z bird $
 ## @file
 # kBuild Tool Config - Watcom C v11.0c
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,13 +35,13 @@ TOOL_WATCOMC11C = Watcom C/C++ v11.0c (generic)
 
 ifeq ($(PATH_TOOL_WATCOMC11C),)
  ifeq ($(PATH_TOOL_WATCOMC11C),)
-  PATH_TOOL_WATCOMC11C := $(wildcard $(PATH_DEVTOOLS_BLD)/watcom/v11.0c*)
+  PATH_TOOL_WATCOMC11C := $(wildcard $(KBUILD_DEVTOOLS_BLD)/watcom/v11.0c*)
  endif
  ifeq ($(PATH_TOOL_WATCOMC11C),)
-  PATH_TOOL_WATCOMC11C := $(wildcard $(PATH_DEVTOOLS_TRG)/watcom/v11.0c*)
+  PATH_TOOL_WATCOMC11C := $(wildcard $(KBUILD_DEVTOOLS_TRG)/watcom/v11.0c*)
  endif
  ifeq ($(PATH_TOOL_WATCOMC11C),)
-  PATH_TOOL_WATCOMC11C := $(wildcard $(PATH_DEVTOOLS)/common/watcom/v11.0c*)
+  PATH_TOOL_WATCOMC11C := $(wildcard $(KBUILD_DEVTOOLS)/common/watcom/v11.0c*)
  endif
  ifeq ($(PATH_TOOL_WATCOMC11C)$(KBUILD_HOST),os2)
   if1of ($(USER) $(USERNAME) $(LOGNAME), bird)
@@ -69,7 +69,7 @@ ifneq ($(PATH_TOOL_WATCOMC11C),)
  	-E 'EDPATH=$(PATH_TOOL_WATCOMC11C)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  else
   PATH_TOOL_WATCOMC11C_BIN   = $(PATH_TOOL_WATCOMC11C)/binnt
   PATH_TOOL_WATCOMC11C_BIN2  = $(PATH_TOOL_WATCOMC11C_BIN)
@@ -79,7 +79,7 @@ ifneq ($(PATH_TOOL_WATCOMC11C),)
  	-E 'EDPATH=$(PATH_TOOL_WATCOMC11C)/EDDAT' \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  endif
 
  TOOL_WATCOMC11C_CC    ?= $(PATH_TOOL_WATCOMC11C_BIN)/wcc386$(HOSTSUFF_EXE)
@@ -99,7 +99,7 @@ else
  TOOL_WATCOMC11C_ENV_SETUP ?= $(REDIRECT) \
  	-E 'LIB=$1' \
  	-E 'INCLUDE=' \
- 	--
+ 	$2 --
  TOOL_WATCOMC11C_CC    ?= wcc386$(HOSTSUFF_EXE)
  TOOL_WATCOMC11C_CC16  ?= wcc$(HOSTSUFF_EXE)
  TOOL_WATCOMC11C_CXX   ?= wpp386$(HOSTSUFF_EXE)
@@ -202,7 +202,7 @@ TOOL_WATCOMC11C_LINK_PROGRAM_OUTPUT = $(outbase).map
 TOOL_WATCOMC11C_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_WATCOMC11C_LINK_PROGRAM_DEPORD =
 define TOOL_WATCOMC11C_LINK_PROGRAM_CMDS
-	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_WATCOMC11C_LD) \
 		$(flags) \
 		-fe=$(subst /,\\,$(out)) \
@@ -221,7 +221,7 @@ TOOL_WATCOMC11C_LINK_DLL_OUTPUT = $(outbase).map
 TOOL_WATCOMC11C_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_WATCOMC11C_LINK_DLL_DEPORD =
 define TOOL_WATCOMC11C_LINK_DLL_CMDS
-	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_WATCOMC11C_LD) \
 		$(flags) \
 		-fe=$(subst /,\\,$(out)) \
@@ -240,7 +240,7 @@ TOOL_WATCOMC11C_LINK_SYSMOD_OUTPUT = $(outbase).map
 TOOL_WATCOMC11C_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) $(othersrc)
 TOOL_WATCOMC11C_LINK_SYSMOD_DEPORD =
 define TOOL_WATCOMC11C_LINK_SYSMOD_CMDS
-	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath)))) \
+	$(QUIET)$(call TOOL_WATCOMC11C_ENV_SETUP,$(subst $(SP),,$(addsuffix ;,$(libpath))),-C $(dir $(out))) \
 		$(TOOL_WATCOMC11C_LD) \
 		$(flags) \
 		-fe=$(subst /,\\,$(out)) \
diff --git a/kBuild/tools/WGET.kmk b/kBuild/tools/WGET.kmk
index b6d4022..2bd0670 100644
--- a/kBuild/tools/WGET.kmk
+++ b/kBuild/tools/WGET.kmk
@@ -1,10 +1,10 @@
-# $Id: WGET.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: WGET.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - wget fetchers.
 #
 
 #
-# Copyright (c) 2006-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2006-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,9 +35,9 @@ TOOL_WGET := wget fetcher.
 
 # Tool Specific Properties
 ifndef TOOL_WGET_FETCH
- TOOL_WGET_FETCH := $(wildcard $(PATH_DEVTOOLS_BLD)/wget/v*/wget$(HOSTSUFF_EXE))
+ TOOL_WGET_FETCH := $(wildcard $(KBUILD_DEVTOOLS_BLD)/wget/v*/wget$(HOSTSUFF_EXE))
  ifneq ($(TOOL_WGET_FETCH),)
-  TOOL_WGET_FETCH := $(wildcard $(PATH_DEVTOOLS_BLD)/bin/wget$(HOSTSUFF_EXE))
+  TOOL_WGET_FETCH := $(wildcard $(KBUILD_DEVTOOLS_BLD)/bin/wget$(HOSTSUFF_EXE))
  endif
  ifneq ($(TOOL_WGET_FETCH),)
   TOOL_WGET_FETCH := $(lastword $(sort $(TOOL_WGET_FETCH)))
diff --git a/kBuild/tools/XGCCAMD64LINUX.kmk b/kBuild/tools/XGCCAMD64LINUX.kmk
index 1e58a0b..2430a8b 100644
--- a/kBuild/tools/XGCCAMD64LINUX.kmk
+++ b/kBuild/tools/XGCCAMD64LINUX.kmk
@@ -1,10 +1,10 @@
-# $Id: XGCCAMD64LINUX.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: XGCCAMD64LINUX.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - GCC Cross compiler for AMD64+Linux.
 #
 
 #
-# Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -43,14 +43,14 @@ else # x-compile:
  ifndef TOOL_XGCCAMD64LINUX_PREFIX
   TOOL_XGCCAMD64LINUX_PREFIX := x86_64-unknown-linux-gnu-
   ifndef PATH_TOOL_XGCCAMD64LINUX
-   PATH_TOOL_XGCCAMD64LINUX := $(sort $(wildcard $(PATH_DEVTOOLS_BLD)/x86_64-unknown-linux-gnu/*))
+   PATH_TOOL_XGCCAMD64LINUX := $(sort $(wildcard $(KBUILD_DEVTOOLS_BLD)/x86_64-unknown-linux-gnu/*))
    ifeq ($(PATH_TOOL_XGCCAMD64LINUX),)
     ifeq ($(filter-out win.amd64,$(KBUILD_HOST).$(KBUILD_HOST_ARCH)),) # these can use the windows build.
      TOOL_XGCCAMD64LINUX_EXEC_PREFIX ?= $(EXEC_X86_WIN32)
      TOOL_XGCCAMD64LINUX_HOSTSUFF_EXE := .exe
-     PATH_TOOL_XGCCAMD64LINUX := $(sort $(wildcard $(PATH_DEVTOOLS)/win.x86/x86_64-unknown-linux-gnu/*))
+     PATH_TOOL_XGCCAMD64LINUX := $(sort $(wildcard $(KBUILD_DEVTOOLS)/win.x86/x86_64-unknown-linux-gnu/*))
      ifeq ($(PATH_TOOL_XGCCAMD64LINUX),)
-      PATH_TOOL_XGCCAMD64LINUX := $(sort $(wildcard $(PATH_DEVTOOLS)/x86.win32/x86_64-unknown-linux-gnu/*))
+      PATH_TOOL_XGCCAMD64LINUX := $(sort $(wildcard $(KBUILD_DEVTOOLS)/x86.win32/x86_64-unknown-linux-gnu/*))
      endif
     endif
    endif
diff --git a/kBuild/tools/YASM.kmk b/kBuild/tools/YASM.kmk
index 8963f14..24a2041 100644
--- a/kBuild/tools/YASM.kmk
+++ b/kBuild/tools/YASM.kmk
@@ -1,10 +1,10 @@
-# $Id: YASM.kmk 2694 2013-07-22 13:39:36Z bird $
+# $Id: YASM.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - YASM 0.4.0 or later.
 #
 
 #
-# Copyright (c) 2006-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2006-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,7 +35,7 @@ TOOL_YASM := YASM v0.4.0+
 
 # Tool Specific Properties
 ifndef PATH_TOOL_YASM
- PATH_TOOL_YASM := $(sort $(wildcard $(PATH_DEVTOOLS_BLD)/yasm/v*.*))
+ PATH_TOOL_YASM := $(sort $(wildcard $(KBUILD_DEVTOOLS_BLD)/yasm/v*.*))
  ifneq ($(PATH_TOOL_YASM),)
   PATH_TOOL_YASM := $(call lastword,$(PATH_TOOL_YASM))
  endif
diff --git a/kBuild/tools/ZIP.kmk b/kBuild/tools/ZIP.kmk
index 11fbf9d..b84f2a4 100644
--- a/kBuild/tools/ZIP.kmk
+++ b/kBuild/tools/ZIP.kmk
@@ -1,10 +1,10 @@
-# $Id: ZIP.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: ZIP.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild Tool Config - The zip/unzip packer/unpacker.
 #
 
 #
-# Copyright (c) 2006-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2006-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -35,12 +35,12 @@ TOOL_ZIP := The zip/unzip packer/unpacker.
 
 # Tool Specific Properties
 ifndef TOOL_ZIP_UNPACK
- TOOL_ZIP_UNPACK := $(wildcard $(PATH_DEVTOOLS_BLD)/unzip/v*/unzip$(HOSTSUFF_EXE))
+ TOOL_ZIP_UNPACK := $(wildcard $(KBUILD_DEVTOOLS_BLD)/unzip/v*/unzip$(HOSTSUFF_EXE))
  ifeq ($(TOOL_ZIP_UNPACK),)
-  TOOL_ZIP_UNPACK := $(wildcard $(PATH_DEVTOOLS_BLD)/zip/v*/unzip$(HOSTSUFF_EXE))
+  TOOL_ZIP_UNPACK := $(wildcard $(KBUILD_DEVTOOLS_BLD)/zip/v*/unzip$(HOSTSUFF_EXE))
  endif
  ifeq ($(TOOL_ZIP_UNPACK),)
-  TOOL_ZIP_UNPACK := $(wildcard $(PATH_DEVTOOLS_BLD)/bin/unzip$(HOSTSUFF_EXE))
+  TOOL_ZIP_UNPACK := $(wildcard $(KBUILD_DEVTOOLS_BLD)/bin/unzip$(HOSTSUFF_EXE))
  endif
  ifneq ($(TOOL_ZIP_UNPACK),)
   TOOL_ZIP_UNPACK := $(lastword $(sort $(TOOL_ZIP_UNPACK)))
@@ -51,12 +51,12 @@ else
  TOOL_ZIP_UNPACK := $(TOOL_ZIP_UNPACK)
 endif
 #ifndef TOOL_ZIP_PACK
-# TOOL_ZIP_PACK := $(wildcard $(PATH_DEVTOOLS_BLD)/zip/v*/zip$(HOSTSUFF_EXE))
+# TOOL_ZIP_PACK := $(wildcard $(KBUILD_DEVTOOLS_BLD)/zip/v*/zip$(HOSTSUFF_EXE))
 # ifeq ($(TOOL_ZIP_PACK),)
-#  TOOL_ZIP_PACK := $(wildcard $(PATH_DEVTOOLS_BLD)/unzip/v*/zip$(HOSTSUFF_EXE))
+#  TOOL_ZIP_PACK := $(wildcard $(KBUILD_DEVTOOLS_BLD)/unzip/v*/zip$(HOSTSUFF_EXE))
 # endif
 # ifeq ($(TOOL_ZIP_PACK),)
-#  TOOL_ZIP_PACK := $(wildcard $(PATH_DEVTOOLS_BLD)/bin/zip$(HOSTSUFF_EXE))
+#  TOOL_ZIP_PACK := $(wildcard $(KBUILD_DEVTOOLS_BLD)/bin/zip$(HOSTSUFF_EXE))
 # endif
 # ifneq ($(TOOL_ZIP_PACK),)
 #  TOOL_ZIP_PACK := $(lastword $(sort $(TOOL_ZIP_PACK)))
diff --git a/kBuild/units/dtrace.kmk b/kBuild/units/dtrace.kmk
index 794725c..5d79744 100644
--- a/kBuild/units/dtrace.kmk
+++ b/kBuild/units/dtrace.kmk
@@ -1,10 +1,10 @@
-# $Id: dtrace.kmk 2571 2012-04-15 11:12:31Z bird $
+# $Id: dtrace.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # DTrace unit.
 #
 
 #
-# Copyright (c) 2012 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2012-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/units/lex.kmk b/kBuild/units/lex.kmk
index dd294b7..c69cb05 100644
--- a/kBuild/units/lex.kmk
+++ b/kBuild/units/lex.kmk
@@ -1,10 +1,10 @@
-# $Id: lex.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: lex.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # lex unit.
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/units/qt3.kmk b/kBuild/units/qt3.kmk
index 17a4973..6e790e8 100644
--- a/kBuild/units/qt3.kmk
+++ b/kBuild/units/qt3.kmk
@@ -1,10 +1,10 @@
-# $Id: qt3.kmk 2544 2011-09-13 19:00:25Z bird $
+# $Id: qt3.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # Qt 3.3.x unit.
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/units/qt4.kmk b/kBuild/units/qt4.kmk
index c906b97..5558bcd 100644
--- a/kBuild/units/qt4.kmk
+++ b/kBuild/units/qt4.kmk
@@ -1,10 +1,10 @@
-# $Id: qt4.kmk 2544 2011-09-13 19:00:25Z bird $
+# $Id: qt4.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # Qt 4 unit.
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/units/yacc.kmk b/kBuild/units/yacc.kmk
index 18ef3c5..7f96431 100644
--- a/kBuild/units/yacc.kmk
+++ b/kBuild/units/yacc.kmk
@@ -1,10 +1,10 @@
-# $Id: yacc.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: yacc.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # yacc/bison unit.
 #
 
 #
-# Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/kBuild/up.kmk b/kBuild/up.kmk
index 9350160..83d5dc2 100644
--- a/kBuild/up.kmk
+++ b/kBuild/up.kmk
@@ -1,11 +1,11 @@
-# $Id: up.kmk 2413 2010-09-11 17:43:04Z bird $
+# $Id: up.kmk 2726 2014-02-26 23:23:54Z bird $
 ## @file
 # kBuild - File included at top of a up forwarder makefile.
 #          This method is DEPRECATED. Use Makefile.kup files instead.
 #
 
 #
-# Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2005-2014 knut st. osmundsen <bird-kBuild-spam-xiv at anduin.net>
 #
 # This file is part of kBuild.
 #
diff --git a/src/ash/Makefile b/src/ash/Makefile
deleted file mode 100644
index 11f4be2..0000000
--- a/src/ash/Makefile
+++ /dev/null
@@ -1,79 +0,0 @@
-#	$NetBSD: Makefile,v 1.80 2005/06/26 19:10:49 christos Exp $
-#	@(#)Makefile	8.4 (Berkeley) 5/5/95
-
-.include <bsd.own.mk>
-
-YHEADER=1
-PROG=	sh
-SHSRCS=	alias.c cd.c echo.c error.c eval.c exec.c expand.c \
-	histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \
-	mystring.c options.c parser.c redir.c show.c trap.c output.c var.c \
-	test.c kill.c syntax.c
-GENSRCS=arith.c arith_lex.c builtins.c init.c nodes.c
-GENHDRS=arith.h builtins.h nodes.h token.h
-SRCS=	${SHSRCS} ${GENSRCS}
-
-DPSRCS+=${GENHDRS}
-
-LDADD+=	-ll -ledit -ltermcap
-DPADD+=	${LIBL} ${LIBEDIT} ${LIBTERMCAP}
-
-LFLAGS=	-8	# 8-bit lex scanner for arithmetic
-YFLAGS=	-d
-
-# The .depend file can get references to these temporary files
-.OPTIONAL: lex.yy.c y.tab.c
-
-.ifdef CRUNCHEDPROG
-LFLAGS+=-L
-YFLAGS+=-l
-.endif
-
-CPPFLAGS+=-DSHELL -I. -I${.CURDIR}
-#XXX: For testing only.
-#CPPFLAGS+=-DDEBUG=1
-#CFLAGS+=-funsigned-char
-#TARGET_CHARFLAG?= -DTARGET_CHAR="unsigned char" -funsigned-char
-
-.ifdef SMALLPROG
-CPPFLAGS+=-DSMALL
-.else
-SRCS+=printf.c
-.endif
-
-.PATH:	${.CURDIR}/bltin ${NETBSDSRCDIR}/bin/test \
-	${NETBSDSRCDIR}/usr.bin/printf \
-	${NETBSDSRCDIR}/bin/kill
-
-CLEANFILES+= ${GENSRCS} ${GENHDRS} y.tab.h
-CLEANFILES+= trace
-
-token.h: mktokens
-	${_MKTARGET_CREATE}
-	${HOST_SH} ${.ALLSRC}
-
-builtins.h: builtins.c
-	${_MKTARGET_CREATE}
-
-builtins.c: mkbuiltins shell.h builtins.def
-	${_MKTARGET_CREATE}
-	${HOST_SH} ${.ALLSRC} ${.OBJDIR}
-	[ -f builtins.h ]
-
-init.c: mkinit.sh ${SHSRCS}
-	${_MKTARGET_CREATE}
-	${HOST_SH} ${.ALLSRC}
-
-nodes.h: nodes.c
-
-nodes.c: mknodes.sh nodetypes nodes.c.pat
-	${_MKTARGET_CREATE}
-	${HOST_SH} ${.ALLSRC} ${.OBJDIR}
-	[ -f nodes.h ]
-
-.if ${USETOOLS} == "yes"
-COMPATOBJDIR!=	cd ${NETBSDSRCDIR}/tools/compat && ${PRINTOBJDIR}
-NBCOMPATLIB=	-L${COMPATOBJDIR} -lnbcompat
-.endif
-
-.include <bsd.prog.mk>
diff --git a/src/ash/Makefile.kmk b/src/ash/Makefile.kmk
deleted file mode 100644
index 44e49e9..0000000
--- a/src/ash/Makefile.kmk
+++ /dev/null
@@ -1,192 +0,0 @@
-# $Id: $
-## @file
-# Sub-makefile for kmk_ash.
-#
-
-#
-# Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
-#
-# This file is part of kBuild.
-#
-# kBuild is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# kBuild is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with kBuild.  If not, see <http://www.gnu.org/licenses/>
-#
-#
-
-SUB_DEPTH = ../..
-include $(KBUILD_PATH)/subheader.kmk
-
-#INSTALLS = ash.man
-
-PROGRAMS += kmk_ash
-kmk_ash_TEMPLATE = BIN
-kmk_ash_DEFS = lint SHELL SMALL KMK
-if "$(USER)" == "bird"
-kmk_ash_DEFS.debug = DEBUG=2
-endif
-kmk_ash_DEFS.linux = BSD
-kmk_ash_DEFS.solaris = BSD
-kmk_ash_DEFS.win = \
-	BSD PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS PC_SLASHES
-kmk_ash_DEFS.os2 = \
-	HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME \
-	EXEC_HASH_BANG_SCRIPT PC_OS2_LIBPATHS PC_PATH_SEP PC_DRIVE_LETTERS PC_EXE_EXTS PC_SLASHES
-kmk_ash_DEFS.darwin = \
-	HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
-kmk_ash_DEFS.dragonfly = \
-	HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
-kmk_ash_DEFS.freebsd = \
-	HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
-kmk_ash_DEFS.openbsd = \
-	HAVE_SYS_SIGNAME HAVE_SYSCTL_H HAVE_SETPROGNAME
-kmk_ash_INCS = $(kmk_ash_0_OUTDIR) . # (the last is because of error.h)
-kmk_ash_CFLAGS.win = -I. ## @todo kBuild bug?
-kmk_ash_INCS.win = win
-kmk_ash_SOURCES = \
-	alias.c \
-	cd.c \
-	error.c \
-	eval.c \
-	exec.c \
-	expand.c \
-	histedit.c \
-	input.c \
-	jobs.c \
-	mail.c \
-	main.c \
-	memalloc.c \
-	miscbltin.c \
-	mystring.c \
-	options.c \
-	output.c \
-	parser.c \
-	redir.c \
-	show.c \
-	syntax.c \
-	trap.c \
-	var.c \
-	bltin/echo.c \
-	bltin/kill.c \
-	bltin/test.c \
-	$(kmk_ash_0_OUTDIR)/builtins.c \
-	$(kmk_ash_0_OUTDIR)/init.c \
-	$(kmk_ash_0_OUTDIR)/nodes.c
-kmk_ash_SOURCES.linux = \
-	sys_signame.c \
-	strlcpy.c \
-	setmode.c
-kmk_ash_SOURCES.win = \
-	win/mscfakes.c \
-	win/err.c \
-	win/dirent.c \
-	sys_signame.c \
-	strlcpy.c \
-	setmode.c
-kmk_ash_SOURCES.solaris = \
-	sys_signame.c \
-	strlcpy.c \
-	setmode.c
-
-kmk_ash_INTERMEDIATES = \
-	$(kmk_ash_0_OUTDIR)/builtins.h \
-	$(kmk_ash_0_OUTDIR)/nodes.h \
-	$(kmk_ash_0_OUTDIR)/token.h
-kmk_ash_CLEAN = \
-	$(kmk_ash_INTERMEDIATES) \
-	$(kmk_ash_0_OUTDIR)/builtins.c \
-	$(kmk_ash_0_OUTDIR)/init.c \
-	$(kmk_ash_0_OUTDIR)/nodes.c
-
-kmk_ash.man_TEMPLATE = usr.bin.man
-kmk_ash.man_SOURCES = \
-	sh.1=>ash.1
-#ash.man_SYMLINKS = \
-#	ash.1.gz=>sh.1
-
-if1of ($(KBUILD_TARGET), win nt)
-#
-# Use the pregenerated code.
-#
-kmk_ash_DEPS :=
-kmk_ash_SOURCES += $(kmk_ash_0_OUTDIR)/arith_lex.c
-
-include $(FILE_KBUILD_SUB_FOOTER)
-
-define def_copy_generated
-$(kmk_ash_0_OUTDIR)/$(src): generated/$(src)
-	$$(RM) -f $$@
-	$$(CP) -f $$^ $$@
-endef
-
-$(foreach src, arith.h arith.c arith_lex.c builtins.h builtins.c nodes.h nodes.c token.h init.c,\
-$(eval $(def_copy_generated)))
-
-
-else
-#
-# Generate the code on the fly.
-#
-
-USES += lex yacc
-kmk_ash_USES = lex yacc
-kmk_ash_LEXTOOL = FLEX
-kmk_ash_LEXFLAGS = -8
-#kmk_ash_YACCTOOL = BISON
-kmk_ash_YACCTOOL = YACC
-kmk_ash_YACCFLAGS = -ld
-kmk_ash_SOURCES += \
-	arith.y \
-	arith_lex.l
-
-
-include $(FILE_KBUILD_SUB_FOOTER)
-
-#
-# ATTENTION! ATTENTION! ATTENTION!
-#
-# Older ash versions has trouble with some of these scripts, great.
-# Kudos to the NetBSD guys for this clever move. ;)
-#
-# So, when building for the frist time, setting BOOSTRAP_SHELL=/bin/bash is good idea.
-#
-BOOTSTRAP_SHELL ?= $(SHELL)
-
-$(kmk_ash_0_OUTDIR)/builtins.h + $(kmk_ash_0_OUTDIR)/builtins.c: \
-		$(kmk_ash_PATH)/mkbuiltins \
-		$(kmk_ash_PATH)/shell.h \
-		$(kmk_ash_PATH)/builtins.def \
-		| $(call DIRDEP,$(kmk_ash_0_OUTDIR))
-	$(BOOTSTRAP_SHELL) $+ $(dir $@)
-	[ -f $(kmk_ash_0_OUTDIR)/builtins.h ]
-
-$(kmk_ash_0_OUTDIR)/nodes.h + $(kmk_ash_0_OUTDIR)/nodes.c: \
-		$(kmk_ash_PATH)/mknodes.sh \
-		$(kmk_ash_PATH)/nodetypes \
-		$(kmk_ash_PATH)/nodes.c.pat \
-		| $(call DIRDEP,$(kmk_ash_0_OUTDIR))
-	$(BOOTSTRAP_SHELL) $+ $(dir $@)
-	[ -f $(dir $@)/nodes.h ]
-
-$(kmk_ash_0_OUTDIR)/token.h: $(kmk_ash_PATH)/mktokens | $(call DIRDEP,$(kmk_ash_0_OUTDIR))
-	$(BOOTSTRAP_SHELL) $+
-	$(MV) token.h $@
-
-$(kmk_ash_0_OUTDIR)/init.c: \
-		$(kmk_ash_PATH)/mkinit.sh \
-		$(abspathex $(filter-out $(kmk_ash_0_OUTDIR)/%,$(kmk_ash_SOURCES)), $(kmk_ash_PATH)) \
-		| $(call DIRDEP,$(kmk_ash_0_OUTDIR))
-	$(BOOTSTRAP_SHELL) $+
-	$(MV) init.c $@
-
-endif # generate on the fly
-
diff --git a/src/ash/TOUR b/src/ash/TOUR
deleted file mode 100644
index f5c00c4..0000000
--- a/src/ash/TOUR
+++ /dev/null
@@ -1,357 +0,0 @@
-#	$NetBSD: TOUR,v 1.8 1996/10/16 14:24:56 christos Exp $
-#	@(#)TOUR	8.1 (Berkeley) 5/31/93
-
-NOTE -- This is the original TOUR paper distributed with ash and
-does not represent the current state of the shell.  It is provided anyway
-since it provides helpful information for how the shell is structured,
-but be warned that things have changed -- the current shell is
-still under development.
-
-================================================================
-
-                       A Tour through Ash
-
-               Copyright 1989 by Kenneth Almquist.
-
-
-DIRECTORIES:  The subdirectory bltin contains commands which can
-be compiled stand-alone.  The rest of the source is in the main
-ash directory.
-
-SOURCE CODE GENERATORS:  Files whose names begin with "mk" are
-programs that generate source code.  A complete list of these
-programs is:
-
-        program         intput files        generates
-        -------         ------------        ---------
-        mkbuiltins      builtins            builtins.h builtins.c
-        mkinit          *.c                 init.c
-        mknodes         nodetypes           nodes.h nodes.c
-        mksignames          -               signames.h signames.c
-        mksyntax            -               syntax.h syntax.c
-        mktokens            -               token.h
-        bltin/mkexpr    unary_op binary_op  operators.h operators.c
-
-There are undoubtedly too many of these.  Mkinit searches all the
-C source files for entries looking like:
-
-        INIT {
-              x = 1;    /* executed during initialization */
-        }
-
-        RESET {
-              x = 2;    /* executed when the shell does a longjmp
-                           back to the main command loop */
-        }
-
-        SHELLPROC {
-              x = 3;    /* executed when the shell runs a shell procedure */
-        }
-
-It pulls this code out into routines which are when particular
-events occur.  The intent is to improve modularity by isolating
-the information about which modules need to be explicitly
-initialized/reset within the modules themselves.
-
-Mkinit recognizes several constructs for placing declarations in
-the init.c file.
-        INCLUDE "file.h"
-includes a file.  The storage class MKINIT makes a declaration
-available in the init.c file, for example:
-        MKINIT int funcnest;    /* depth of function calls */
-MKINIT alone on a line introduces a structure or union declara-
-tion:
-        MKINIT
-        struct redirtab {
-              short renamed[10];
-        };
-Preprocessor #define statements are copied to init.c without any
-special action to request this.
-
-INDENTATION:  The ash source is indented in multiples of six
-spaces.  The only study that I have heard of on the subject con-
-cluded that the optimal amount to indent is in the range of four
-to six spaces.  I use six spaces since it is not too big a jump
-from the widely used eight spaces.  If you really hate six space
-indentation, use the adjind (source included) program to change
-it to something else.
-
-EXCEPTIONS:  Code for dealing with exceptions appears in
-exceptions.c.  The C language doesn't include exception handling,
-so I implement it using setjmp and longjmp.  The global variable
-exception contains the type of exception.  EXERROR is raised by
-calling error.  EXINT is an interrupt.  EXSHELLPROC is an excep-
-tion which is raised when a shell procedure is invoked.  The pur-
-pose of EXSHELLPROC is to perform the cleanup actions associated
-with other exceptions.  After these cleanup actions, the shell
-can interpret a shell procedure itself without exec'ing a new
-copy of the shell.
-
-INTERRUPTS:  In an interactive shell, an interrupt will cause an
-EXINT exception to return to the main command loop.  (Exception:
-EXINT is not raised if the user traps interrupts using the trap
-command.)  The INTOFF and INTON macros (defined in exception.h)
-provide uninterruptable critical sections.  Between the execution
-of INTOFF and the execution of INTON, interrupt signals will be
-held for later delivery.  INTOFF and INTON can be nested.
-
-MEMALLOC.C:  Memalloc.c defines versions of malloc and realloc
-which call error when there is no memory left.  It also defines a
-stack oriented memory allocation scheme.  Allocating off a stack
-is probably more efficient than allocation using malloc, but the
-big advantage is that when an exception occurs all we have to do
-to free up the memory in use at the time of the exception is to
-restore the stack pointer.  The stack is implemented using a
-linked list of blocks.
-
-STPUTC:  If the stack were contiguous, it would be easy to store
-strings on the stack without knowing in advance how long the
-string was going to be:
-        p = stackptr;
-        *p++ = c;       /* repeated as many times as needed */
-        stackptr = p;
-The folloing three macros (defined in memalloc.h) perform these
-operations, but grow the stack if you run off the end:
-        STARTSTACKSTR(p);
-        STPUTC(c, p);   /* repeated as many times as needed */
-        grabstackstr(p);
-
-We now start a top-down look at the code:
-
-MAIN.C:  The main routine performs some initialization, executes
-the user's profile if necessary, and calls cmdloop.  Cmdloop is
-repeatedly parses and executes commands.
-
-OPTIONS.C:  This file contains the option processing code.  It is
-called from main to parse the shell arguments when the shell is
-invoked, and it also contains the set builtin.  The -i and -j op-
-tions (the latter turns on job control) require changes in signal
-handling.  The routines setjobctl (in jobs.c) and setinteractive
-(in trap.c) are called to handle changes to these options.
-
-PARSING:  The parser code is all in parser.c.  A recursive des-
-cent parser is used.  Syntax tables (generated by mksyntax) are
-used to classify characters during lexical analysis.  There are
-three tables:  one for normal use, one for use when inside single
-quotes, and one for use when inside double quotes.  The tables
-are machine dependent because they are indexed by character vari-
-ables and the range of a char varies from machine to machine.
-
-PARSE OUTPUT:  The output of the parser consists of a tree of
-nodes.  The various types of nodes are defined in the file node-
-types.
-
-Nodes of type NARG are used to represent both words and the con-
-tents of here documents.  An early version of ash kept the con-
-tents of here documents in temporary files, but keeping here do-
-cuments in memory typically results in significantly better per-
-formance.  It would have been nice to make it an option to use
-temporary files for here documents, for the benefit of small
-machines, but the code to keep track of when to delete the tem-
-porary files was complex and I never fixed all the bugs in it.
-(AT&T has been maintaining the Bourne shell for more than ten
-years, and to the best of my knowledge they still haven't gotten
-it to handle temporary files correctly in obscure cases.)
-
-The text field of a NARG structure points to the text of the
-word.  The text consists of ordinary characters and a number of
-special codes defined in parser.h.  The special codes are:
-
-        CTLVAR              Variable substitution
-        CTLENDVAR           End of variable substitution
-        CTLBACKQ            Command substitution
-        CTLBACKQ|CTLQUOTE   Command substitution inside double quotes
-        CTLESC              Escape next character
-
-A variable substitution contains the following elements:
-
-        CTLVAR type name '=' [ alternative-text CTLENDVAR ]
-
-The type field is a single character specifying the type of sub-
-stitution.  The possible types are:
-
-        VSNORMAL            $var
-        VSMINUS             ${var-text}
-        VSMINUS|VSNUL       ${var:-text}
-        VSPLUS              ${var+text}
-        VSPLUS|VSNUL        ${var:+text}
-        VSQUESTION          ${var?text}
-        VSQUESTION|VSNUL    ${var:?text}
-        VSASSIGN            ${var=text}
-        VSASSIGN|VSNUL      ${var=text}
-
-In addition, the type field will have the VSQUOTE flag set if the
-variable is enclosed in double quotes.  The name of the variable
-comes next, terminated by an equals sign.  If the type is not
-VSNORMAL, then the text field in the substitution follows, ter-
-minated by a CTLENDVAR byte.
-
-Commands in back quotes are parsed and stored in a linked list.
-The locations of these commands in the string are indicated by
-CTLBACKQ and CTLBACKQ+CTLQUOTE characters, depending upon whether
-the back quotes were enclosed in double quotes.
-
-The character CTLESC escapes the next character, so that in case
-any of the CTL characters mentioned above appear in the input,
-they can be passed through transparently.  CTLESC is also used to
-escape '*', '?', '[', and '!' characters which were quoted by the
-user and thus should not be used for file name generation.
-
-CTLESC characters have proved to be particularly tricky to get
-right.  In the case of here documents which are not subject to
-variable and command substitution, the parser doesn't insert any
-CTLESC characters to begin with (so the contents of the text
-field can be written without any processing).  Other here docu-
-ments, and words which are not subject to splitting and file name
-generation, have the CTLESC characters removed during the vari-
-able and command substitution phase.  Words which are subject
-splitting and file name generation have the CTLESC characters re-
-moved as part of the file name phase.
-
-EXECUTION:  Command execution is handled by the following files:
-        eval.c     The top level routines.
-        redir.c    Code to handle redirection of input and output.
-        jobs.c     Code to handle forking, waiting, and job control.
-        exec.c     Code to to path searches and the actual exec sys call.
-        expand.c   Code to evaluate arguments.
-        var.c      Maintains the variable symbol table.  Called from expand.c.
-
-EVAL.C:  Evaltree recursively executes a parse tree.  The exit
-status is returned in the global variable exitstatus.  The alter-
-native entry evalbackcmd is called to evaluate commands in back
-quotes.  It saves the result in memory if the command is a buil-
-tin; otherwise it forks off a child to execute the command and
-connects the standard output of the child to a pipe.
-
-JOBS.C:  To create a process, you call makejob to return a job
-structure, and then call forkshell (passing the job structure as
-an argument) to create the process.  Waitforjob waits for a job
-to complete.  These routines take care of process groups if job
-control is defined.
-
-REDIR.C:  Ash allows file descriptors to be redirected and then
-restored without forking off a child process.  This is accom-
-plished by duplicating the original file descriptors.  The redir-
-tab structure records where the file descriptors have be dupli-
-cated to.
-
-EXEC.C:  The routine find_command locates a command, and enters
-the command in the hash table if it is not already there.  The
-third argument specifies whether it is to print an error message
-if the command is not found.  (When a pipeline is set up,
-find_command is called for all the commands in the pipeline be-
-fore any forking is done, so to get the commands into the hash
-table of the parent process.  But to make command hashing as
-transparent as possible, we silently ignore errors at that point
-and only print error messages if the command cannot be found
-later.)
-
-The routine shellexec is the interface to the exec system call.
-
-EXPAND.C:  Arguments are processed in three passes.  The first
-(performed by the routine argstr) performs variable and command
-substitution.  The second (ifsbreakup) performs word splitting
-and the third (expandmeta) performs file name generation.  If the
-"/u" directory is simulated, then when "/u/username" is replaced
-by the user's home directory, the flag "didudir" is set.  This
-tells the cd command that it should print out the directory name,
-just as it would if the "/u" directory were implemented using
-symbolic links.
-
-VAR.C:  Variables are stored in a hash table.  Probably we should
-switch to extensible hashing.  The variable name is stored in the
-same string as the value (using the format "name=value") so that
-no string copying is needed to create the environment of a com-
-mand.  Variables which the shell references internally are preal-
-located so that the shell can reference the values of these vari-
-ables without doing a lookup.
-
-When a program is run, the code in eval.c sticks any environment
-variables which precede the command (as in "PATH=xxx command") in
-the variable table as the simplest way to strip duplicates, and
-then calls "environment" to get the value of the environment.
-There are two consequences of this.  First, if an assignment to
-PATH precedes the command, the value of PATH before the assign-
-ment must be remembered and passed to shellexec.  Second, if the
-program turns out to be a shell procedure, the strings from the
-environment variables which preceded the command must be pulled
-out of the table and replaced with strings obtained from malloc,
-since the former will automatically be freed when the stack (see
-the entry on memalloc.c) is emptied.
-
-BUILTIN COMMANDS:  The procedures for handling these are scat-
-tered throughout the code, depending on which location appears
-most appropriate.  They can be recognized because their names al-
-ways end in "cmd".  The mapping from names to procedures is
-specified in the file builtins, which is processed by the mkbuil-
-tins command.
-
-A builtin command is invoked with argc and argv set up like a
-normal program.  A builtin command is allowed to overwrite its
-arguments.  Builtin routines can call nextopt to do option pars-
-ing.  This is kind of like getopt, but you don't pass argc and
-argv to it.  Builtin routines can also call error.  This routine
-normally terminates the shell (or returns to the main command
-loop if the shell is interactive), but when called from a builtin
-command it causes the builtin command to terminate with an exit
-status of 2.
-
-The directory bltins contains commands which can be compiled in-
-dependently but can also be built into the shell for efficiency
-reasons.  The makefile in this directory compiles these programs
-in the normal fashion (so that they can be run regardless of
-whether the invoker is ash), but also creates a library named
-bltinlib.a which can be linked with ash.  The header file bltin.h
-takes care of most of the differences between the ash and the
-stand-alone environment.  The user should call the main routine
-"main", and #define main to be the name of the routine to use
-when the program is linked into ash.  This #define should appear
-before bltin.h is included; bltin.h will #undef main if the pro-
-gram is to be compiled stand-alone.
-
-CD.C:  This file defines the cd and pwd builtins.  The pwd com-
-mand runs /bin/pwd the first time it is invoked (unless the user
-has already done a cd to an absolute pathname), but then
-remembers the current directory and updates it when the cd com-
-mand is run, so subsequent pwd commands run very fast.  The main
-complication in the cd command is in the docd command, which
-resolves symbolic links into actual names and informs the user
-where the user ended up if he crossed a symbolic link.
-
-SIGNALS:  Trap.c implements the trap command.  The routine set-
-signal figures out what action should be taken when a signal is
-received and invokes the signal system call to set the signal ac-
-tion appropriately.  When a signal that a user has set a trap for
-is caught, the routine "onsig" sets a flag.  The routine dotrap
-is called at appropriate points to actually handle the signal.
-When an interrupt is caught and no trap has been set for that
-signal, the routine "onint" in error.c is called.
-
-OUTPUT:  Ash uses it's own output routines.  There are three out-
-put structures allocated.  "Output" represents the standard out-
-put, "errout" the standard error, and "memout" contains output
-which is to be stored in memory.  This last is used when a buil-
-tin command appears in backquotes, to allow its output to be col-
-lected without doing any I/O through the UNIX operating system.
-The variables out1 and out2 normally point to output and errout,
-respectively, but they are set to point to memout when appropri-
-ate inside backquotes.
-
-INPUT:  The basic input routine is pgetc, which reads from the
-current input file.  There is a stack of input files; the current
-input file is the top file on this stack.  The code allows the
-input to come from a string rather than a file.  (This is for the
--c option and the "." and eval builtin commands.)  The global
-variable plinno is saved and restored when files are pushed and
-popped from the stack.  The parser routines store the number of
-the current line in this variable.
-
-DEBUGGING:  If DEBUG is defined in shell.h, then the shell will
-write debugging information to the file $HOME/trace.  Most of
-this is done using the TRACE macro, which takes a set of printf
-arguments inside two sets of parenthesis.  Example:
-"TRACE(("n=%d0, n))".  The double parenthesis are necessary be-
-cause the preprocessor can't handle functions with a variable
-number of arguments.  Defining DEBUG also causes the shell to
-generate a core dump if it is sent a quit signal.  The tracing
-code is in show.c.
diff --git a/src/ash/alias.c b/src/ash/alias.c
deleted file mode 100644
index caad2ad..0000000
--- a/src/ash/alias.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*	$NetBSD: alias.c,v 1.12 2003/08/07 09:05:29 agc Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)alias.c	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: alias.c,v 1.12 2003/08/07 09:05:29 agc Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#include "shell.h"
-#include "input.h"
-#include "output.h"
-#include "error.h"
-#include "memalloc.h"
-#include "mystring.h"
-#include "alias.h"
-#include "options.h"	/* XXX for argptr (should remove?) */
-#include "var.h"
-
-#define ATABSIZE 39
-
-struct alias *atab[ATABSIZE];
-
-STATIC void setalias(char *, char *);
-STATIC int unalias(char *);
-STATIC struct alias **hashalias(char *);
-
-STATIC
-void
-setalias(char *name, char *val)
-{
-	struct alias *ap, **app;
-
-	app = hashalias(name);
-	for (ap = *app; ap; ap = ap->next) {
-		if (equal(name, ap->name)) {
-			INTOFF;
-			ckfree(ap->val);
-			ap->val	= savestr(val);
-			INTON;
-			return;
-		}
-	}
-	/* not found */
-	INTOFF;
-	ap = ckmalloc(sizeof (struct alias));
-	ap->name = savestr(name);
-	/*
-	 * XXX - HACK: in order that the parser will not finish reading the
-	 * alias value off the input before processing the next alias, we
-	 * dummy up an extra space at the end of the alias.  This is a crock
-	 * and should be re-thought.  The idea (if you feel inclined to help)
-	 * is to avoid alias recursions.  The mechanism used is: when
-	 * expanding an alias, the value of the alias is pushed back on the
-	 * input as a string and a pointer to the alias is stored with the
-	 * string.  The alias is marked as being in use.  When the input
-	 * routine finishes reading the string, it markes the alias not
-	 * in use.  The problem is synchronization with the parser.  Since
-	 * it reads ahead, the alias is marked not in use before the
-	 * resulting token(s) is next checked for further alias sub.  The
-	 * H A C K is that we add a little fluff after the alias value
-	 * so that the string will not be exhausted.  This is a good
-	 * idea ------- ***NOT***
-	 */
-#ifdef notyet
-	ap->val = savestr(val);
-#else /* hack */
-	{
-	int len = strlen(val);
-	ap->val = ckmalloc(len + 2);
-	memcpy(ap->val, val, len);
-	ap->val[len] = ' ';	/* fluff */
-	ap->val[len+1] = '\0';
-	}
-#endif
-	ap->next = *app;
-	*app = ap;
-	INTON;
-}
-
-STATIC int
-unalias(char *name)
-{
-	struct alias *ap, **app;
-
-	app = hashalias(name);
-
-	for (ap = *app; ap; app = &(ap->next), ap = ap->next) {
-		if (equal(name, ap->name)) {
-			/*
-			 * if the alias is currently in use (i.e. its
-			 * buffer is being used by the input routine) we
-			 * just null out the name instead of freeing it.
-			 * We could clear it out later, but this situation
-			 * is so rare that it hardly seems worth it.
-			 */
-			if (ap->flag & ALIASINUSE)
-				*ap->name = '\0';
-			else {
-				INTOFF;
-				*app = ap->next;
-				ckfree(ap->name);
-				ckfree(ap->val);
-				ckfree(ap);
-				INTON;
-			}
-			return (0);
-		}
-	}
-
-	return (1);
-}
-
-#ifdef mkinit
-MKINIT void rmaliases(void);
-
-SHELLPROC {
-	rmaliases();
-}
-#endif
-
-void
-rmaliases(void)
-{
-	struct alias *ap, *tmp;
-	int i;
-
-	INTOFF;
-	for (i = 0; i < ATABSIZE; i++) {
-		ap = atab[i];
-		atab[i] = NULL;
-		while (ap) {
-			ckfree(ap->name);
-			ckfree(ap->val);
-			tmp = ap;
-			ap = ap->next;
-			ckfree(tmp);
-		}
-	}
-	INTON;
-}
-
-struct alias *
-lookupalias(char *name, int check)
-{
-	struct alias *ap = *hashalias(name);
-
-	for (; ap; ap = ap->next) {
-		if (equal(name, ap->name)) {
-			if (check && (ap->flag & ALIASINUSE))
-				return (NULL);
-			return (ap);
-		}
-	}
-
-	return (NULL);
-}
-
-char *
-get_alias_text(char *name)
-{
-	struct alias *ap;
-
-	ap = lookupalias(name, 0);
-	if (ap == NULL)
-		return NULL;
-	return ap->val;
-}
-
-/*
- * TODO - sort output
- */
-int
-aliascmd(int argc, char **argv)
-{
-	char *n, *v;
-	int ret = 0;
-	struct alias *ap;
-
-	if (argc == 1) {
-		int i;
-
-		for (i = 0; i < ATABSIZE; i++)
-			for (ap = atab[i]; ap; ap = ap->next) {
-				if (*ap->name != '\0') {
-					out1fmt("alias %s=", ap->name);
-					print_quoted(ap->val);
-					out1c('\n');
-				}
-			}
-		return (0);
-	}
-	while ((n = *++argv) != NULL) {
-		if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
-			if ((ap = lookupalias(n, 0)) == NULL) {
-				outfmt(out2, "alias: %s not found\n", n);
-				ret = 1;
-			} else {
-				out1fmt("alias %s=", n);
-				print_quoted(ap->val);
-				out1c('\n');
-			}
-		} else {
-			*v++ = '\0';
-			setalias(n, v);
-		}
-	}
-
-	return (ret);
-}
-
-int
-unaliascmd(int argc, char **argv)
-{
-	int i;
-
-	while ((i = nextopt("a")) != '\0') {
-		if (i == 'a') {
-			rmaliases();
-			return (0);
-		}
-	}
-	for (i = 0; *argptr; argptr++)
-		i = unalias(*argptr);
-
-	return (i);
-}
-
-STATIC struct alias **
-hashalias(char *p)
-{
-	unsigned int hashval;
-
-	hashval = *p << 4;
-	while (*p)
-		hashval+= *p++;
-	return &atab[hashval % ATABSIZE];
-}
diff --git a/src/ash/alias.h b/src/ash/alias.h
deleted file mode 100644
index 7ce25f4..0000000
--- a/src/ash/alias.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*	$NetBSD: alias.h,v 1.6 2003/08/07 09:05:29 agc Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)alias.h	8.2 (Berkeley) 5/4/95
- */
-
-#define ALIASINUSE	1
-
-struct alias {
-	struct alias *next;
-	char *name;
-	char *val;
-	int flag;
-};
-
-struct alias *lookupalias(char *, int);
-char *get_alias_text(char *);
-int aliascmd(int, char **);
-int unaliascmd(int, char **);
-void rmaliases(void);
diff --git a/src/ash/arith.y b/src/ash/arith.y
deleted file mode 100644
index 9f123f5..0000000
--- a/src/ash/arith.y
+++ /dev/null
@@ -1,202 +0,0 @@
-%{
-/*	$NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)arith.y	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#include "expand.h"
-#include "shell.h"
-#include "error.h"
-#include "output.h"
-#include "memalloc.h"
-
-const char *arith_buf, *arith_startbuf;
-
-void yyerror(const char *);
-#ifdef TESTARITH
-int main(int , char *[]);
-int error(char *);
-#endif
-
-%}
-%token ARITH_NUM ARITH_LPAREN ARITH_RPAREN
-
-%left ARITH_OR
-%left ARITH_AND
-%left ARITH_BOR
-%left ARITH_BXOR
-%left ARITH_BAND
-%left ARITH_EQ ARITH_NE
-%left ARITH_LT ARITH_GT ARITH_GE ARITH_LE
-%left ARITH_LSHIFT ARITH_RSHIFT
-%left ARITH_ADD ARITH_SUB
-%left ARITH_MUL ARITH_DIV ARITH_REM
-%left ARITH_UNARYMINUS ARITH_UNARYPLUS ARITH_NOT ARITH_BNOT
-%%
-
-exp:	expr {
-			return ($1);
-		}
-	;
-
-
-expr:	ARITH_LPAREN expr ARITH_RPAREN { $$ = $2; }
-	| expr ARITH_OR expr	{ $$ = $1 ? $1 : $3 ? $3 : 0; }
-	| expr ARITH_AND expr	{ $$ = $1 ? ( $3 ? $3 : 0 ) : 0; }
-	| expr ARITH_BOR expr	{ $$ = $1 | $3; }
-	| expr ARITH_BXOR expr	{ $$ = $1 ^ $3; }
-	| expr ARITH_BAND expr	{ $$ = $1 & $3; }
-	| expr ARITH_EQ expr	{ $$ = $1 == $3; }
-	| expr ARITH_GT expr	{ $$ = $1 > $3; }
-	| expr ARITH_GE expr	{ $$ = $1 >= $3; }
-	| expr ARITH_LT expr	{ $$ = $1 < $3; }
-	| expr ARITH_LE expr	{ $$ = $1 <= $3; }
-	| expr ARITH_NE expr	{ $$ = $1 != $3; }
-	| expr ARITH_LSHIFT expr { $$ = $1 << $3; }
-	| expr ARITH_RSHIFT expr { $$ = $1 >> $3; }
-	| expr ARITH_ADD expr	{ $$ = $1 + $3; }
-	| expr ARITH_SUB expr	{ $$ = $1 - $3; }
-	| expr ARITH_MUL expr	{ $$ = $1 * $3; }
-	| expr ARITH_DIV expr	{
-			if ($3 == 0)
-				yyerror("division by zero");
-			$$ = $1 / $3;
-			}
-	| expr ARITH_REM expr   {
-			if ($3 == 0)
-				yyerror("division by zero");
-			$$ = $1 % $3;
-			}
-	| ARITH_NOT expr	{ $$ = !($2); }
-	| ARITH_BNOT expr	{ $$ = ~($2); }
-	| ARITH_SUB expr %prec ARITH_UNARYMINUS { $$ = -($2); }
-	| ARITH_ADD expr %prec ARITH_UNARYPLUS { $$ = $2; }
-	| ARITH_NUM
-	;
-%%
-int
-arith(s)
-	const char *s;
-{
-	long result;
-
-	arith_buf = arith_startbuf = s;
-
-	INTOFF;
-	result = yyparse();
-	arith_lex_reset();	/* reprime lex */
-	INTON;
-
-	return (result);
-}
-
-
-/*
- *  The exp(1) builtin.
- */
-int
-expcmd(argc, argv)
-	int argc;
-	char **argv;
-{
-	const char *p;
-	char *concat;
-	char **ap;
-	long i;
-
-	if (argc > 1) {
-		p = argv[1];
-		if (argc > 2) {
-			/*
-			 * concatenate arguments
-			 */
-			STARTSTACKSTR(concat);
-			ap = argv + 2;
-			for (;;) {
-				while (*p)
-					STPUTC(*p++, concat);
-				if ((p = *ap++) == NULL)
-					break;
-				STPUTC(' ', concat);
-			}
-			STPUTC('\0', concat);
-			p = grabstackstr(concat);
-		}
-	} else
-		p = "";
-
-	i = arith(p);
-
-	out1fmt("%ld\n", i);
-	return (! i);
-}
-
-/*************************/
-#ifdef TEST_ARITH
-#include <stdio.h>
-main(argc, argv)
-	char *argv[];
-{
-	printf("%d\n", exp(argv[1]));
-}
-error(s)
-	char *s;
-{
-	fprintf(stderr, "exp: %s\n", s);
-	exit(1);
-}
-#endif
-
-void
-yyerror(s)
-	const char *s;
-{
-#ifndef YYBISON /* yyerrok references yyerrstatus which is a local variable in yyparse().*/
-	yyerrok;
-#endif
-	yyclearin;
-	arith_lex_reset();	/* reprime lex */
-	error("arithmetic expression: %s: \"%s\"", s, arith_startbuf);
-	/* NOTREACHED */
-}
diff --git a/src/ash/arith_lex.l b/src/ash/arith_lex.l
deleted file mode 100644
index 5502492..0000000
--- a/src/ash/arith_lex.l
+++ /dev/null
@@ -1,105 +0,0 @@
-%option noyywrap
-%{
-/*	$NetBSD: arith_lex.l,v 1.13 2005/03/21 22:37:09 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)arith_lex.l	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: arith_lex.l,v 1.13 2005/03/21 22:37:09 dsl Exp $");
-#endif
-#endif /* not lint */
-
-#include <unistd.h>
-#include "arith.h"
-#include "error.h"
-#include "expand.h"
-#include "var.h"
-
-extern int yylval;
-extern char *arith_buf, *arith_startbuf;
-#undef YY_INPUT
-#define YY_INPUT(buf,result,max) \
-	result = (*buf = *arith_buf++) ? 1 : YY_NULL;
-#define YY_NO_UNPUT
-%}
-
-%%
-[ \t\n]	{ ; }
-0x[0-9a-fA-F]+	{ yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
-0[0-7]*		{ yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
-[1-9][0-9]*	{ yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
-[A-Za-z_][A-Za-z_0-9]*	{ char *v = lookupvar(yytext);
-			if (v) {
-				yylval = strtol(v, &v, 0);
-				if (*v == 0)
-					return ARITH_NUM;
-			}
-			error("arith: syntax error: \"%s\"", arith_startbuf);
-		}
-"("	{ return(ARITH_LPAREN); }
-")"	{ return(ARITH_RPAREN); }
-"||"	{ return(ARITH_OR); }
-"&&"	{ return(ARITH_AND); }
-"|"	{ return(ARITH_BOR); }
-"^"	{ return(ARITH_BXOR); }
-"&"	{ return(ARITH_BAND); }
-"=="	{ return(ARITH_EQ); }
-"!="	{ return(ARITH_NE); }
-">"	{ return(ARITH_GT); }
-">="	{ return(ARITH_GE); }
-"<"	{ return(ARITH_LT); }
-"<="	{ return(ARITH_LE); }
-"<<"	{ return(ARITH_LSHIFT); }
-">>"	{ return(ARITH_RSHIFT); }
-"*"	{ return(ARITH_MUL); }
-"/"	{ return(ARITH_DIV); }
-"%"	{ return(ARITH_REM); }
-"+"	{ return(ARITH_ADD); }
-"-"	{ return(ARITH_SUB); }
-"~"	{ return(ARITH_BNOT); }
-"!"	{ return(ARITH_NOT); }
-.	{ error("arith: syntax error: \"%s\"", arith_startbuf); }
-%%
-
-void
-arith_lex_reset() {
-#ifdef YY_NEW_FILE
-	YY_NEW_FILE;
-#endif
-}
diff --git a/src/ash/bltin/bltin.h b/src/ash/bltin/bltin.h
deleted file mode 100644
index b8f9d75..0000000
--- a/src/ash/bltin/bltin.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*	$NetBSD: bltin.h,v 1.11 2003/08/07 09:05:40 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)bltin.h	8.1 (Berkeley) 5/31/93
- */
-
-/*
- * This file is included by programs which are optionally built into the
- * shell.  If SHELL is defined, we try to map the standard UNIX library
- * routines to ash routines using defines.
- */
-
-#include "../shell.h"
-#include "../mystring.h"
-#ifdef SHELL
-#include "../output.h"
-#include "../error.h"
-#undef stdout
-#undef stderr
-#undef putc
-#undef putchar
-#undef fileno
-#define stdout out1
-#define stderr out2
-#define printf out1fmt
-#define putc(c, file)	outc(c, file)
-#define putchar(c)	out1c(c)
-#define FILE struct output
-#define fprintf outfmt
-#define fputs outstr
-#define fflush flushout
-#define fileno(f) ((f)->fd)
-#define INITARGS(argv)
-#define	err sh_err
-#define	verr sh_verr
-#define	errx sh_errx
-#define	verrx sh_verrx
-#define	warn sh_warn
-#define	vwarn sh_vwarn
-#define	warnx sh_warnx
-#define	vwarnx sh_vwarnx
-#define exit sh_exit
-#define setprogname(s)
-#define getprogname() commandname
-#define setlocate(l,s) 0
-
-#define getenv(p) bltinlookup((p),0)
-
-#else
-#undef NULL
-#include <stdio.h>
-#undef main
-#define INITARGS(argv)	if ((commandname = argv[0]) == NULL) {fputs("Argc is zero\n", stderr); exit(2);} else
-#endif
-
-pointer stalloc(int);
-void error(const char *, ...);
-void sh_warnx(const char *, ...);
-void sh_exit(int) __attribute__((__noreturn__));
-
-int echocmd(int, char **);
-
-
-extern const char *commandname;
diff --git a/src/ash/bltin/echo.1 b/src/ash/bltin/echo.1
deleted file mode 100644
index 7e71fa3..0000000
--- a/src/ash/bltin/echo.1
+++ /dev/null
@@ -1,109 +0,0 @@
-.\"	$NetBSD: echo.1,v 1.13 2003/08/07 09:05:40 agc Exp $
-.\"
-.\" Copyright (c) 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Kenneth Almquist.
-.\" Copyright 1989 by Kenneth Almquist
-.\"
-.\" 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 the University 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 REGENTS 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 REGENTS 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.
-.\"
-.\"	@(#)echo.1	8.1 (Berkeley) 5/31/93
-.\"
-.Dd May 31, 1993
-.Dt ECHO 1
-.Os
-.Sh NAME
-.Nm echo
-.Nd produce message in a shell script
-.Sh SYNOPSIS
-.Nm
-.Op Fl n | Fl e
-.Ar args ...
-.Sh DESCRIPTION
-.Nm
-prints its arguments on the standard output, separated by spaces.
-Unless the
-.Fl n
-option is present, a newline is output following the arguments.
-The
-.Fl e
-option causes
-.Nm
-to treat the escape sequences specially, as described in the following
-paragraph.
-The
-.Fl e
-option is the default, and is provided solely for compatibility with
-other systems.
-Only one of the options
-.Fl n
-and
-.Fl e
-may be given.
-.Pp
-If any of the following sequences of characters is encountered during
-output, the sequence is not output.  Instead, the specified action is
-performed:
-.Bl -tag -width indent
-.It Li \eb
-A backspace character is output.
-.It Li \ec
-Subsequent output is suppressed.  This is normally used at the end of the
-last argument to suppress the trailing newline that
-.Nm
-would otherwise output.
-.It Li \ef
-Output a form feed.
-.It Li \en
-Output a newline character.
-.It Li \er
-Output a carriage return.
-.It Li \et
-Output a (horizontal) tab character.
-.It Li \ev
-Output a vertical tab.
-.It Li \e0 Ns Ar digits
-Output the character whose value is given by zero to three digits.
-If there are zero digits, a nul character is output.
-.It Li \e\e
-Output a backslash.
-.El
-.Sh HINTS
-Remember that backslash is special to the shell and needs to be escaped.
-To output a message to standard error, say
-.Pp
-.D1  echo message \*[Gt]\*[Am]2
-.Sh BUGS
-The octal character escape mechanism
-.Pq Li \e0 Ns Ar digits
-differs from the
-C language mechanism.
-.Pp
-There is no way to force
-.Nm
-to treat its arguments literally, rather than interpreting them as
-options and escape sequences.
diff --git a/src/ash/bltin/echo.c b/src/ash/bltin/echo.c
deleted file mode 100644
index f04f30e..0000000
--- a/src/ash/bltin/echo.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*	$NetBSD: echo.c,v 1.12 2005/02/06 04:43:43 perry Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)echo.c	8.1 (Berkeley) 5/31/93
- */
-
-/*
- * Echo command.
- *
- * echo is steeped in tradition - several of them!
- * netbsd has supported 'echo [-n | -e] args' in spite of -e not being
- * documented anywhere.
- * Posix requires that -n be supported, output from strings containing
- * \ is implementation defined
- * The Single Unix Spec requires that \ escapes be treated as if -e
- * were set, but that -n not be treated as an option.
- * (ksh supports 'echo [-eEn] args', but not -- so that it is actually
- * impossible to actually output '-n')
- *
- * It is suggested that 'printf "%b" "string"' be used to get \ sequences
- * expanded.  printf is now a builtin of netbsd's sh and csh.
- */
-
-#define main echocmd
-
-#include "bltin.h"
-
-int
-main(int argc, char **argv)
-{
-	char **ap;
-	char *p;
-	char c;
-	int count;
-	int nflag = 0;
-	int eflag = 0;
-
-	ap = argv;
-	if (argc)
-		ap++;
-
-	if ((p = *ap) != NULL) {
-		if (equal(p, "-n")) {
-			nflag = 1;
-			ap++;
-		} else if (equal(p, "-e")) {
-			eflag = 1;
-			ap++;
-		}
-	}
-
-	while ((p = *ap++) != NULL) {
-		while ((c = *p++) != '\0') {
-			if (c == '\\' && eflag) {
-				switch (*p++) {
-				case 'a':  c = '\a';  break;	/* bell */
-				case 'b':  c = '\b';  break;
-				case 'c':  return 0;		/* exit */
-				case 'e':  c =  033;  break;	/* escape */
-				case 'f':  c = '\f';  break;
-				case 'n':  c = '\n';  break;
-				case 'r':  c = '\r';  break;
-				case 't':  c = '\t';  break;
-				case 'v':  c = '\v';  break;
-				case '\\':  break;		/* c = '\\' */
-				case '0':
-					c = 0;
-					count = 3;
-					while (--count >= 0 && (unsigned)(*p - '0') < 8)
-						c = (c << 3) + (*p++ - '0');
-					break;
-				default:
-					/* Output the '/' and char following */
-					p--;
-					break;
-				}
-			}
-			putchar(c);
-		}
-		if (*ap)
-			putchar(' ');
-	}
-	if (! nflag)
-		putchar('\n');
-	return 0;
-}
diff --git a/src/ash/bltin/kill.c b/src/ash/bltin/kill.c
deleted file mode 100644
index e03ae8e..0000000
--- a/src/ash/bltin/kill.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/* $NetBSD: kill.c,v 1.23 2003/08/07 09:05:13 agc Exp $ */
-
-/*
- * Copyright (c) 1988, 1993, 1994
- *	The Regents of the University of California.  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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#if !defined(lint) && !defined(SHELL)
-__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\
-	The Regents of the University of California.  All rights reserved.\n");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)kill.c	8.4 (Berkeley) 4/28/95";
-#else
-__RCSID("$NetBSD: kill.c,v 1.23 2003/08/07 09:05:13 agc Exp $");
-#endif
-#endif /* not lint */
-
-#include <ctype.h>
-#ifndef __sun__
-#include <err.h>
-#endif
-#include <errno.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <locale.h>
-#include <sys/ioctl.h>
-
-#ifndef HAVE_SYS_SIGNAME
-extern void init_sys_signame(void);
-extern char sys_signame[NSIG][16];
-#endif
-
-#ifdef SHELL            /* sh (aka ash) builtin */
-#define main killcmd
-#include "bltin/bltin.h"
-#endif /* SHELL */
-
-static void nosig(char *);
-static void printsignals(FILE *);
-static int signame_to_signum(char *);
-static void usage(void);
-int main(int, char *[]);
-
-int
-main(int argc, char *argv[])
-{
-	int errors, numsig, pid;
-	char *ep;
-
-	setprogname(argv[0]);
-	setlocale(LC_ALL, "");
-	if (argc < 2)
-		usage();
-
-	numsig = SIGTERM;
-
-	argc--, argv++;
-	if (strcmp(*argv, "-l") == 0) {
-		argc--, argv++;
-		if (argc > 1)
-			usage();
-		if (argc == 1) {
-			if (isdigit((unsigned char)**argv) == 0)
-				usage();
-			numsig = strtol(*argv, &ep, 10);
-			if (*ep != '\0') {
-				errx(EXIT_FAILURE, "illegal signal number: %s",
-						*argv);
-				/* NOTREACHED */
-			}
-			if (numsig >= 128)
-				numsig -= 128;
-			if (numsig <= 0 || numsig >= NSIG)
-				nosig(*argv);
-#ifndef HAVE_SYS_SIGNAME
-			init_sys_signame();
-#endif
-			printf("%s\n", sys_signame[numsig]);
-			exit(0);
-		}
-		printsignals(stdout);
-		exit(0);
-	}
-
-	if (!strcmp(*argv, "-s")) {
-		argc--, argv++;
-		if (argc < 1) {
-			warnx("option requires an argument -- s");
-			usage();
-		}
-		if (strcmp(*argv, "0")) {
-			if ((numsig = signame_to_signum(*argv)) < 0)
-				nosig(*argv);
-		} else
-			numsig = 0;
-		argc--, argv++;
-	} else if (**argv == '-') {
-		++*argv;
-		if (isalpha((unsigned char)**argv)) {
-			if ((numsig = signame_to_signum(*argv)) < 0)
-				nosig(*argv);
-		} else if (isdigit((unsigned char)**argv)) {
-			numsig = strtol(*argv, &ep, 10);
-			if (!*argv || *ep) {
-				errx(EXIT_FAILURE, "illegal signal number: %s",
-						*argv);
-				/* NOTREACHED */
-			}
-			if (numsig < 0 || numsig >= NSIG)
-				nosig(*argv);
-		} else
-			nosig(*argv);
-		argc--, argv++;
-	}
-
-	if (argc == 0)
-		usage();
-
-	for (errors = 0; argc; argc--, argv++) {
-#ifdef SHELL
-		extern int getjobpgrp(const char *);
-		if (*argv[0] == '%') {
-			pid = getjobpgrp(*argv);
-			if (pid == 0) {
-				warnx("illegal job id: %s", *argv);
-				errors = 1;
-				continue;
-			}
-		} else
-#endif
-		{
-			pid = strtol(*argv, &ep, 10);
-			if (!**argv || *ep) {
-				warnx("illegal process id: %s", *argv);
-				errors = 1;
-				continue;
-			}
-		}
-		if (kill(pid, numsig) == -1) {
-			warn("%s", *argv);
-			errors = 1;
-		}
-#ifdef SHELL
-		/* Wakeup the process if it was suspended, so it can
-		   exit without an explicit 'fg'. */
-		if (numsig == SIGTERM || numsig == SIGHUP)
-			kill(pid, SIGCONT);
-#endif
-	}
-
-	exit(errors);
-	/* NOTREACHED */
-}
-
-static int
-signame_to_signum(char *sig)
-{
-	int n;
-#ifndef HAVE_SYS_SIGNAME
-	init_sys_signame();
-#endif
-	if (strncasecmp(sig, "sig", 3) == 0)
-		sig += 3;
-	for (n = 1; n < NSIG; n++) {
-		if (!strcasecmp(sys_signame[n], sig))
-			return (n);
-	}
-	return (-1);
-}
-
-static void
-nosig(char *name)
-{
-
-	warnx("unknown signal %s; valid signals:", name);
-	printsignals(stderr);
-	exit(1);
-	/* NOTREACHED */
-}
-
-static void
-printsignals(FILE *fp)
-{
-	int sig;
-	int len, nl;
-	const char *name;
-	int termwidth = 80;
-
-#ifdef TIOCGWINSZ
-	if (isatty(fileno(fp))) {
-		struct winsize win;
-		if (ioctl(fileno(fp), TIOCGWINSZ, &win) == 0 && win.ws_col > 0)
-			termwidth = win.ws_col;
-	}
-#else
-#ifndef _MSC_VER
-#warning TIOCGWINSZ is not present.
-#endif
-#endif
-#ifndef HAVE_SYS_SIGNAME
-    init_sys_signame();
-#endif
-
-	for (len = 0, sig = 1; sig < NSIG; sig++) {
-		name = sys_signame[sig];
-		nl = 1 + strlen(name);
-
-		if (len + nl >= termwidth) {
-			fprintf(fp, "\n");
-			len = 0;
-		} else
-			if (len != 0)
-				fprintf(fp, " ");
-		len += nl;
-		fprintf(fp, "%s", name);
-	}
-	if (len != 0)
-		fprintf(fp, "\n");
-}
-
-static void
-usage(void)
-{
-
-	fprintf(stderr, "usage: %s [-s signal_name] pid ...\n"
-	    "       %s -l [exit_status]\n"
-	    "       %s -signal_name pid ...\n"
-	    "       %s -signal_number pid ...\n",
-	    getprogname(), getprogname(), getprogname(), getprogname());
-	exit(1);
-	/* NOTREACHED */
-}
diff --git a/src/ash/bltin/printf.c b/src/ash/bltin/printf.c
deleted file mode 100644
index cbc93d4..0000000
--- a/src/ash/bltin/printf.c
+++ /dev/null
@@ -1,664 +0,0 @@
-/*	$NetBSD: printf.c,v 1.31 2005/03/22 23:55:46 dsl Exp $	*/
-
-/*
- * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if !defined(BUILTIN) && !defined(SHELL)
-__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
-	The Regents of the University of California.  All rights reserved.\n");
-#endif
-#endif
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)printf.c	8.2 (Berkeley) 3/22/95";
-#else
-__RCSID("$NetBSD: printf.c,v 1.31 2005/03/22 23:55:46 dsl Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <limits.h>
-#include <locale.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef __GNUC__
-#define ESCAPE '\e'
-#else
-#define ESCAPE 033
-#endif
-
-static void	 conv_escape_str(char *, void (*)(int));
-static char	*conv_escape(char *, char *);
-static char	*conv_expand(const char *);
-static int	 getchr(void);
-static double	 getdouble(void);
-static int	 getwidth(void);
-static intmax_t	 getintmax(void);
-static uintmax_t getuintmax(void);
-static char	*getstr(void);
-static char	*mklong(const char *, int);
-static void      check_conversion(const char *, const char *);
-static void	 usage(void);
-
-static void	b_count(int);
-static void	b_output(int);
-static size_t	b_length;
-static char	*b_fmt;
-
-static int	rval;
-static char  **gargv;
-
-#ifdef BUILTIN		/* csh builtin */
-#define main progprintf
-#endif
-
-#ifdef SHELL		/* sh (aka ash) builtin */
-#define main printfcmd
-#include "../../bin/sh/bltin/bltin.h"
-#endif /* SHELL */
-
-#define PF(f, func) { \
-	if (fieldwidth != -1) { \
-		if (precision != -1) \
-			(void)printf(f, fieldwidth, precision, func); \
-		else \
-			(void)printf(f, fieldwidth, func); \
-	} else if (precision != -1) \
-		(void)printf(f, precision, func); \
-	else \
-		(void)printf(f, func); \
-}
-
-#define APF(cpp, f, func) { \
-	if (fieldwidth != -1) { \
-		if (precision != -1) \
-			(void)asprintf(cpp, f, fieldwidth, precision, func); \
-		else \
-			(void)asprintf(cpp, f, fieldwidth, func); \
-	} else if (precision != -1) \
-		(void)asprintf(cpp, f, precision, func); \
-	else \
-		(void)asprintf(cpp, f, func); \
-}
-
-int main(int, char **);
-int main(int argc, char *argv[])
-{
-	char *fmt, *start;
-	int fieldwidth, precision;
-	char nextch;
-	char *format;
-	int ch;
-
-#if !defined(SHELL) && !defined(BUILTIN)
-	(void)setlocale (LC_ALL, "");
-#endif
-
-	while ((ch = getopt(argc, argv, "")) != -1) {
-		switch (ch) {
-		case '?':
-		default:
-			usage();
-			return 1;
-		}
-	}
-	argc -= optind;
-	argv += optind;
-
-	if (argc < 1) {
-		usage();
-		return 1;
-	}
-
-	format = *argv;
-	gargv = ++argv;
-
-#define SKIP1	"#-+ 0"
-#define SKIP2	"*0123456789"
-	do {
-		/*
-		 * Basic algorithm is to scan the format string for conversion
-		 * specifications -- once one is found, find out if the field
-		 * width or precision is a '*'; if it is, gather up value.
-		 * Note, format strings are reused as necessary to use up the
-		 * provided arguments, arguments of zero/null string are
-		 * provided to use up the format string.
-		 */
-
-		/* find next format specification */
-		for (fmt = format; (ch = *fmt++) != '\0';) {
-			if (ch == '\\') {
-				char c_ch;
-				fmt = conv_escape(fmt, &c_ch);
-				putchar(c_ch);
-				continue;
-			}
-			if (ch != '%' || (*fmt == '%' && ++fmt)) {
-				(void)putchar(ch);
-				continue;
-			}
-
-			/* Ok - we've found a format specification,
-			   Save its address for a later printf(). */
-			start = fmt - 1;
-
-			/* skip to field width */
-			fmt += strspn(fmt, SKIP1);
-			fieldwidth = *fmt == '*' ? getwidth() : -1;
-
-			/* skip to possible '.', get following precision */
-			fmt += strspn(fmt, SKIP2);
-			if (*fmt == '.')
-				++fmt;
-			precision = *fmt == '*' ? getwidth() : -1;
-
-			fmt += strspn(fmt, SKIP2);
-
-			ch = *fmt;
-			if (!ch) {
-				warnx("missing format character");
-				return (1);
-			}
-			/* null terminate format string to we can use it
-			   as an argument to printf. */
-			nextch = fmt[1];
-			fmt[1] = 0;
-			switch (ch) {
-
-			case 'B': {
-				const char *p = conv_expand(getstr());
-				*fmt = 's';
-				PF(start, p);
-				break;
-			}
-			case 'b': {
-				/* There has to be a better way to do this,
-				 * but the string we generate might have
-				 * embedded nulls. */
-				static char *a, *t;
-				char *cp = getstr();
-				/* Free on entry in case shell longjumped out */
-				if (a != NULL)
-					free(a);
-				a = NULL;
-				if (t != NULL)
-					free(t);
-				t = NULL;
-				/* Count number of bytes we want to output */
-				b_length = 0;
-				conv_escape_str(cp, b_count);
-				t = malloc(b_length + 1);
-				if (t == NULL)
-					break;
-				memset(t, 'x', b_length);
-				t[b_length] = 0;
-				/* Get printf to calculate the lengths */
-				*fmt = 's';
-				APF(&a, start, t);
-				b_fmt = a;
-				/* Output leading spaces and data bytes */
-				conv_escape_str(cp, b_output);
-				/* Add any trailing spaces */
-				printf("%s", b_fmt);
-				break;
-			}
-			case 'c': {
-				char p = getchr();
-				PF(start, p);
-				break;
-			}
-			case 's': {
-				char *p = getstr();
-				PF(start, p);
-				break;
-			}
-			case 'd':
-			case 'i': {
-				intmax_t p = getintmax();
-				char *f = mklong(start, ch);
-				PF(f, p);
-				break;
-			}
-			case 'o':
-			case 'u':
-			case 'x':
-			case 'X': {
-				uintmax_t p = getuintmax();
-				char *f = mklong(start, ch);
-				PF(f, p);
-				break;
-			}
-			case 'e':
-			case 'E':
-			case 'f':
-			case 'g':
-			case 'G': {
-				double p = getdouble();
-				PF(start, p);
-				break;
-			}
-			default:
-				warnx("%s: invalid directive", start);
-				return 1;
-			}
-			*fmt++ = ch;
-			*fmt = nextch;
-			/* escape if a \c was encountered */
-			if (rval & 0x100)
-				return rval & ~0x100;
-		}
-	} while (gargv != argv && *gargv);
-
-	return rval;
-}
-
-/* helper functions for conv_escape_str */
-
-static void
-/*ARGSUSED*/
-b_count(int ch)
-{
-	b_length++;
-}
-
-/* Output one converted character for every 'x' in the 'format' */
-
-static void
-b_output(int ch)
-{
-	for (;;) {
-		switch (*b_fmt++) {
-		case 0:
-			b_fmt--;
-			return;
-		case ' ':
-			putchar(' ');
-			break;
-		default:
-			putchar(ch);
-			return;
-		}
-	}
-}
-
-
-/*
- * Print SysV echo(1) style escape string
- *	Halts processing string if a \c escape is encountered.
- */
-static void
-conv_escape_str(char *str, void (*do_putchar)(int))
-{
-	int value;
-	int ch;
-	char c;
-
-	while ((ch = *str++) != '\0') {
-		if (ch != '\\') {
-			do_putchar(ch);
-			continue;
-		}
-
-		ch = *str++;
-		if (ch == 'c') {
-			/* \c as in SYSV echo - abort all processing.... */
-			rval |= 0x100;
-			break;
-		}
-
-		/*
-		 * %b string octal constants are not like those in C.
-		 * They start with a \0, and are followed by 0, 1, 2,
-		 * or 3 octal digits.
-		 */
-		if (ch == '0') {
-			int octnum = 0, i;
-			for (i = 0; i < 3; i++) {
-				if (!isdigit((unsigned char)*str) || *str > '7')
-					break;
-				octnum = (octnum << 3) | (*str++ - '0');
-			}
-			do_putchar(octnum);
-			continue;
-		}
-
-		/* \[M][^|-]C as defined by vis(3) */
-		if (ch == 'M' && *str == '-') {
-			do_putchar(0200 | str[1]);
-			str += 2;
-			continue;
-		}
-		if (ch == 'M' && *str == '^') {
-			str++;
-			value = 0200;
-			ch = '^';
-		} else
-			value = 0;
-		if (ch == '^') {
-			ch = *str++;
-			if (ch == '?')
-				value |= 0177;
-			else
-				value |= ch & 037;
-			do_putchar(value);
-			continue;
-		}
-
-		/* Finally test for sequences valid in the format string */
-		str = conv_escape(str - 1, &c);
-		do_putchar(c);
-	}
-}
-
-/*
- * Print "standard" escape characters
- */
-static char *
-conv_escape(char *str, char *conv_ch)
-{
-	int value;
-	int ch;
-	char num_buf[4], *num_end;
-
-	ch = *str++;
-
-	switch (ch) {
-	case '0': case '1': case '2': case '3':
-	case '4': case '5': case '6': case '7':
-		num_buf[0] = ch;
-		ch = str[0];
-		num_buf[1] = ch;
-		num_buf[2] = ch ? str[1] : 0;
-		num_buf[3] = 0;
-		value = strtoul(num_buf, &num_end, 8);
-		str += num_end  - (num_buf + 1);
-		break;
-
-	case 'x':
-		/* Hexadecimal character constants are not required to be
-		   supported (by SuS v1) because there is no consistent
-		   way to detect the end of the constant.
-		   Supporting 2 byte constants is a compromise. */
-		ch = str[0];
-		num_buf[0] = ch;
-		num_buf[1] = ch ? str[1] : 0;
-		num_buf[2] = 0;
-		value = strtoul(num_buf, &num_end, 16);
-		str += num_end - num_buf;
-		break;
-
-	case '\\':	value = '\\';	break;	/* backslash */
-	case '\'':	value = '\'';	break;	/* single quote */
-	case '"':	value = '"';	break;	/* double quote */
-	case 'a':	value = '\a';	break;	/* alert */
-	case 'b':	value = '\b';	break;	/* backspace */
-	case 'e':	value = ESCAPE;	break;	/* escape */
-	case 'f':	value = '\f';	break;	/* form-feed */
-	case 'n':	value = '\n';	break;	/* newline */
-	case 'r':	value = '\r';	break;	/* carriage-return */
-	case 't':	value = '\t';	break;	/* tab */
-	case 'v':	value = '\v';	break;	/* vertical-tab */
-
-	default:
-		warnx("unknown escape sequence `\\%c'", ch);
-		rval = 1;
-		value = ch;
-		break;
-	}
-
-	*conv_ch = value;
-	return str;
-}
-
-/* expand a string so that everything is printable */
-
-static char *
-conv_expand(const char *str)
-{
-	static char *conv_str;
-	static char no_memory[] = "<no memory>";
-	char *cp;
-	int ch;
-
-	if (conv_str)
-		free(conv_str);
-	/* get a buffer that is definitely large enough.... */
-	conv_str = malloc(4 * strlen(str) + 1);
-	if (!conv_str)
-		return no_memory;
-	cp = conv_str;
-
-	while ((ch = *(const unsigned char *)str++) != '\0') {
-		switch (ch) {
-		/* Use C escapes for expected control characters */
-		case '\\':	ch = '\\';	break;	/* backslash */
-		case '\'':	ch = '\'';	break;	/* single quote */
-		case '"':	ch = '"';	break;	/* double quote */
-		case '\a':	ch = 'a';	break;	/* alert */
-		case '\b':	ch = 'b';	break;	/* backspace */
-		case ESCAPE:	ch = 'e';	break;	/* escape */
-		case '\f':	ch = 'f';	break;	/* form-feed */
-		case '\n':	ch = 'n';	break;	/* newline */
-		case '\r':	ch = 'r';	break;	/* carriage-return */
-		case '\t':	ch = 't';	break;	/* tab */
-		case '\v':	ch = 'v';	break;	/* vertical-tab */
-		default:
-			/* Copy anything printable */
-			if (isprint(ch)) {
-				*cp++ = ch;
-				continue;
-			}
-			/* Use vis(3) encodings for the rest */
-			*cp++ = '\\';
-			if (ch & 0200) {
-				*cp++ = 'M';
-				ch &= ~0200;
-			}
-			if (ch == 0177) {
-				*cp++ = '^';
-				*cp++ = '?';
-				continue;
-			}
-			if (ch < 040) {
-				*cp++ = '^';
-				*cp++ = ch | 0100;
-				continue;
-			}
-			*cp++ = '-';
-			*cp++ = ch;
-			continue;
-		}
-		*cp++ = '\\';
-		*cp++ = ch;
-	}
-
-	*cp = 0;
-	return conv_str;
-}
-
-static char *
-mklong(const char *str, int ch)
-{
-	static char copy[64];
-	size_t len;
-
-	len = strlen(str) + 2;
-	if (len > sizeof copy) {
-		warnx("format %s too complex\n", str);
-		len = 4;
-	}
-	(void)memmove(copy, str, len - 3);
-	copy[len - 3] = 'j';
-	copy[len - 2] = ch;
-	copy[len - 1] = '\0';
-	return copy;
-}
-
-static int
-getchr(void)
-{
-	if (!*gargv)
-		return 0;
-	return (int)**gargv++;
-}
-
-static char *
-getstr(void)
-{
-	static char empty[] = "";
-	if (!*gargv)
-		return empty;
-	return *gargv++;
-}
-
-static int
-getwidth(void)
-{
-	long val;
-	char *s, *ep;
-
-	s = *gargv;
-	if (!*gargv)
-		return (0);
-	gargv++;
-
-	errno = 0;
-	val = strtoul(s, &ep, 0);
-	check_conversion(s, ep);
-
-	/* Arbitrarily 'restrict' field widths to 1Mbyte */
-	if (val < 0 || val > 1 << 20) {
-		warnx("%s: invalid field width", s);
-		return 0;
-	}
-
-	return val;
-}
-
-static intmax_t
-getintmax(void)
-{
-	intmax_t val;
-	char *cp, *ep;
-
-	cp = *gargv;
-	if (cp == NULL)
-		return 0;
-	gargv++;
-
-	if (*cp == '\"' || *cp == '\'')
-		return *(cp+1);
-
-	errno = 0;
-	val = strtoimax(cp, &ep, 0);
-	check_conversion(cp, ep);
-	return val;
-}
-
-static uintmax_t
-getuintmax(void)
-{
-	uintmax_t val;
-	char *cp, *ep;
-
-	cp = *gargv;
-	if (cp == NULL)
-		return 0;
-	gargv++;
-
-	if (*cp == '\"' || *cp == '\'')
-		return *(cp + 1);
-
-	/* strtoumax won't error -ve values */
-	while (isspace(*(unsigned char *)cp))
-		cp++;
-	if (*cp == '-') {
-		warnx("%s: expected positive numeric value", cp);
-		rval = 1;
-		return 0;
-	}
-
-	errno = 0;
-	val = strtoumax(cp, &ep, 0);
-	check_conversion(cp, ep);
-	return val;
-}
-
-static double
-getdouble(void)
-{
-	double val;
-	char *ep;
-
-	if (!*gargv)
-		return (0.0);
-
-	if (**gargv == '\"' || **gargv == '\'')
-		return (double) *((*gargv++)+1);
-
-	errno = 0;
-	val = strtod(*gargv, &ep);
-	check_conversion(*gargv++, ep);
-	return val;
-}
-
-static void
-check_conversion(const char *s, const char *ep)
-{
-	if (*ep) {
-		if (ep == s)
-			warnx("%s: expected numeric value", s);
-		else
-			warnx("%s: not completely converted", s);
-		rval = 1;
-	} else if (errno == ERANGE) {
-		warnx("%s: %s", s, strerror(ERANGE));
-		rval = 1;
-	}
-}
-
-static void
-usage(void)
-{
-	(void)fprintf(stderr, "Usage: %s format [arg ...]\n", getprogname());
-}
diff --git a/src/ash/bltin/test.c b/src/ash/bltin/test.c
deleted file mode 100644
index 6ead997..0000000
--- a/src/ash/bltin/test.c
+++ /dev/null
@@ -1,509 +0,0 @@
-/* $NetBSD: test.c,v 1.26 2005/02/10 06:56:55 simonb Exp $ */
-
-/*
- * test(1); version 7-like  --  author Erik Baalbergen
- * modified by Eric Gisin to be used as built-in.
- * modified by Arnold Robbins to add SVR3 compatibility
- * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
- * modified by J.T. Conklin for NetBSD.
- *
- * This program is in the Public Domain.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-__RCSID("$NetBSD: test.c,v 1.26 2005/02/10 06:56:55 simonb Exp $");
-#endif
-
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <ctype.h>
-#ifndef __sun__
-#include <err.h>
-#endif
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdarg.h>
-
-/* test(1) accepts the following grammar:
-	oexpr	::= aexpr | aexpr "-o" oexpr ;
-	aexpr	::= nexpr | nexpr "-a" aexpr ;
-	nexpr	::= primary | "!" primary
-	primary	::= unary-operator operand
-		| operand binary-operator operand
-		| operand
-		| "(" oexpr ")"
-		;
-	unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
-		"-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
-
-	binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
-			"-nt"|"-ot"|"-ef";
-	operand ::= <any legal UNIX file name>
-*/
-
-enum token {
-	EOI,
-	FILRD,
-	FILWR,
-	FILEX,
-	FILEXIST,
-	FILREG,
-	FILDIR,
-	FILCDEV,
-	FILBDEV,
-	FILFIFO,
-	FILSOCK,
-	FILSYM,
-	FILGZ,
-	FILTT,
-	FILSUID,
-	FILSGID,
-	FILSTCK,
-	FILNT,
-	FILOT,
-	FILEQ,
-	FILUID,
-	FILGID,
-	STREZ,
-	STRNZ,
-	STREQ,
-	STRNE,
-	STRLT,
-	STRGT,
-	INTEQ,
-	INTNE,
-	INTGE,
-	INTGT,
-	INTLE,
-	INTLT,
-	UNOT,
-	BAND,
-	BOR,
-	LPAREN,
-	RPAREN,
-	OPERAND
-};
-
-enum token_types {
-	UNOP,
-	BINOP,
-	BUNOP,
-	BBINOP,
-	PAREN
-};
-
-static struct t_op {
-	const char *op_text;
-	short op_num, op_type;
-} const ops [] = {
-	{"-r",	FILRD,	UNOP},
-	{"-w",	FILWR,	UNOP},
-	{"-x",	FILEX,	UNOP},
-	{"-e",	FILEXIST,UNOP},
-	{"-f",	FILREG,	UNOP},
-	{"-d",	FILDIR,	UNOP},
-	{"-c",	FILCDEV,UNOP},
-	{"-b",	FILBDEV,UNOP},
-	{"-p",	FILFIFO,UNOP},
-	{"-u",	FILSUID,UNOP},
-	{"-g",	FILSGID,UNOP},
-	{"-k",	FILSTCK,UNOP},
-	{"-s",	FILGZ,	UNOP},
-	{"-t",	FILTT,	UNOP},
-	{"-z",	STREZ,	UNOP},
-	{"-n",	STRNZ,	UNOP},
-	{"-h",	FILSYM,	UNOP},		/* for backwards compat */
-	{"-O",	FILUID,	UNOP},
-	{"-G",	FILGID,	UNOP},
-	{"-L",	FILSYM,	UNOP},
-	{"-S",	FILSOCK,UNOP},
-	{"=",	STREQ,	BINOP},
-	{"!=",	STRNE,	BINOP},
-	{"<",	STRLT,	BINOP},
-	{">",	STRGT,	BINOP},
-	{"-eq",	INTEQ,	BINOP},
-	{"-ne",	INTNE,	BINOP},
-	{"-ge",	INTGE,	BINOP},
-	{"-gt",	INTGT,	BINOP},
-	{"-le",	INTLE,	BINOP},
-	{"-lt",	INTLT,	BINOP},
-	{"-nt",	FILNT,	BINOP},
-	{"-ot",	FILOT,	BINOP},
-	{"-ef",	FILEQ,	BINOP},
-	{"!",	UNOT,	BUNOP},
-	{"-a",	BAND,	BBINOP},
-	{"-o",	BOR,	BBINOP},
-	{"(",	LPAREN,	PAREN},
-	{")",	RPAREN,	PAREN},
-	{0,	0,	0}
-};
-
-static char **t_wp;
-static struct t_op const *t_wp_op;
-
-static void syntax(const char *, const char *);
-static int oexpr(enum token);
-static int aexpr(enum token);
-static int nexpr(enum token);
-static int primary(enum token);
-static int binop(void);
-static int filstat(char *, enum token);
-static enum token t_lex(char *);
-static int isoperand(void);
-static int getn(const char *);
-static int newerf(const char *, const char *);
-static int olderf(const char *, const char *);
-static int equalf(const char *, const char *);
-
-#if defined(SHELL)
-extern void error(const char *, ...) __attribute__((__noreturn__));
-#else
-static void error(const char *, ...) __attribute__((__noreturn__));
-
-static void
-error(const char *msg, ...)
-{
-	va_list ap;
-
-	va_start(ap, msg);
-	verrx(2, msg, ap);
-	/*NOTREACHED*/
-	va_end(ap);
-}
-#endif
-
-#ifdef SHELL
-int testcmd(int, char **);
-
-int
-testcmd(int argc, char **argv)
-#else
-int main(int, char *[]);
-
-int
-main(int argc, char *argv[])
-#endif
-{
-	int res;
-
-#ifdef HAVE_SETPROGNAME
-	setprogname(argv[0]);
-#endif
-	if (strcmp(argv[0], "[") == 0) {
-		if (strcmp(argv[--argc], "]"))
-			error("missing ]");
-		argv[argc] = NULL;
-	}
-
-	if (argc < 2)
-		return 1;
-
-	t_wp = &argv[1];
-	res = !oexpr(t_lex(*t_wp));
-
-	if (*t_wp != NULL && *++t_wp != NULL)
-		syntax(*t_wp, "unexpected operator");
-
-	return res;
-}
-
-static void
-syntax(const char *op, const char *msg)
-{
-
-	if (op && *op)
-		error("%s: %s", op, msg);
-	else
-		error("%s", msg);
-}
-
-static int
-oexpr(enum token n)
-{
-	int res;
-
-	res = aexpr(n);
-	if (t_lex(*++t_wp) == BOR)
-		return oexpr(t_lex(*++t_wp)) || res;
-	t_wp--;
-	return res;
-}
-
-static int
-aexpr(enum token n)
-{
-	int res;
-
-	res = nexpr(n);
-	if (t_lex(*++t_wp) == BAND)
-		return aexpr(t_lex(*++t_wp)) && res;
-	t_wp--;
-	return res;
-}
-
-static int
-nexpr(enum token n)
-{
-
-	if (n == UNOT)
-		return !nexpr(t_lex(*++t_wp));
-	return primary(n);
-}
-
-static int
-primary(enum token n)
-{
-	enum token nn;
-	int res;
-
-	if (n == EOI)
-		return 0;		/* missing expression */
-	if (n == LPAREN) {
-		if ((nn = t_lex(*++t_wp)) == RPAREN)
-			return 0;	/* missing expression */
-		res = oexpr(nn);
-		if (t_lex(*++t_wp) != RPAREN)
-			syntax(NULL, "closing paren expected");
-		return res;
-	}
-	if (t_wp_op && t_wp_op->op_type == UNOP) {
-		/* unary expression */
-		if (*++t_wp == NULL)
-			syntax(t_wp_op->op_text, "argument expected");
-		switch (n) {
-		case STREZ:
-			return strlen(*t_wp) == 0;
-		case STRNZ:
-			return strlen(*t_wp) != 0;
-		case FILTT:
-			return isatty(getn(*t_wp));
-		default:
-			return filstat(*t_wp, n);
-		}
-	}
-
-	if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) {
-		return binop();
-	}
-
-	return strlen(*t_wp) > 0;
-}
-
-static int
-binop(void)
-{
-	const char *opnd1, *opnd2;
-	struct t_op const *op;
-
-	opnd1 = *t_wp;
-	(void) t_lex(*++t_wp);
-	op = t_wp_op;
-
-	if ((opnd2 = *++t_wp) == NULL)
-		syntax(op->op_text, "argument expected");
-
-	switch (op->op_num) {
-	case STREQ:
-		return strcmp(opnd1, opnd2) == 0;
-	case STRNE:
-		return strcmp(opnd1, opnd2) != 0;
-	case STRLT:
-		return strcmp(opnd1, opnd2) < 0;
-	case STRGT:
-		return strcmp(opnd1, opnd2) > 0;
-	case INTEQ:
-		return getn(opnd1) == getn(opnd2);
-	case INTNE:
-		return getn(opnd1) != getn(opnd2);
-	case INTGE:
-		return getn(opnd1) >= getn(opnd2);
-	case INTGT:
-		return getn(opnd1) > getn(opnd2);
-	case INTLE:
-		return getn(opnd1) <= getn(opnd2);
-	case INTLT:
-		return getn(opnd1) < getn(opnd2);
-	case FILNT:
-		return newerf(opnd1, opnd2);
-	case FILOT:
-		return olderf(opnd1, opnd2);
-	case FILEQ:
-		return equalf(opnd1, opnd2);
-	default:
-		abort();
-		/* NOTREACHED */
-	}
-}
-
-static int
-filstat(char *nm, enum token mode)
-{
-	struct stat s;
-
-	if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s))
-		return 0;
-
-	switch (mode) {
-	case FILRD:
-		return access(nm, R_OK) == 0;
-	case FILWR:
-		return access(nm, W_OK) == 0;
-	case FILEX:
-		return access(nm, X_OK) == 0;
-	case FILEXIST:
-		return access(nm, F_OK) == 0;
-	case FILREG:
-		return S_ISREG(s.st_mode);
-	case FILDIR:
-		return S_ISDIR(s.st_mode);
-	case FILCDEV:
-#ifdef S_ISCHR
-		return S_ISCHR(s.st_mode);
-#else
-        return 0;
-#endif
-	case FILBDEV:
-#ifdef S_ISBLK
-		return S_ISBLK(s.st_mode);
-#else
-        return 0;
-#endif
-	case FILFIFO:
-#ifdef S_ISFIFO
-		return S_ISFIFO(s.st_mode);
-#else
-        return 0;
-#endif
-	case FILSOCK:
-#ifdef S_ISSOCK
-		return S_ISSOCK(s.st_mode);
-#else
-        return 0;
-#endif
-	case FILSYM:
-		return S_ISLNK(s.st_mode);
-	case FILSUID:
-		return (s.st_mode & S_ISUID) != 0;
-	case FILSGID:
-		return (s.st_mode & S_ISGID) != 0;
-	case FILSTCK:
-#ifdef S_ISVTX
-		return (s.st_mode & S_ISVTX) != 0;
-#else
-        return 0;
-#endif
-	case FILGZ:
-		return s.st_size > (off_t)0;
-	case FILUID:
-		return s.st_uid == geteuid();
-	case FILGID:
-		return s.st_gid == getegid();
-	default:
-		return 1;
-	}
-}
-
-static enum token
-t_lex(char *s)
-{
-	struct t_op const *op;
-
-	op = ops;
-
-	if (s == 0) {
-		t_wp_op = NULL;
-		return EOI;
-	}
-	while (op->op_text) {
-		if (strcmp(s, op->op_text) == 0) {
-			if ((op->op_type == UNOP && isoperand()) ||
-			    (op->op_num == LPAREN && *(t_wp+1) == 0))
-				break;
-			t_wp_op = op;
-			return op->op_num;
-		}
-		op++;
-	}
-	t_wp_op = NULL;
-	return OPERAND;
-}
-
-static int
-isoperand(void)
-{
-	struct t_op const *op;
-	char *s, *t;
-
-	op = ops;
-	if ((s  = *(t_wp+1)) == 0)
-		return 1;
-	if ((t = *(t_wp+2)) == 0)
-		return 0;
-	while (op->op_text) {
-		if (strcmp(s, op->op_text) == 0)
-	    		return op->op_type == BINOP &&
-	    		    (t[0] != ')' || t[1] != '\0');
-		op++;
-	}
-	return 0;
-}
-
-/* atoi with error detection */
-static int
-getn(const char *s)
-{
-	char *p;
-	long r;
-
-	errno = 0;
-	r = strtol(s, &p, 10);
-
-	if (errno != 0)
-	      error("%s: out of range", s);
-
-	while (isspace((unsigned char)*p))
-	      p++;
-
-	if (*p)
-	      error("%s: bad number", s);
-
-	return (int) r;
-}
-
-static int
-newerf(const char *f1, const char *f2)
-{
-	struct stat b1, b2;
-
-	return (stat(f1, &b1) == 0 &&
-		stat(f2, &b2) == 0 &&
-		b1.st_mtime > b2.st_mtime);
-}
-
-static int
-olderf(const char *f1, const char *f2)
-{
-	struct stat b1, b2;
-
-	return (stat(f1, &b1) == 0 &&
-		stat(f2, &b2) == 0 &&
-		b1.st_mtime < b2.st_mtime);
-}
-
-static int
-equalf(const char *f1, const char *f2)
-{
-	struct stat b1, b2;
-
-	return (stat(f1, &b1) == 0 &&
-		stat(f2, &b2) == 0 &&
-		b1.st_dev == b2.st_dev &&
-		b1.st_ino == b2.st_ino);
-}
diff --git a/src/ash/builtins.def b/src/ash/builtins.def
deleted file mode 100644
index bd38c33..0000000
--- a/src/ash/builtins.def
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/bin/sh -
-#	$NetBSD: builtins.def,v 1.21 2004/07/13 15:05:59 seb Exp $
-#
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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 the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)builtins.def	8.4 (Berkeley) 5/4/95
-
-#
-# This file lists all the builtin commands.  The first column is the name
-# of a C routine.
-# The -j flag specifies that this command is to be excluded from systems
-# without job control.
-# The -h flag specifies that this command is to be excluded from systems
-# based on the SMALL compile-time symbol.
-# The -s flag specifies that this is a posix 'special builtin' command.
-# The -u flag specifies that this is a posix 'standard utility'.
-# The rest of the line specifies the command name or names used to run
-# the command.
-
-bltincmd	-u command
-bgcmd -j	-u bg
-breakcmd	-s break -s continue
-cdcmd		-u cd chdir
-dotcmd		-s .
-echocmd		echo
-evalcmd		-s eval
-execcmd		-s exec
-exitcmd		-s exit
-expcmd		exp let
-exportcmd	-s export -s readonly
-falsecmd	-u false
-histcmd -h	-u fc
-inputrc		inputrc
-fgcmd -j	-u fg
-getoptscmd	-u getopts
-hashcmd		hash
-jobidcmd	jobid
-jobscmd		-u jobs
-localcmd	local
-#ifndef SMALL
-printfcmd	printf
-#endif
-pwdcmd		-u pwd
-readcmd		-u read
-returncmd	-s return
-setcmd		-s set
-setvarcmd	setvar
-shiftcmd	-s shift
-timescmd	-s times
-trapcmd		-s trap
-truecmd		-s : -u true
-typecmd		type
-umaskcmd	-u umask
-unaliascmd	-u unalias
-unsetcmd	-s unset
-waitcmd		-u wait
-aliascmd	-u alias
-ulimitcmd	ulimit
-testcmd		test [
-killcmd		-u kill		# mandated by posix for 'kill %job'
-wordexpcmd	wordexp
-#newgrp		-u newgrp	# optional command in posix
-
-#exprcmd	expr
diff --git a/src/ash/cd.c b/src/ash/cd.c
deleted file mode 100644
index aae21f8..0000000
--- a/src/ash/cd.c
+++ /dev/null
@@ -1,448 +0,0 @@
-/*	$NetBSD: cd.c,v 1.34 2003/11/14 20:00:28 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)cd.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: cd.c,v 1.34 2003/11/14 20:00:28 dsl Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-/*
- * The cd and pwd commands.
- */
-
-#include "shell.h"
-#include "var.h"
-#include "nodes.h"	/* for jobs.h */
-#include "jobs.h"
-#include "options.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "exec.h"
-#include "redir.h"
-#include "mystring.h"
-#include "show.h"
-#include "cd.h"
-
-STATIC int docd(char *, int);
-STATIC char *getcomponent(void);
-STATIC void updatepwd(char *);
-STATIC void find_curdir(int noerror);
-
-char *curdir = NULL;		/* current working directory */
-char *prevdir;			/* previous working directory */
-STATIC char *cdcomppath;
-
-int
-cdcmd(int argc, char **argv)
-{
-	const char *dest;
-	const char *path;
-	char *p, *d;
-	struct stat statb;
-	int print = cdprint;	/* set -cdprint to enable */
-
-	nextopt(nullstr);
-
-	/*
-	 * Try (quite hard) to have 'curdir' defined, nothing has set
-	 * it on entry to the shell, but we want 'cd fred; cd -' to work.
-	 */
-	getpwd(1);
-	dest = *argptr;
-	if (dest == NULL) {
-		dest = bltinlookup("HOME", 1);
-		if (dest == NULL)
-			error("HOME not set");
-	} else {
-		if (argptr[1]) {
-			/* Do 'ksh' style substitution */
-			if (!curdir)
-				error("PWD not set");
-			p = strstr(curdir, dest);
-			if (!p)
-				error("bad substitution");
-			d = stalloc(strlen(curdir) + strlen(argptr[1]) + 1);
-			memcpy(d, curdir, p - curdir);
-			strcpy(d + (p - curdir), argptr[1]);
-			strcat(d, p + strlen(dest));
-			dest = d;
-			print = 1;
-		}
-	}
-
-	if (dest[0] == '-' && dest[1] == '\0') {
-		dest = prevdir ? prevdir : curdir;
-		print = 1;
-	}
-	if (*dest == '\0')
-	        dest = ".";
-	if (IS_ROOT(dest) || (path = bltinlookup("CDPATH", 1)) == NULL)
-		path = nullstr;
-	while ((p = padvance(&path, dest)) != NULL) {
-		if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
-			if (!print) {
-				/*
-				 * XXX - rethink
-				 */
-				if (p[0] == '.' && p[1] == '/' && p[2] != '\0')
-					p += 2;
-				print = strcmp(p, dest);
-			}
-			if (docd(p, print) >= 0)
-				return 0;
-
-		}
-	}
-	error("can't cd to %s", dest);
-	/* NOTREACHED */
-}
-
-
-/*
- * Actually do the chdir.  In an interactive shell, print the
- * directory name if "print" is nonzero.
- */
-
-STATIC int
-docd(char *dest, int print)
-{
-	char *p;
-	char *q;
-	char *component;
-	struct stat statb;
-	int first;
-	int badstat;
-
-	TRACE(("docd(\"%s\", %d) called\n", dest, print));
-
-	/*
-	 *  Check each component of the path. If we find a symlink or
-	 *  something we can't stat, clear curdir to force a getcwd()
-	 *  next time we get the value of the current directory.
-	 */
-	badstat = 0;
-	cdcomppath = stalloc(strlen(dest) + 1);
-	scopy(dest, cdcomppath);
-	STARTSTACKSTR(p);
-	if (IS_ROOT(dest)) {
-		STPUTC('/', p);
-		cdcomppath++;
-	}
-	first = 1;
-	while ((q = getcomponent()) != NULL) {
-		if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))
-			continue;
-		if (! first)
-			STPUTC('/', p);
-		first = 0;
-		component = q;
-		while (*q)
-			STPUTC(*q++, p);
-		if (equal(component, ".."))
-			continue;
-		STACKSTRNUL(p);
-		if ((lstat(stackblock(), &statb) < 0)
-		    || (S_ISLNK(statb.st_mode)))  {
-			/* print = 1; */
-			badstat = 1;
-			break;
-		}
-	}
-
-	INTOFF;
-	if (chdir(dest) < 0) {
-		INTON;
-		return -1;
-	}
-	updatepwd(badstat ? NULL : dest);
-	INTON;
-	if (print && iflag && curdir)
-		out1fmt("%s\n", curdir);
-	return 0;
-}
-
-
-/*
- * Get the next component of the path name pointed to by cdcomppath.
- * This routine overwrites the string pointed to by cdcomppath.
- */
-
-STATIC char *
-getcomponent()
-{
-	char *p;
-	char *start;
-
-	if ((p = cdcomppath) == NULL)
-		return NULL;
-	start = cdcomppath;
-	while (*p != '/' && *p != '\0')
-		p++;
-	if (*p == '\0') {
-		cdcomppath = NULL;
-	} else {
-		*p++ = '\0';
-		cdcomppath = p;
-	}
-	return start;
-}
-
-
-
-/*
- * Update curdir (the name of the current directory) in response to a
- * cd command.  We also call hashcd to let the routines in exec.c know
- * that the current directory has changed.
- */
-
-STATIC void
-updatepwd(char *dir)
-{
-	char *new;
-	char *p;
-
-	hashcd();				/* update command hash table */
-
-	/*
-	 * If our argument is NULL, we don't know the current directory
-	 * any more because we traversed a symbolic link or something
-	 * we couldn't stat().
-	 */
-	if (dir == NULL || curdir == NULL)  {
-		if (prevdir)
-			ckfree(prevdir);
-		INTOFF;
-		prevdir = curdir;
-		curdir = NULL;
-		getpwd(1);
-		INTON;
-		if (curdir)
-			setvar("PWD", curdir, VEXPORT);
-		else
-			unsetvar("PWD", 0);
-		return;
-	}
-	cdcomppath = stalloc(strlen(dir) + 1);
-	scopy(dir, cdcomppath);
-	STARTSTACKSTR(new);
-	if (!IS_ROOT(dir)) {
-		p = curdir;
-		while (*p)
-			STPUTC(*p++, new);
-		if (p[-1] == '/')
-			STUNPUTC(new);
-	}
-	while ((p = getcomponent()) != NULL) {
-		if (equal(p, "..")) {
-			while (new > stackblock() && (STUNPUTC(new), *new) != '/');
-		} else if (*p != '\0' && ! equal(p, ".")) {
-			STPUTC('/', new);
-			while (*p)
-				STPUTC(*p++, new);
-		}
-	}
-	if (new == stackblock())
-		STPUTC('/', new);
-	STACKSTRNUL(new);
-	INTOFF;
-	if (prevdir)
-		ckfree(prevdir);
-	prevdir = curdir;
-	curdir = savestr(stackblock());
-	setvar("PWD", curdir, VEXPORT);
-	INTON;
-}
-
-/*
- * Posix says the default should be 'pwd -L' (as below), however
- * the 'cd' command (above) does something much nearer to the
- * posix 'cd -P' (not the posix default of 'cd -L').
- * If 'cd' is changed to support -P/L then the default here
- * needs to be revisited if the historic behaviour is to be kept.
- */
-
-int
-pwdcmd(int argc, char **argv)
-{
-	int i;
-	char opt = 'L';
-
-	while ((i = nextopt("LP")) != '\0')
-		opt = i;
-	if (*argptr)
-		error("unexpected argument");
-
-	if (opt == 'L')
-		getpwd(0);
-	else
-		find_curdir(0);
-
-	setvar("PWD", curdir, VEXPORT);
-	out1str(curdir);
-	out1c('\n');
-	return 0;
-}
-
-
-
-
-#define MAXPWD 256
-
-/*
- * Find out what the current directory is. If we already know the current
- * directory, this routine returns immediately.
- */
-void
-getpwd(int noerror)
-{
-	char *pwd;
-	struct stat stdot, stpwd;
-	static int first = 1;
-
-	if (curdir)
-		return;
-
-	if (first) {
-		first = 0;
-		pwd = getenv("PWD");
-		if (pwd && IS_ROOT(pwd) && stat(".", &stdot) != -1 &&
-		    stat(pwd, &stpwd) != -1 &&
-		    stdot.st_dev == stpwd.st_dev &&
-		    stdot.st_ino == stpwd.st_ino) {
-			curdir = savestr(pwd);
-			return;
-		}
-	}
-
-	find_curdir(noerror);
-
-	return;
-}
-
-STATIC void
-find_curdir(int noerror)
-{
-	int i;
-	char *pwd;
-
-	/*
-	 * Things are a bit complicated here; we could have just used
-	 * getcwd, but traditionally getcwd is implemented using popen
-	 * to /bin/pwd. This creates a problem for us, since we cannot
-	 * keep track of the job if it is being ran behind our backs.
-	 * So we re-implement getcwd(), and we suppress interrupts
-	 * throughout the process. This is not completely safe, since
-	 * the user can still break out of it by killing the pwd program.
-	 * We still try to use getcwd for systems that we know have a
-	 * c implementation of getcwd, that does not open a pipe to
-	 * /bin/pwd.
-	 */
-#if defined(__NetBSD__) || defined(__SVR4) || defined(__INNOTEK_LIBC__) || 1 /* bird: nobody spawns pwd any more (we hope). */
-
-	for (i = MAXPWD;; i *= 2) {
-		pwd = stalloc(i);
-		if (getcwd(pwd, i) != NULL) {
-			curdir = savestr(pwd);
-			return;
-		}
-		stunalloc(pwd);
-		if (errno == ERANGE)
-			continue;
-		if (!noerror)
-			error("getcwd() failed: %s", strerror(errno));
-		return;
-	}
-#else
-	{
-		char *p;
-		int status;
-		struct job *jp;
-		int pip[2];
-
-		pwd = stalloc(MAXPWD);
-		INTOFF;
-		if (pipe(pip) < 0)
-			error("Pipe call failed");
-		jp = makejob((union node *)NULL, 1);
-		if (forkshell(jp, (union node *)NULL, FORK_NOJOB) == 0) {
-			(void) close(pip[0]);
-			if (pip[1] != 1) {
-				close(1);
-				copyfd(pip[1], 1);
-				close(pip[1]);
-			}
-			(void) execl("/bin/pwd", "pwd", (char *)0);
-			error("Cannot exec /bin/pwd");
-		}
-		(void) close(pip[1]);
-		pip[1] = -1;
-		p = pwd;
-		while ((i = read(pip[0], p, pwd + MAXPWD - p)) > 0
-		     || (i == -1 && errno == EINTR)) {
-			if (i > 0)
-				p += i;
-		}
-		(void) close(pip[0]);
-		pip[0] = -1;
-		status = waitforjob(jp);
-		if (status != 0)
-			error((char *)0);
-		if (i < 0 || p == pwd || p[-1] != '\n') {
-			if (noerror) {
-				INTON;
-				return;
-			}
-			error("pwd command failed");
-		}
-		p[-1] = '\0';
-		INTON;
-		curdir = savestr(pwd);
-		return;
-	}
-#endif
-}
diff --git a/src/ash/cd.h b/src/ash/cd.h
deleted file mode 100644
index 409d5ce..0000000
--- a/src/ash/cd.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$NetBSD: cd.h,v 1.4 2003/08/07 09:05:30 agc Exp $	*/
-
-/*-
- * Copyright (c) 1995
- *	The Regents of the University of California.  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 the University 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 REGENTS 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 REGENTS 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.
- *
- */
-
-void	getpwd(int);
-int	cdcmd(int, char **);
-int	pwdcmd(int, char **);
-#ifdef PC_DRIVE_LETTERS
-#define IS_ROOT(path) (   *(path) == '/' \
-                       || *(path) == '\\' \
-                       ||  ( ((*(path) >= 'A' && *(path) <= 'Z') || (*(path) >= 'a' && *(path) <= 'z')) \
-                             && (path)[1] == ':') )
-#else
-#define IS_ROOT(path) ( *(path) == '/' )
-#endif
diff --git a/src/ash/error.c b/src/ash/error.c
deleted file mode 100644
index 94b514d..0000000
--- a/src/ash/error.c
+++ /dev/null
@@ -1,370 +0,0 @@
-/*	$NetBSD: error.c,v 1.31 2003/08/07 09:05:30 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)error.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: error.c,v 1.31 2003/08/07 09:05:30 agc Exp $");
-#endif
-#endif /* not lint */
-
-/*
- * Errors and exceptions.
- */
-
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "shell.h"
-#include "main.h"
-#include "options.h"
-#include "output.h"
-#include "error.h"
-#include "show.h"
-
-
-/*
- * Code to handle exceptions in C.
- */
-
-struct jmploc *handler;
-int exception;
-volatile int suppressint;
-volatile int intpending;
-char *commandname;
-
-
-static void exverror(int, const char *, va_list)
-    __attribute__((__noreturn__));
-
-/*
- * Called to raise an exception.  Since C doesn't include exceptions, we
- * just do a longjmp to the exception handler.  The type of exception is
- * stored in the global variable "exception".
- */
-
-void
-exraise(int e)
-{
-	if (handler == NULL)
-		abort();
-	exception = e;
-	longjmp(handler->loc, 1);
-}
-
-
-/*
- * Called from trap.c when a SIGINT is received.  (If the user specifies
- * that SIGINT is to be trapped or ignored using the trap builtin, then
- * this routine is not called.)  Suppressint is nonzero when interrupts
- * are held using the INTOFF macro.  The call to _exit is necessary because
- * there is a short period after a fork before the signal handlers are
- * set to the appropriate value for the child.  (The test for iflag is
- * just defensive programming.)
- */
-
-void
-onint(void)
-{
-	sigset_t nsigset;
-
-	if (suppressint) {
-		intpending = 1;
-		return;
-	}
-	intpending = 0;
-	sigemptyset(&nsigset);
-	sigprocmask(SIG_SETMASK, &nsigset, NULL);
-	if (rootshell && iflag)
-		exraise(EXINT);
-	else {
-		signal(SIGINT, SIG_DFL);
-		raise(SIGINT);
-	}
-	/* NOTREACHED */
-}
-
-static void
-exvwarning(int sv_errno, const char *msg, va_list ap)
-{
-	/* Partially emulate line buffered output so that:
-	 *	printf '%d\n' 1 a 2
-	 * and
-	 *	printf '%d %d %d\n' 1 a 2
-	 * both generate sensible text when stdout and stderr are merged.
-	 */
-	if (output.nextc != output.buf && output.nextc[-1] == '\n')
-		flushout(&output);
-	if (commandname)
-		outfmt(&errout, "%s: ", commandname);
-	if (msg != NULL) {
-		doformat(&errout, msg, ap);
-		if (sv_errno >= 0)
-			outfmt(&errout, ": ");
-	}
-	if (sv_errno >= 0)
-		outfmt(&errout, "%s", strerror(sv_errno));
-	out2c('\n');
-	flushout(&errout);
-}
-
-/*
- * Exverror is called to raise the error exception.  If the second argument
- * is not NULL then error prints an error message using printf style
- * formatting.  It then raises the error exception.
- */
-static void
-exverror(int cond, const char *msg, va_list ap)
-{
-	CLEAR_PENDING_INT;
-	INTOFF;
-
-#ifdef DEBUG
-	if (msg) {
-		TRACE(("exverror(%d, \"", cond));
-		TRACEV((msg, ap));
-		TRACE(("\") pid=%d\n", getpid()));
-	} else
-		TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid()));
-#endif
-	if (msg)
-		exvwarning(-1, msg, ap);
-
-	output_flushall();
-	exraise(cond);
-	/* NOTREACHED */
-}
-
-
-void
-error(const char *msg, ...)
-{
-	va_list ap;
-
-	va_start(ap, msg);
-	exverror(EXERROR, msg, ap);
-	/* NOTREACHED */
-	va_end(ap);
-}
-
-
-void
-exerror(int cond, const char *msg, ...)
-{
-	va_list ap;
-
-	va_start(ap, msg);
-	exverror(cond, msg, ap);
-	/* NOTREACHED */
-	va_end(ap);
-}
-
-/*
- * error/warning routines for external builtins
- */
-
-void
-sh_exit(int rval)
-{
-	exerrno = rval & 255;
-	exraise(EXEXEC);
-}
-
-void
-sh_err(int status, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	exvwarning(errno, fmt, ap);
-	va_end(ap);
-	sh_exit(status);
-}
-
-void
-sh_verr(int status, const char *fmt, va_list ap)
-{
-	exvwarning(errno, fmt, ap);
-	sh_exit(status);
-}
-
-void
-sh_errx(int status, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	exvwarning(-1, fmt, ap);
-	va_end(ap);
-	sh_exit(status);
-}
-
-void
-sh_verrx(int status, const char *fmt, va_list ap)
-{
-	exvwarning(-1, fmt, ap);
-	sh_exit(status);
-}
-
-void
-sh_warn(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	exvwarning(errno, fmt, ap);
-	va_end(ap);
-}
-
-void
-sh_vwarn(const char *fmt, va_list ap)
-{
-	exvwarning(errno, fmt, ap);
-}
-
-void
-sh_warnx(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	exvwarning(-1, fmt, ap);
-	va_end(ap);
-}
-
-void
-sh_vwarnx(const char *fmt, va_list ap)
-{
-	exvwarning(-1, fmt, ap);
-}
-
-
-/*
- * Table of error messages.
- */
-
-struct errname {
-	short errcode;		/* error number */
-	short action;		/* operation which encountered the error */
-	const char *msg;	/* text describing the error */
-};
-
-
-#define ALL (E_OPEN|E_CREAT|E_EXEC)
-
-STATIC const struct errname errormsg[] = {
-	{ EINTR,	ALL,	"interrupted" },
-	{ EACCES,	ALL,	"permission denied" },
-	{ EIO,		ALL,	"I/O error" },
-	{ EEXIST,	ALL,	"file exists" },
-	{ ENOENT,	E_OPEN,	"no such file" },
-	{ ENOENT,	E_CREAT,"directory nonexistent" },
-	{ ENOENT,	E_EXEC,	"not found" },
-	{ ENOTDIR,	E_OPEN,	"no such file" },
-	{ ENOTDIR,	E_CREAT,"directory nonexistent" },
-	{ ENOTDIR,	E_EXEC,	"not found" },
-	{ EISDIR,	ALL,	"is a directory" },
-#ifdef EMFILE
-	{ EMFILE,	ALL,	"too many open files" },
-#endif
-	{ ENFILE,	ALL,	"file table overflow" },
-	{ ENOSPC,	ALL,	"file system full" },
-#ifdef EDQUOT
-	{ EDQUOT,	ALL,	"disk quota exceeded" },
-#endif
-#ifdef ENOSR
-	{ ENOSR,	ALL,	"no streams resources" },
-#endif
-	{ ENXIO,	ALL,	"no such device or address" },
-	{ EROFS,	ALL,	"read-only file system" },
-#ifdef ETXTBSY
-	{ ETXTBSY,	ALL,	"text busy" },
-#endif
-#ifdef EAGAIN
-	{ EAGAIN,	E_EXEC,	"not enough memory" },
-#endif
-	{ ENOMEM,	ALL,	"not enough memory" },
-#ifdef ENOLINK
-	{ ENOLINK,	ALL,	"remote access failed" },
-#endif
-#ifdef EMULTIHOP
-	{ EMULTIHOP,	ALL,	"remote access failed" },
-#endif
-#ifdef ECOMM
-	{ ECOMM,	ALL,	"remote access failed" },
-#endif
-#ifdef ESTALE
-	{ ESTALE,	ALL,	"remote access failed" },
-#endif
-#ifdef ETIMEDOUT
-	{ ETIMEDOUT,	ALL,	"remote access failed" },
-#endif
-#ifdef ELOOP
-	{ ELOOP,	ALL,	"symbolic link loop" },
-#endif
-	{ E2BIG,	E_EXEC,	"argument list too long" },
-#ifdef ELIBACC
-	{ ELIBACC,	E_EXEC,	"shared library missing" },
-#endif
-	{ 0,		0,	NULL },
-};
-
-
-/*
- * Return a string describing an error.  The returned string may be a
- * pointer to a static buffer that will be overwritten on the next call.
- * Action describes the operation that got the error.
- */
-
-const char *
-errmsg(int e, int action)
-{
-	struct errname const *ep;
-	static char buf[12];
-
-	for (ep = errormsg ; ep->errcode ; ep++) {
-		if (ep->errcode == e && (ep->action & action) != 0)
-			return ep->msg;
-	}
-	fmtstr(buf, sizeof buf, "error %d", e);
-	return buf;
-}
diff --git a/src/ash/error.h b/src/ash/error.h
deleted file mode 100644
index b4637f1..0000000
--- a/src/ash/error.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*	$NetBSD: error.h,v 1.16 2003/08/07 09:05:30 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)error.h	8.2 (Berkeley) 5/4/95
- */
-
-#include <stdarg.h>
-
-/*
- * Types of operations (passed to the errmsg routine).
- */
-
-#define E_OPEN 01	/* opening a file */
-#define E_CREAT 02	/* creating a file */
-#define E_EXEC 04	/* executing a program */
-
-
-/*
- * We enclose jmp_buf in a structure so that we can declare pointers to
- * jump locations.  The global variable handler contains the location to
- * jump to when an exception occurs, and the global variable exception
- * contains a code identifying the exeception.  To implement nested
- * exception handlers, the user should save the value of handler on entry
- * to an inner scope, set handler to point to a jmploc structure for the
- * inner scope, and restore handler on exit from the scope.
- */
-
-#include <setjmp.h>
-
-struct jmploc {
-	jmp_buf loc;
-};
-
-extern struct jmploc *handler;
-extern int exception;
-extern int exerrno;	/* error for EXEXEC */
-
-/* exceptions */
-#define EXINT 0		/* SIGINT received */
-#define EXERROR 1	/* a generic error */
-#define EXSHELLPROC 2	/* execute a shell procedure */
-#define EXEXEC 3	/* command execution failed */
-
-
-/*
- * These macros allow the user to suspend the handling of interrupt signals
- * over a period of time.  This is similar to SIGHOLD to or sigblock, but
- * much more efficient and portable.  (But hacking the kernel is so much
- * more fun than worrying about efficiency and portability. :-))
- */
-
-extern volatile int suppressint;
-extern volatile int intpending;
-
-#define INTOFF suppressint++
-#define INTON { if (--suppressint == 0 && intpending) onint(); }
-#define FORCEINTON {suppressint = 0; if (intpending) onint();}
-#define CLEAR_PENDING_INT intpending = 0
-#define int_pending() intpending
-
-void exraise(int) __attribute__((__noreturn__));
-void onint(void);
-void error(const char *, ...) __attribute__((__noreturn__));
-void exerror(int, const char *, ...) __attribute__((__noreturn__));
-const char *errmsg(int, int);
-
-void sh_err(int, const char *, ...) __attribute__((__noreturn__));
-void sh_verr(int, const char *, va_list) __attribute__((__noreturn__));
-void sh_errx(int, const char *, ...) __attribute__((__noreturn__));
-void sh_verrx(int, const char *, va_list) __attribute__((__noreturn__));
-void sh_warn(const char *, ...);
-void sh_vwarn(const char *, va_list);
-void sh_warnx(const char *, ...);
-void sh_vwarnx(const char *, va_list);
-
-void sh_exit(int) __attribute__((__noreturn__));
-
-
-/*
- * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
- * so we use _setjmp instead.
- */
-
-#if defined(BSD) && !defined(__SVR4) && !defined(__GLIBC__) && !defined(__KLIBC__) && !defined(_MSC_VER)
-#define setjmp(jmploc)	_setjmp(jmploc)
-#define longjmp(jmploc, val)	_longjmp(jmploc, val)
-#endif
diff --git a/src/ash/eval.c b/src/ash/eval.c
deleted file mode 100644
index d738c5b..0000000
--- a/src/ash/eval.c
+++ /dev/null
@@ -1,1285 +0,0 @@
-/*	$NetBSD: eval.c,v 1.84 2005/06/23 23:05:29 christos Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
-#else
-__RCSID("$NetBSD: eval.c,v 1.84 2005/06/23 23:05:29 christos Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#include <signal.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/fcntl.h>
-#include <sys/times.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#ifdef HAVE_SYSCTL_H
-#include <sys/sysctl.h>
-#endif
-#ifdef __sun__
-#include <iso/limits_iso.h>
-#endif
-
-/*
- * Evaluate a command.
- */
-
-#include "shell.h"
-#include "nodes.h"
-#include "syntax.h"
-#include "expand.h"
-#include "parser.h"
-#include "jobs.h"
-#include "eval.h"
-#include "builtins.h"
-#include "options.h"
-#include "exec.h"
-#include "redir.h"
-#include "input.h"
-#include "output.h"
-#include "trap.h"
-#include "var.h"
-#include "memalloc.h"
-#include "error.h"
-#include "show.h"
-#include "mystring.h"
-#include "main.h"
-#ifndef SMALL
-#include "myhistedit.h"
-#endif
-
-
-/* flags in argument to evaltree */
-#define EV_EXIT 01		/* exit after evaluating tree */
-#define EV_TESTED 02		/* exit status is checked; ignore -e flag */
-#define EV_BACKCMD 04		/* command executing within back quotes */
-
-int evalskip;			/* set if we are skipping commands */
-STATIC int skipcount;		/* number of levels to skip */
-MKINIT int loopnest;		/* current loop nesting level */
-int funcnest;			/* depth of function calls */
-
-
-char *commandname;
-struct strlist *cmdenviron;
-int exitstatus;			/* exit status of last command */
-int back_exitstatus;		/* exit status of backquoted command */
-
-
-STATIC void evalloop(union node *, int);
-STATIC void evalfor(union node *, int);
-STATIC void evalcase(union node *, int);
-STATIC void evalsubshell(union node *, int);
-STATIC void expredir(union node *);
-STATIC void evalpipe(union node *);
-STATIC void evalcommand(union node *, int, struct backcmd *);
-STATIC void prehash(union node *);
-
-
-/*
- * Called to reset things after an exception.
- */
-
-#ifdef mkinit
-INCLUDE "eval.h"
-
-RESET {
-	evalskip = 0;
-	loopnest = 0;
-	funcnest = 0;
-}
-
-SHELLPROC {
-	exitstatus = 0;
-}
-#endif
-
-static int
-sh_pipe(int fds[2])
-{
-	int nfd;
-
-	if (pipe(fds))
-		return -1;
-
-	if (fds[0] < 3) {
-		nfd = fcntl(fds[0], F_DUPFD, 3);
-		if (nfd != -1) {
-			close(fds[0]);
-			fds[0] = nfd;
-		}
-	}
-
-	if (fds[1] < 3) {
-		nfd = fcntl(fds[1], F_DUPFD, 3);
-		if (nfd != -1) {
-			close(fds[1]);
-			fds[1] = nfd;
-		}
-	}
-	return 0;
-}
-
-
-/*
- * The eval commmand.
- */
-
-int
-evalcmd(int argc, char **argv)
-{
-        char *p;
-        char *concat;
-        char **ap;
-
-        if (argc > 1) {
-                p = argv[1];
-                if (argc > 2) {
-                        STARTSTACKSTR(concat);
-                        ap = argv + 2;
-                        for (;;) {
-                                while (*p)
-                                        STPUTC(*p++, concat);
-                                if ((p = *ap++) == NULL)
-                                        break;
-                                STPUTC(' ', concat);
-                        }
-                        STPUTC('\0', concat);
-                        p = grabstackstr(concat);
-                }
-                evalstring(p, EV_TESTED);
-        }
-        return exitstatus;
-}
-
-
-/*
- * Execute a command or commands contained in a string.
- */
-
-void
-evalstring(char *s, int flag)
-{
-	union node *n;
-	struct stackmark smark;
-
-	setstackmark(&smark);
-	setinputstring(s, 1);
-
-	while ((n = parsecmd(0)) != NEOF) {
-		evaltree(n, flag);
-		popstackmark(&smark);
-	}
-	popfile();
-	popstackmark(&smark);
-}
-
-
-
-/*
- * Evaluate a parse tree.  The value is left in the global variable
- * exitstatus.
- */
-
-void
-evaltree(union node *n, int flags)
-{
-	if (n == NULL) {
-		TRACE(("evaltree(NULL) called\n"));
-		exitstatus = 0;
-		goto out;
-	}
-#ifndef SMALL
-	displayhist = 1;	/* show history substitutions done with fc */
-#endif
-	TRACE(("pid %d, evaltree(%p: %d, %d) called\n",
-	    getpid(), n, n->type, flags));
-	switch (n->type) {
-	case NSEMI:
-		evaltree(n->nbinary.ch1, flags & EV_TESTED);
-		if (evalskip)
-			goto out;
-		evaltree(n->nbinary.ch2, flags);
-		break;
-	case NAND:
-		evaltree(n->nbinary.ch1, EV_TESTED);
-		if (evalskip || exitstatus != 0)
-			goto out;
-		evaltree(n->nbinary.ch2, flags);
-		break;
-	case NOR:
-		evaltree(n->nbinary.ch1, EV_TESTED);
-		if (evalskip || exitstatus == 0)
-			goto out;
-		evaltree(n->nbinary.ch2, flags);
-		break;
-	case NREDIR:
-		expredir(n->nredir.redirect);
-		redirect(n->nredir.redirect, REDIR_PUSH);
-		evaltree(n->nredir.n, flags);
-		popredir();
-		break;
-	case NSUBSHELL:
-		evalsubshell(n, flags);
-		break;
-	case NBACKGND:
-		evalsubshell(n, flags);
-		break;
-	case NIF: {
-		evaltree(n->nif.test, EV_TESTED);
-		if (evalskip)
-			goto out;
-		if (exitstatus == 0)
-			evaltree(n->nif.ifpart, flags);
-		else if (n->nif.elsepart)
-			evaltree(n->nif.elsepart, flags);
-		else
-			exitstatus = 0;
-		break;
-	}
-	case NWHILE:
-	case NUNTIL:
-		evalloop(n, flags);
-		break;
-	case NFOR:
-		evalfor(n, flags);
-		break;
-	case NCASE:
-		evalcase(n, flags);
-		break;
-	case NDEFUN:
-		defun(n->narg.text, n->narg.next);
-		exitstatus = 0;
-		break;
-	case NNOT:
-		evaltree(n->nnot.com, EV_TESTED);
-		exitstatus = !exitstatus;
-		break;
-	case NPIPE:
-		evalpipe(n);
-		break;
-	case NCMD:
-		evalcommand(n, flags, (struct backcmd *)NULL);
-		break;
-	default:
-		out1fmt("Node type = %d\n", n->type);
-		flushout(&output);
-		break;
-	}
-out:
-	if (pendingsigs)
-		dotrap();
-	if ((flags & EV_EXIT) != 0)
-		exitshell(exitstatus);
-}
-
-
-STATIC void
-evalloop(union node *n, int flags)
-{
-	int status;
-
-	loopnest++;
-	status = 0;
-	for (;;) {
-		evaltree(n->nbinary.ch1, EV_TESTED);
-		if (evalskip) {
-skipping:	  if (evalskip == SKIPCONT && --skipcount <= 0) {
-				evalskip = 0;
-				continue;
-			}
-			if (evalskip == SKIPBREAK && --skipcount <= 0)
-				evalskip = 0;
-			break;
-		}
-		if (n->type == NWHILE) {
-			if (exitstatus != 0)
-				break;
-		} else {
-			if (exitstatus == 0)
-				break;
-		}
-		evaltree(n->nbinary.ch2, flags & EV_TESTED);
-		status = exitstatus;
-		if (evalskip)
-			goto skipping;
-	}
-	loopnest--;
-	exitstatus = status;
-}
-
-
-
-STATIC void
-evalfor(union node *n, int flags)
-{
-	struct arglist arglist;
-	union node *argp;
-	struct strlist *sp;
-	struct stackmark smark;
-	int status = 0;
-
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-	for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
-		expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
-		if (evalskip)
-			goto out;
-	}
-	*arglist.lastp = NULL;
-
-	loopnest++;
-	for (sp = arglist.list ; sp ; sp = sp->next) {
-		setvar(n->nfor.var, sp->text, 0);
-		evaltree(n->nfor.body, flags & EV_TESTED);
-		status = exitstatus;
-		if (evalskip) {
-			if (evalskip == SKIPCONT && --skipcount <= 0) {
-				evalskip = 0;
-				continue;
-			}
-			if (evalskip == SKIPBREAK && --skipcount <= 0)
-				evalskip = 0;
-			break;
-		}
-	}
-	loopnest--;
-	exitstatus = status;
-out:
-	popstackmark(&smark);
-}
-
-
-
-STATIC void
-evalcase(union node *n, int flags)
-{
-	union node *cp;
-	union node *patp;
-	struct arglist arglist;
-	struct stackmark smark;
-	int status = 0;
-
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-	expandarg(n->ncase.expr, &arglist, EXP_TILDE);
-	for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
-		for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
-			if (casematch(patp, arglist.list->text)) {
-				if (evalskip == 0) {
-					evaltree(cp->nclist.body, flags);
-					status = exitstatus;
-				}
-				goto out;
-			}
-		}
-	}
-out:
-	exitstatus = status;
-	popstackmark(&smark);
-}
-
-
-
-/*
- * Kick off a subshell to evaluate a tree.
- */
-
-STATIC void
-evalsubshell(union node *n, int flags)
-{
-	struct job *jp;
-	int backgnd = (n->type == NBACKGND);
-
-	expredir(n->nredir.redirect);
-	INTOFF;
-	jp = makejob(n, 1);
-	if (forkshell(jp, n, backgnd ? FORK_BG : FORK_FG) == 0) {
-		INTON;
-		if (backgnd)
-			flags &=~ EV_TESTED;
-		redirect(n->nredir.redirect, 0);
-		/* never returns */
-		evaltree(n->nredir.n, flags | EV_EXIT);
-	}
-	if (! backgnd)
-		exitstatus = waitforjob(jp);
-	INTON;
-}
-
-
-
-/*
- * Compute the names of the files in a redirection list.
- */
-
-STATIC void
-expredir(union node *n)
-{
-	union node *redir;
-
-	for (redir = n ; redir ; redir = redir->nfile.next) {
-		struct arglist fn;
-		fn.lastp = &fn.list;
-		switch (redir->type) {
-		case NFROMTO:
-		case NFROM:
-		case NTO:
-		case NCLOBBER:
-		case NAPPEND:
-			expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
-			redir->nfile.expfname = fn.list->text;
-			break;
-		case NFROMFD:
-		case NTOFD:
-			if (redir->ndup.vname) {
-				expandarg(redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE);
-				fixredir(redir, fn.list->text, 1);
-			}
-			break;
-		}
-	}
-}
-
-
-
-/*
- * Evaluate a pipeline.  All the processes in the pipeline are children
- * of the process creating the pipeline.  (This differs from some versions
- * of the shell, which make the last process in a pipeline the parent
- * of all the rest.)
- */
-
-STATIC void
-evalpipe(union node *n)
-{
-	struct job *jp;
-	struct nodelist *lp;
-	int pipelen;
-	int prevfd;
-	int pip[2];
-
-	TRACE(("evalpipe(0x%lx) called\n", (long)n));
-	pipelen = 0;
-	for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
-		pipelen++;
-	INTOFF;
-	jp = makejob(n, pipelen);
-	prevfd = -1;
-	for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
-		prehash(lp->n);
-		pip[1] = -1;
-		if (lp->next) {
-			if (sh_pipe(pip) < 0) {
-				close(prevfd);
-				error("Pipe call failed");
-			}
-		}
-		if (forkshell(jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG) == 0) {
-			INTON;
-			if (prevfd > 0) {
-				close(0);
-				copyfd(prevfd, 0);
-				close(prevfd);
-			}
-			if (pip[1] >= 0) {
-				close(pip[0]);
-				if (pip[1] != 1) {
-					close(1);
-					copyfd(pip[1], 1);
-					close(pip[1]);
-				}
-			}
-			evaltree(lp->n, EV_EXIT);
-		}
-		if (prevfd >= 0)
-			close(prevfd);
-		prevfd = pip[0];
-		close(pip[1]);
-	}
-	if (n->npipe.backgnd == 0) {
-		exitstatus = waitforjob(jp);
-		TRACE(("evalpipe:  job done exit status %d\n", exitstatus));
-	}
-	INTON;
-}
-
-
-
-/*
- * Execute a command inside back quotes.  If it's a builtin command, we
- * want to save its output in a block obtained from malloc.  Otherwise
- * we fork off a subprocess and get the output of the command via a pipe.
- * Should be called with interrupts off.
- */
-
-void
-evalbackcmd(union node *n, struct backcmd *result)
-{
-	int pip[2];
-	struct job *jp;
-	struct stackmark smark;		/* unnecessary */
-
-	setstackmark(&smark);
-	result->fd = -1;
-	result->buf = NULL;
-	result->nleft = 0;
-	result->jp = NULL;
-	if (n == NULL) {
-		goto out;
-	}
-#ifdef notyet
-	/*
-	 * For now we disable executing builtins in the same
-	 * context as the shell, because we are not keeping
-	 * enough state to recover from changes that are
-	 * supposed only to affect subshells. eg. echo "`cd /`"
-	 */
-	if (n->type == NCMD) {
-		exitstatus = oexitstatus;
-		evalcommand(n, EV_BACKCMD, result);
-	} else
-#endif
-	{
-		INTOFF;
-		if (sh_pipe(pip) < 0)
-			error("Pipe call failed");
-		jp = makejob(n, 1);
-		if (forkshell(jp, n, FORK_NOJOB) == 0) {
-			FORCEINTON;
-			close(pip[0]);
-			if (pip[1] != 1) {
-				close(1);
-				copyfd(pip[1], 1);
-				close(pip[1]);
-			}
-			eflag = 0;
-			evaltree(n, EV_EXIT);
-			/* NOTREACHED */
-		}
-		close(pip[1]);
-		result->fd = pip[0];
-		result->jp = jp;
-		INTON;
-	}
-out:
-	popstackmark(&smark);
-	TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
-		result->fd, result->buf, result->nleft, result->jp));
-}
-
-static const char *
-syspath(void)
-{
-#ifdef CTL_USER
-	static char *sys_path = NULL;
-	static int mib[] = {CTL_USER, USER_CS_PATH};
-#endif
-#ifdef PC_PATH_SEP
-	static char def_path[] = "PATH=/usr/bin;/bin;/usr/sbin;/sbin";
-#else
-	static char def_path[] = "PATH=/usr/bin:/bin:/usr/sbin:/sbin";
-#endif
-#ifdef CTL_USER
-	size_t len;
-
-	if (sys_path == NULL) {
-		if (sysctl(mib, 2, 0, &len, 0, 0) != -1 &&
-		    (sys_path = ckmalloc(len + 5)) != NULL &&
-		    sysctl(mib, 2, sys_path + 5, &len, 0, 0) != -1) {
-			memcpy(sys_path, "PATH=", 5);
-		} else {
-			ckfree(sys_path);
-			/* something to keep things happy */
-			sys_path = def_path;
-		}
-	}
-	return sys_path;
-#else
-    return def_path;
-#endif
-}
-
-static int
-parse_command_args(int argc, char **argv, int *use_syspath)
-{
-	int sv_argc = argc;
-	char *cp, c;
-
-	*use_syspath = 0;
-
-	for (;;) {
-		argv++;
-		if (--argc == 0)
-			break;
-		cp = *argv;
-		if (*cp++ != '-')
-			break;
-		if (*cp == '-' && cp[1] == 0) {
-			argv++;
-			argc--;
-			break;
-		}
-		while ((c = *cp++)) {
-			switch (c) {
-			case 'p':
-				*use_syspath = 1;
-				break;
-			default:
-				/* run 'typecmd' for other options */
-				return 0;
-			}
-		}
-	}
-	return sv_argc - argc;
-}
-
-int vforked = 0;
-
-/*
- * Execute a simple command.
- */
-
-STATIC void
-evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
-{
-	struct stackmark smark;
-	union node *argp;
-	struct arglist arglist;
-	struct arglist varlist;
-	char **argv;
-	int argc;
-	char **envp;
-	int varflag;
-	struct strlist *sp;
-	int mode;
-	int pip[2];
-	struct cmdentry cmdentry;
-	struct job *jp;
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-	char *volatile savecmdname;
-	volatile struct shparam saveparam;
-	struct localvar *volatile savelocalvars;
-	volatile int e;
-	char *lastarg;
-	const char *path = pathval();
-	volatile int temp_path;
-#if __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &argv;
-	(void) &argc;
-	(void) &lastarg;
-	(void) &flags;
-#endif
-
-	vforked = 0;
-	/* First expand the arguments. */
-	TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
-	setstackmark(&smark);
-	back_exitstatus = 0;
-
-	arglist.lastp = &arglist.list;
-	varflag = 1;
-	/* Expand arguments, ignoring the initial 'name=value' ones */
-	for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
-		char *p = argp->narg.text;
-		if (varflag && is_name(*p)) {
-			do {
-				p++;
-			} while (is_in_name(*p));
-			if (*p == '=')
-				continue;
-		}
-		expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
-		varflag = 0;
-	}
-	*arglist.lastp = NULL;
-
-	expredir(cmd->ncmd.redirect);
-
-	/* Now do the initial 'name=value' ones we skipped above */
-	varlist.lastp = &varlist.list;
-	for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
-		char *p = argp->narg.text;
-		if (!is_name(*p))
-			break;
-		do
-			p++;
-		while (is_in_name(*p));
-		if (*p != '=')
-			break;
-		expandarg(argp, &varlist, EXP_VARTILDE);
-	}
-	*varlist.lastp = NULL;
-
-	argc = 0;
-	for (sp = arglist.list ; sp ; sp = sp->next)
-		argc++;
-	argv = stalloc(sizeof (char *) * (argc + 1));
-
-	for (sp = arglist.list ; sp ; sp = sp->next) {
-		TRACE(("evalcommand arg: %s\n", sp->text));
-		*argv++ = sp->text;
-	}
-	*argv = NULL;
-	lastarg = NULL;
-	if (iflag && funcnest == 0 && argc > 0)
-		lastarg = argv[-1];
-	argv -= argc;
-
-	/* Print the command if xflag is set. */
-	if (xflag) {
-		char sep = 0;
-		out2str(ps4val());
-		for (sp = varlist.list ; sp ; sp = sp->next) {
-			if (sep != 0)
-				outc(sep, &errout);
-			out2str(sp->text);
-			sep = ' ';
-		}
-		for (sp = arglist.list ; sp ; sp = sp->next) {
-			if (sep != 0)
-				outc(sep, &errout);
-			out2str(sp->text);
-			sep = ' ';
-		}
-		outc('\n', &errout);
-		flushout(&errout);
-	}
-
-	/* Now locate the command. */
-	if (argc == 0) {
-		cmdentry.cmdtype = CMDSPLBLTIN;
-		cmdentry.u.bltin = bltincmd;
-	} else {
-		static const char PATH[] = "PATH=";
-		int cmd_flags = DO_ERR;
-
-		/*
-		 * Modify the command lookup path, if a PATH= assignment
-		 * is present
-		 */
-		for (sp = varlist.list; sp; sp = sp->next)
-			if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0)
-				path = sp->text + sizeof(PATH) - 1;
-
-		do {
-			int argsused, use_syspath;
-			find_command(argv[0], &cmdentry, cmd_flags, path);
-			if (cmdentry.cmdtype == CMDUNKNOWN) {
-				exitstatus = 127;
-				flushout(&errout);
-				goto out;
-			}
-
-			/* implement the 'command' builtin here */
-			if (cmdentry.cmdtype != CMDBUILTIN ||
-			    cmdentry.u.bltin != bltincmd)
-				break;
-			cmd_flags |= DO_NOFUNC;
-			argsused = parse_command_args(argc, argv, &use_syspath);
-			if (argsused == 0) {
-				/* use 'type' builting to display info */
-				cmdentry.u.bltin = typecmd;
-				break;
-			}
-			argc -= argsused;
-			argv += argsused;
-			if (use_syspath)
-				path = syspath() + 5;
-		} while (argc != 0);
-		if (cmdentry.cmdtype == CMDSPLBLTIN && cmd_flags & DO_NOFUNC)
-			/* posix mandates that 'command <splbltin>' act as if
-			   <splbltin> was a normal builtin */
-			cmdentry.cmdtype = CMDBUILTIN;
-	}
-
-	/* Fork off a child process if necessary. */
-	if (cmd->ncmd.backgnd
-	 || (cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0)
-	 || ((flags & EV_BACKCMD) != 0
-	    && ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN)
-		 || cmdentry.u.bltin == dotcmd
-		 || cmdentry.u.bltin == evalcmd))) {
-		INTOFF;
-		jp = makejob(cmd, 1);
-		mode = cmd->ncmd.backgnd;
-		if (flags & EV_BACKCMD) {
-			mode = FORK_NOJOB;
-			if (sh_pipe(pip) < 0)
-				error("Pipe call failed");
-		}
-#ifdef DO_SHAREDVFORK
-		/* It is essential that if DO_SHAREDVFORK is defined that the
-		 * child's address space is actually shared with the parent as
-		 * we rely on this.
-		 */
-		if (cmdentry.cmdtype == CMDNORMAL) {
-			pid_t	pid;
-
-			savelocalvars = localvars;
-			localvars = NULL;
-			vforked = 1;
-			switch (pid = vfork()) {
-			case -1:
-				TRACE(("Vfork failed, errno=%d\n", errno));
-				INTON;
-				error("Cannot vfork");
-				break;
-			case 0:
-				/* Make sure that exceptions only unwind to
-				 * after the vfork(2)
-				 */
-				if (setjmp(jmploc.loc)) {
-					if (exception == EXSHELLPROC) {
-						/* We can't progress with the vfork,
-						 * so, set vforked = 2 so the parent
-						 * knows, and _exit();
-						 */
-						vforked = 2;
-						_exit(0);
-					} else {
-						_exit(exerrno);
-					}
-				}
-				savehandler = handler;
-				handler = &jmploc;
-				listmklocal(varlist.list, VEXPORT | VNOFUNC);
-				forkchild(jp, cmd, mode, vforked);
-				break;
-			default:
-				handler = savehandler;	/* restore from vfork(2) */
-				poplocalvars();
-				localvars = savelocalvars;
-				if (vforked == 2) {
-					vforked = 0;
-
-					(void)waitpid(pid, NULL, 0);
-					/* We need to progress in a normal fork fashion */
-					goto normal_fork;
-				}
-				vforked = 0;
-				forkparent(jp, cmd, mode, pid);
-				goto parent;
-			}
-		} else {
-normal_fork:
-#endif
-			if (forkshell(jp, cmd, mode) != 0)
-				goto parent;	/* at end of routine */
-			FORCEINTON;
-#ifdef DO_SHAREDVFORK
-		}
-#endif
-		if (flags & EV_BACKCMD) {
-			if (!vforked) {
-				FORCEINTON;
-			}
-			close(pip[0]);
-			if (pip[1] != 1) {
-				close(1);
-				copyfd(pip[1], 1);
-				close(pip[1]);
-			}
-		}
-		flags |= EV_EXIT;
-	}
-
-	/* This is the child process if a fork occurred. */
-	/* Execute the command. */
-	switch (cmdentry.cmdtype) {
-	case CMDFUNCTION:
-#ifdef DEBUG
-		trputs("Shell function:  ");  trargs(argv);
-#endif
-		redirect(cmd->ncmd.redirect, REDIR_PUSH);
-		saveparam = shellparam;
-		shellparam.malloc = 0;
-		shellparam.reset = 1;
-		shellparam.nparam = argc - 1;
-		shellparam.p = argv + 1;
-		shellparam.optnext = NULL;
-		INTOFF;
-		savelocalvars = localvars;
-		localvars = NULL;
-		INTON;
-		if (setjmp(jmploc.loc)) {
-			if (exception == EXSHELLPROC) {
-				freeparam((volatile struct shparam *)
-				    &saveparam);
-			} else {
-				freeparam(&shellparam);
-				shellparam = saveparam;
-			}
-			poplocalvars();
-			localvars = savelocalvars;
-			handler = savehandler;
-			longjmp(handler->loc, 1);
-		}
-		savehandler = handler;
-		handler = &jmploc;
-		listmklocal(varlist.list, 0);
-		/* stop shell blowing its stack */
-		if (++funcnest > 1000)
-			error("too many nested function calls");
-		evaltree(cmdentry.u.func, flags & EV_TESTED);
-		funcnest--;
-		INTOFF;
-		poplocalvars();
-		localvars = savelocalvars;
-		freeparam(&shellparam);
-		shellparam = saveparam;
-		handler = savehandler;
-		popredir();
-		INTON;
-		if (evalskip == SKIPFUNC) {
-			evalskip = 0;
-			skipcount = 0;
-		}
-		if (flags & EV_EXIT)
-			exitshell(exitstatus);
-		break;
-
-	case CMDBUILTIN:
-	case CMDSPLBLTIN:
-#ifdef DEBUG
-		trputs("builtin command:  ");  trargs(argv);
-#endif
-		mode = (cmdentry.u.bltin == execcmd) ? 0 : REDIR_PUSH;
-		if (flags == EV_BACKCMD) {
-			memout.nleft = 0;
-			memout.nextc = memout.buf;
-			memout.bufsize = 64;
-			mode |= REDIR_BACKQ;
-		}
-		e = -1;
-		savehandler = handler;
-		savecmdname = commandname;
-		handler = &jmploc;
-		if (!setjmp(jmploc.loc)) {
-			/* We need to ensure the command hash table isn't
-			 * corruped by temporary PATH assignments.
-			 * However we must ensure the 'local' command works!
-			 */
-			if (path != pathval() && (cmdentry.u.bltin == hashcmd ||
-			    cmdentry.u.bltin == typecmd)) {
-				savelocalvars = localvars;
-				localvars = 0;
-				mklocal(path - 5 /* PATH= */, 0);
-				temp_path = 1;
-			} else
-				temp_path = 0;
-			redirect(cmd->ncmd.redirect, mode);
-
-			/* exec is a special builtin, but needs this list... */
-			cmdenviron = varlist.list;
-			/* we must check 'readonly' flag for all builtins */
-			listsetvar(varlist.list,
-				cmdentry.cmdtype == CMDSPLBLTIN ? 0 : VNOSET);
-			commandname = argv[0];
-			/* initialize nextopt */
-			argptr = argv + 1;
-			optptr = NULL;
-			/* and getopt */
-#if defined(__FreeBSD__) || defined(__EMX__) || defined(__APPLE__)
-			optreset = 1;
-			optind = 1;
-#else
-			optind = 0; /* init */
-#endif
-
-			exitstatus = cmdentry.u.bltin(argc, argv);
-		} else {
-			e = exception;
-			exitstatus = e == EXINT ? SIGINT + 128 :
-					e == EXEXEC ? exerrno : 2;
-		}
-		handler = savehandler;
-		output_flushall();
-		out1 = &output;
-		out2 = &errout;
-		freestdout();
-		if (temp_path) {
-			poplocalvars();
-			localvars = savelocalvars;
-		}
-		cmdenviron = NULL;
-		if (e != EXSHELLPROC) {
-			commandname = savecmdname;
-			if (flags & EV_EXIT)
-				exitshell(exitstatus);
-		}
-		if (e != -1) {
-			if ((e != EXERROR && e != EXEXEC)
-			    || cmdentry.cmdtype == CMDSPLBLTIN)
-				exraise(e);
-			FORCEINTON;
-		}
-		if (cmdentry.u.bltin != execcmd)
-			popredir();
-		if (flags == EV_BACKCMD) {
-			backcmd->buf = memout.buf;
-			backcmd->nleft = memout.nextc - memout.buf;
-			memout.buf = NULL;
-		}
-		break;
-
-	default:
-#ifdef DEBUG
-		trputs("normal command:  ");  trargs(argv);
-#endif
-		clearredir(vforked);
-		redirect(cmd->ncmd.redirect, vforked ? REDIR_VFORK : 0);
-		if (!vforked)
-			for (sp = varlist.list ; sp ; sp = sp->next)
-				setvareq(sp->text, VEXPORT|VSTACK);
-		envp = environment();
-		shellexec(argv, envp, path, cmdentry.u.index, vforked);
-		break;
-	}
-	goto out;
-
-parent:	/* parent process gets here (if we forked) */
-	if (mode == FORK_FG) {	/* argument to fork */
-		exitstatus = waitforjob(jp);
-	} else if (mode == FORK_NOJOB) {
-		backcmd->fd = pip[0];
-		close(pip[1]);
-		backcmd->jp = jp;
-	}
-	FORCEINTON;
-
-out:
-	if (lastarg)
-		/* dsl: I think this is intended to be used to support
-		 * '_' in 'vi' command mode during line editing...
-		 * However I implemented that within libedit itself.
-		 */
-		setvar("_", lastarg, 0);
-	popstackmark(&smark);
-
-	if (eflag && exitstatus && !(flags & EV_TESTED))
-		exitshell(exitstatus);
-}
-
-
-/*
- * Search for a command.  This is called before we fork so that the
- * location of the command will be available in the parent as well as
- * the child.  The check for "goodname" is an overly conservative
- * check that the name will not be subject to expansion.
- */
-
-STATIC void
-prehash(union node *n)
-{
-	struct cmdentry entry;
-
-	if (n->type == NCMD && n->ncmd.args)
-		if (goodname(n->ncmd.args->narg.text))
-			find_command(n->ncmd.args->narg.text, &entry, 0,
-				     pathval());
-}
-
-
-
-/*
- * Builtin commands.  Builtin commands whose functions are closely
- * tied to evaluation are implemented here.
- */
-
-/*
- * No command given.
- */
-
-int
-bltincmd(int argc, char **argv)
-{
-	/*
-	 * Preserve exitstatus of a previous possible redirection
-	 * as POSIX mandates
-	 */
-	return back_exitstatus;
-}
-
-
-/*
- * Handle break and continue commands.  Break, continue, and return are
- * all handled by setting the evalskip flag.  The evaluation routines
- * above all check this flag, and if it is set they start skipping
- * commands rather than executing them.  The variable skipcount is
- * the number of loops to break/continue, or the number of function
- * levels to return.  (The latter is always 1.)  It should probably
- * be an error to break out of more loops than exist, but it isn't
- * in the standard shell so we don't make it one here.
- */
-
-int
-breakcmd(int argc, char **argv)
-{
-	int n = argc > 1 ? number(argv[1]) : 1;
-
-	if (n > loopnest)
-		n = loopnest;
-	if (n > 0) {
-		evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
-		skipcount = n;
-	}
-	return 0;
-}
-
-
-/*
- * The return command.
- */
-
-int
-returncmd(int argc, char **argv)
-{
-#if 0
-	int ret = argc > 1 ? number(argv[1]) : exitstatus;
-#else
-	int ret;
-	if (argc > 1)  {
-		/* make return -1 and VSC lite work ... */
-    		if (argv[1][0] != '-' || !is_number(&argv[1][1]))
-			ret = number(argv[1]);
-		else
-			ret = -number(&argv[1][1]) & 255; /* take the bash approach */
-	} else {
-    		ret = exitstatus;
-	}
-#endif
-
-	if (funcnest) {
-		evalskip = SKIPFUNC;
-		skipcount = 1;
-		return ret;
-	}
-	else {
-		/* Do what ksh does; skip the rest of the file */
-		evalskip = SKIPFILE;
-		skipcount = 1;
-		return ret;
-	}
-}
-
-
-int
-falsecmd(int argc, char **argv)
-{
-	return 1;
-}
-
-
-int
-truecmd(int argc, char **argv)
-{
-	return 0;
-}
-
-
-int
-execcmd(int argc, char **argv)
-{
-	if (argc > 1) {
-		struct strlist *sp;
-
-		iflag = 0;		/* exit on error */
-		mflag = 0;
-		optschanged();
-		for (sp = cmdenviron; sp; sp = sp->next)
-			setvareq(sp->text, VEXPORT|VSTACK);
-		shellexec(argv + 1, environment(), pathval(), 0, 0);
-	}
-	return 0;
-}
-
-static int
-conv_time(clock_t ticks, char *seconds, size_t l)
-{
-	static clock_t tpm = 0;
-	clock_t mins;
-	int i;
-
-	if (!tpm)
-		tpm = sysconf(_SC_CLK_TCK) * 60;
-
-	mins = ticks / tpm;
-	snprintf(seconds, l, "%.4f", (ticks - mins * tpm) * 60.0 / tpm );
-
-	if (seconds[0] == '6' && seconds[1] == '0') {
-		/* 59.99995 got rounded up... */
-		mins++;
-		strlcpy(seconds, "0.0", l);
-		return mins;
-	}
-
-	/* suppress trailing zeros */
-	i = strlen(seconds) - 1;
-	for (; seconds[i] == '0' && seconds[i - 1] != '.'; i--)
-		seconds[i] = 0;
-	return mins;
-}
-
-int
-timescmd(int argc, char **argv)
-{
-	struct tms tms;
-	int u, s, cu, cs;
-	char us[8], ss[8], cus[8], css[8];
-
-	nextopt("");
-
-	times(&tms);
-
-	u = conv_time(tms.tms_utime, us, sizeof(us));
-	s = conv_time(tms.tms_stime, ss, sizeof(ss));
-	cu = conv_time(tms.tms_cutime, cus, sizeof(cus));
-	cs = conv_time(tms.tms_cstime, css, sizeof(css));
-
-	outfmt(out1, "%dm%ss %dm%ss\n%dm%ss %dm%ss\n",
-		u, us, s, ss, cu, cus, cs, css);
-
-	return 0;
-}
diff --git a/src/ash/eval.h b/src/ash/eval.h
deleted file mode 100644
index 155bc44..0000000
--- a/src/ash/eval.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*	$NetBSD: eval.h,v 1.14 2003/08/07 09:05:31 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)eval.h	8.2 (Berkeley) 5/4/95
- */
-
-extern char *commandname;	/* currently executing command */
-extern int exitstatus;		/* exit status of last command */
-extern int back_exitstatus;	/* exit status of backquoted command */
-extern struct strlist *cmdenviron;  /* environment for builtin command */
-
-
-struct backcmd {		/* result of evalbackcmd */
-	int fd;			/* file descriptor to read from */
-	char *buf;		/* buffer */
-	int nleft;		/* number of chars in buffer */
-	struct job *jp;		/* job structure for command */
-};
-
-void evalstring(char *, int);
-union node;	/* BLETCH for ansi C */
-void evaltree(union node *, int);
-void evalbackcmd(union node *, struct backcmd *);
-
-/* in_function returns nonzero if we are currently evaluating a function */
-#define in_function()	funcnest
-extern int funcnest;
-extern int evalskip;
-
-/* reasons for skipping commands (see comment on breakcmd routine) */
-#define SKIPBREAK	1
-#define SKIPCONT	2
-#define SKIPFUNC	3
-#define SKIPFILE	4
diff --git a/src/ash/exec.c b/src/ash/exec.c
deleted file mode 100644
index 31be37f..0000000
--- a/src/ash/exec.c
+++ /dev/null
@@ -1,1199 +0,0 @@
-/*	$NetBSD: exec.c,v 1.37 2003/08/07 09:05:31 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)exec.c	8.4 (Berkeley) 6/8/95";
-#else
-__RCSID("$NetBSD: exec.c,v 1.37 2003/08/07 09:05:31 agc Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/*
- * When commands are first encountered, they are entered in a hash table.
- * This ensures that a full path search will not have to be done for them
- * on each invocation.
- *
- * We should investigate converting to a linear search, even though that
- * would make the command name "hash" a misnomer.
- */
-
-#include "shell.h"
-#include "main.h"
-#include "nodes.h"
-#include "parser.h"
-#include "redir.h"
-#include "eval.h"
-#include "exec.h"
-#include "builtins.h"
-#include "var.h"
-#include "options.h"
-#include "input.h"
-#include "output.h"
-#include "syntax.h"
-#include "memalloc.h"
-#include "error.h"
-#include "init.h"
-#include "mystring.h"
-#include "show.h"
-#include "jobs.h"
-#include "alias.h"
-#ifdef __INNOTEK_LIBC__
-#include <InnoTekLIBC/backend.h>
-#endif
-
-
-#define CMDTABLESIZE 31		/* should be prime */
-#define ARB 1			/* actual size determined at run time */
-
-
-
-struct tblentry {
-	struct tblentry *next;	/* next entry in hash chain */
-	union param param;	/* definition of builtin function */
-	short cmdtype;		/* index identifying command */
-	char rehash;		/* if set, cd done since entry created */
-	char cmdname[ARB];	/* name of command */
-};
-
-
-STATIC struct tblentry *cmdtable[CMDTABLESIZE];
-STATIC int builtinloc = -1;		/* index in path of %builtin, or -1 */
-int exerrno = 0;			/* Last exec error */
-
-
-STATIC void tryexec(char *, char **, char **, int, int);
-STATIC void execinterp(char **, char **);
-STATIC void printentry(struct tblentry *, int);
-STATIC void clearcmdentry(int);
-STATIC struct tblentry *cmdlookup(const char *, int);
-STATIC void delete_cmd_entry(void);
-#ifdef PC_EXE_EXTS
-STATIC int stat_pc_exec_exts(char *fullname, struct stat *st, int has_ext);
-#endif
-
-
-extern char *const parsekwd[];
-
-/*
- * Exec a program.  Never returns.  If you change this routine, you may
- * have to change the find_command routine as well.
- */
-
-void
-shellexec(char **argv, char **envp, const char *path, int idx, int vforked)
-{
-	char *cmdname;
-	int e;
-#ifdef PC_EXE_EXTS
-        int has_ext = strlen(argv[0]) - 4;
-        has_ext = has_ext > 0
-            && argv[0][has_ext] == '.'
-            /* use strstr and upper/lower permuated extensions to avoid multiple strcasecmp calls. */
-            && strstr("exe;" "Exe;" "EXe;" "EXE;" "ExE;" "eXe;" "eXE;" "exE;"
-                      "cmd;" "Cmd;" "CMd;" "CMD;" "CmD;" "cMd;" "cMD;" "cmD;"
-                      "com;" "Com;" "COm;" "COM;" "CoM;" "cOm;" "cOM;" "coM;"
-                      "bat;" "Bat;" "BAt;" "BAT;" "BaT;" "bAt;" "bAT;" "baT;"
-                      "btm;" "Btm;" "BTm;" "BTM;" "BtM;" "bTm;" "bTM;" "btM;",
-                      argv[0] + has_ext + 1)
-               != NULL;
-#else
-	const int has_ext = 1;
-#endif
-	TRACE(("shellexec: argv[0]=%s idx=%d\n", argv[0], idx));
-	if (strchr(argv[0], '/') != NULL) {
-		cmdname = stalloc(strlen(argv[0]) + 5);
-		strcpy(cmdname, argv[0]);
-		tryexec(cmdname, argv, envp, vforked, has_ext);
-		TRACE(("shellexec: cmdname=%s\n", cmdname));
-		stunalloc(cmdname);
-		e = errno;
-	} else {
-		e = ENOENT;
-		while ((cmdname = padvance(&path, argv[0])) != NULL) {
-			if (--idx < 0 && pathopt == NULL) {
-				tryexec(cmdname, argv, envp, vforked, has_ext);
-				if (errno != ENOENT && errno != ENOTDIR)
-					e = errno;
-			}
-			stunalloc(cmdname);
-		}
-	}
-
-	/* Map to POSIX errors */
-	switch (e) {
-	case EACCES:
-		exerrno = 126;
-		break;
-	case ENOENT:
-		exerrno = 127;
-		break;
-	default:
-		exerrno = 2;
-		break;
-	}
-	TRACE(("shellexec failed for '%s', errno %d, vforked %d, suppressint %d\n",
-		argv[0], e, vforked, suppressint ));
-	exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC));
-	/* NOTREACHED */
-}
-
-
-STATIC void
-tryexec(char *cmd, char **argv, char **envp, int vforked, int has_ext)
-{
-	int e;
-#ifdef EXEC_HASH_BANG_SCRIPT
-	char *p;
-#endif
-#ifdef PC_EXE_EXTS
-        /* exploit the effect of stat_pc_exec_exts which adds the
-         * correct extentions to the file.
-         */
-        struct stat st;
-        if (!has_ext)
-            stat_pc_exec_exts(cmd, &st, 0);
-#endif
-#if defined __INNOTEK_LIBC__ && defined EXEC_HASH_BANG_SCRIPT
-	__libc_Back_gfProcessHandleHashBangScripts = 0;
-#endif
-
-#ifdef SYSV
-	do {
-		execve(cmd, argv, envp);
-	} while (errno == EINTR);
-#else
-	execve(cmd, argv, envp);
-#endif
-	e = errno;
-	if (e == ENOEXEC) {
-		if (vforked) {
-			/* We are currently vfork(2)ed, so raise an
-			 * exception, and evalcommand will try again
-			 * with a normal fork(2).
-			 */
-			exraise(EXSHELLPROC);
-		}
-		initshellproc();
-		setinputfile(cmd, 0);
-		commandname = arg0 = savestr(argv[0]);
-#ifdef EXEC_HASH_BANG_SCRIPT
-		pgetc(); pungetc();		/* fill up input buffer */
-		p = parsenextc;
-		if (parsenleft > 2 && p[0] == '#' && p[1] == '!') {
-			argv[0] = cmd;
-			execinterp(argv, envp);
-		}
-#endif
-		setparam(argv + 1);
-		exraise(EXSHELLPROC);
-	}
-	errno = e;
-}
-
-
-#ifdef EXEC_HASH_BANG_SCRIPT
-/*
- * Execute an interpreter introduced by "#!", for systems where this
- * feature has not been built into the kernel.  If the interpreter is
- * the shell, return (effectively ignoring the "#!").  If the execution
- * of the interpreter fails, exit.
- *
- * This code peeks inside the input buffer in order to avoid actually
- * reading any input.  It would benefit from a rewrite.
- */
-
-#define NEWARGS 5
-
-STATIC void
-execinterp(char **argv, char **envp)
-{
-	int n;
-	char *inp;
-	char *outp;
-	char c;
-	char *p;
-	char **ap;
-	char *newargs[NEWARGS];
-	int i;
-	char **ap2;
-	char **new;
-
-	n = parsenleft - 2;
-	inp = parsenextc + 2;
-	ap = newargs;
-	for (;;) {
-		while (--n >= 0 && (*inp == ' ' || *inp == '\t'))
-			inp++;
-		if (n < 0)
-			goto bad;
-		if ((c = *inp++) == '\n')
-			break;
-		if (ap == &newargs[NEWARGS])
-bad:		  error("Bad #! line");
-		STARTSTACKSTR(outp);
-		do {
-			STPUTC(c, outp);
-		} while (--n >= 0 && (c = *inp++) != ' ' && c != '\t' && c != '\n');
-		STPUTC('\0', outp);
-		n++, inp--;
-		*ap++ = grabstackstr(outp);
-	}
-	if (ap == newargs + 1) {	/* if no args, maybe no exec is needed */
-		p = newargs[0];
-		for (;;) {
-			if (equal(p, "sh") || equal(p, "ash")) {
-				TRACE(("hash bang self\n"));
-				return;
-			}
-			while (*p != '/') {
-				if (*p == '\0')
-					goto break2;
-				p++;
-			}
-			p++;
-		}
-break2:;
-	}
-	i = (char *)ap - (char *)newargs;		/* size in bytes */
-	if (i == 0)
-		error("Bad #! line");
-	for (ap2 = argv ; *ap2++ != NULL ; );
-	new = ckmalloc(i + ((char *)ap2 - (char *)argv));
-	ap = newargs, ap2 = new;
-	while ((i -= sizeof (char **)) >= 0)
-		*ap2++ = *ap++;
-	ap = argv;
-	while (*ap2++ = *ap++);
-	TRACE(("hash bang '%s'\n", new[0]));
-	shellexec(new, envp, pathval(), 0, 0);
-	/* NOTREACHED */
-}
-#endif
-
-
-
-/*
- * Do a path search.  The variable path (passed by reference) should be
- * set to the start of the path before the first call; padvance will update
- * this value as it proceeds.  Successive calls to padvance will return
- * the possible path expansions in sequence.  If an option (indicated by
- * a percent sign) appears in the path entry then the global variable
- * pathopt will be set to point to it; otherwise pathopt will be set to
- * NULL.
- */
-
-const char *pathopt;
-
-char *
-padvance(const char **path, const char *name)
-{
-	const char *p;
-	char *q;
-#ifdef PC_SLASHES
-	char *s;
-#endif
-	const char *start;
-	int len;
-
-	if (*path == NULL)
-		return NULL;
-	start = *path;
-#ifdef PC_PATH_SEP
-	for (p = start ; *p && *p != ';' && *p != '%' ; p++);
-#else
-	for (p = start ; *p && *p != ':' && *p != '%' ; p++);
-#endif
-	len = p - start + strlen(name) + 2;	/* "2" is for '/' and '\0' */
-#ifdef PC_EXE_EXTS
-        len += 4; /* "4" is for .exe/.com/.cmd/.bat/.btm */
-#endif
-	while (stackblocksize() < len)
-		growstackblock();
-#ifdef PC_SLASHES
-	s =
-#endif
-	q = stackblock();
-	if (p != start) {
-		memcpy(q, start, p - start);
-		q += p - start;
-		*q++ = '/';
-	}
-	strcpy(q, name);
-#ifdef PC_SLASHES
-	while ((s = strchr(s, '\\')) != NULL)
-		*s++ = '/';
-#endif
-	pathopt = NULL;
-	if (*p == '%') {
-		pathopt = ++p;
-#ifdef PC_PATH_SEP
-		while (*p && *p != ';')  p++;
-#else
-		while (*p && *p != ':')  p++;
-#endif
-	}
-#ifdef PC_PATH_SEP
-	if (*p == ';')
-#else
-	if (*p == ':')
-#endif
-		*path = p + 1;
-	else
-		*path = NULL;
-	return stalloc(len);
-}
-
-
-#ifdef PC_EXE_EXTS
-STATIC int stat_pc_exec_exts(char *fullname, struct stat *st, int has_ext)
-{
-    /* skip the SYSV crap */
-    if (stat(fullname, st) >= 0)
-        return 0;
-    if (!has_ext && errno == ENOENT)
-    {
-        char *psz = strchr(fullname, '\0');
-        memcpy(psz, ".exe", 5);
-        if (stat(fullname, st) >= 0)
-            return 0;
-        if (errno != ENOENT && errno != ENOTDIR)
-            return -1;
-
-        memcpy(psz, ".cmd", 5);
-        if (stat(fullname, st) >= 0)
-            return 0;
-        if (errno != ENOENT && errno != ENOTDIR)
-            return -1;
-
-        memcpy(psz, ".bat", 5);
-        if (stat(fullname, st) >= 0)
-            return 0;
-        if (errno != ENOENT && errno != ENOTDIR)
-            return -1;
-
-        memcpy(psz, ".com", 5);
-        if (stat(fullname, st) >= 0)
-            return 0;
-        if (errno != ENOENT && errno != ENOTDIR)
-            return -1;
-
-        memcpy(psz, ".btm", 5);
-        if (stat(fullname, st) >= 0)
-            return 0;
-        *psz = '\0';
-    }
-    return -1;
-}
-#endif /* PC_EXE_EXTS */
-
-
-
-/*** Command hashing code ***/
-
-
-int
-hashcmd(int argc, char **argv)
-{
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-	int c;
-	int verbose;
-	struct cmdentry entry;
-	char *name;
-
-	verbose = 0;
-	while ((c = nextopt("rv")) != '\0') {
-		if (c == 'r') {
-			clearcmdentry(0);
-		} else if (c == 'v') {
-			verbose++;
-		}
-	}
-	if (*argptr == NULL) {
-		for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
-			for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-				if (verbose || cmdp->cmdtype == CMDNORMAL)
-					printentry(cmdp, verbose);
-			}
-		}
-		return 0;
-	}
-	while ((name = *argptr) != NULL) {
-		if ((cmdp = cmdlookup(name, 0)) != NULL
-		 && (cmdp->cmdtype == CMDNORMAL
-		     || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)))
-			delete_cmd_entry();
-		find_command(name, &entry, DO_ERR, pathval());
-		if (verbose) {
-			if (entry.cmdtype != CMDUNKNOWN) {	/* if no error msg */
-				cmdp = cmdlookup(name, 0);
-				printentry(cmdp, verbose);
-			}
-			output_flushall();
-		}
-		argptr++;
-	}
-	return 0;
-}
-
-
-STATIC void
-printentry(struct tblentry *cmdp, int verbose)
-{
-	int idx;
-	const char *path;
-	char *name;
-
-	switch (cmdp->cmdtype) {
-	case CMDNORMAL:
-		idx = cmdp->param.index;
-		path = pathval();
-		do {
-			name = padvance(&path, cmdp->cmdname);
-			stunalloc(name);
-		} while (--idx >= 0);
-		out1str(name);
-		break;
-	case CMDSPLBLTIN:
-		out1fmt("special builtin %s", cmdp->cmdname);
-		break;
-	case CMDBUILTIN:
-		out1fmt("builtin %s", cmdp->cmdname);
-		break;
-	case CMDFUNCTION:
-		out1fmt("function %s", cmdp->cmdname);
-		if (verbose) {
-			struct procstat ps;
-			INTOFF;
-			commandtext(&ps, cmdp->param.func);
-			INTON;
-			out1str("() { ");
-			out1str(ps.cmd);
-			out1str("; }");
-		}
-		break;
-	default:
-		error("internal error: %s cmdtype %d", cmdp->cmdname, cmdp->cmdtype);
-	}
-	if (cmdp->rehash)
-		out1c('*');
-	out1c('\n');
-}
-
-
-
-/*
- * Resolve a command name.  If you change this routine, you may have to
- * change the shellexec routine as well.
- */
-
-void
-find_command(char *name, struct cmdentry *entry, int act, const char *path)
-{
-	struct tblentry *cmdp, loc_cmd;
-	int idx;
-	int prev;
-	char *fullname;
-	struct stat statb;
-	int e;
-	int (*bltin)(int,char **);
-
-#ifdef PC_EXE_EXTS
-        int has_ext = strlen(name) - 4;
-        has_ext = has_ext > 0
-            && name[has_ext] == '.'
-            /* use strstr and upper/lower permuated extensions to avoid multiple strcasecmp calls. */
-            && strstr("exe;" "Exe;" "EXe;" "EXE;" "ExE;" "eXe;" "eXE;" "exE;"
-                      "cmd;" "Cmd;" "CMd;" "CMD;" "CmD;" "cMd;" "cMD;" "cmD;"
-                      "com;" "Com;" "COm;" "COM;" "CoM;" "cOm;" "cOM;" "coM;"
-                      "bat;" "Bat;" "BAt;" "BAT;" "BaT;" "bAt;" "bAT;" "baT;"
-                      "btm;" "Btm;" "BTm;" "BTM;" "BtM;" "bTm;" "bTM;" "btM;",
-                      name + has_ext + 1)
-               != NULL;
-#endif
-
-	/* If name contains a slash, don't use PATH or hash table */
-	if (strchr(name, '/') != NULL) {
-		if (act & DO_ABS) {
-			while (stat(name, &statb) < 0) {
-#ifdef SYSV
-				if (errno == EINTR)
-					continue;
-#endif
-				if (errno != ENOENT && errno != ENOTDIR)
-					e = errno;
-				entry->cmdtype = CMDUNKNOWN;
-				entry->u.index = -1;
-				return;
-			}
-			entry->cmdtype = CMDNORMAL;
-			entry->u.index = -1;
-			return;
-		}
-		entry->cmdtype = CMDNORMAL;
-		entry->u.index = 0;
-		return;
-	}
-
-	if (path != pathval())
-		act |= DO_ALTPATH;
-
-	if (act & DO_ALTPATH && strstr(path, "%builtin") != NULL)
-		act |= DO_ALTBLTIN;
-
-	/* If name is in the table, check answer will be ok */
-	if ((cmdp = cmdlookup(name, 0)) != NULL) {
-		do {
-			switch (cmdp->cmdtype) {
-			case CMDNORMAL:
-				if (act & DO_ALTPATH) {
-					cmdp = NULL;
-					continue;
-				}
-				break;
-			case CMDFUNCTION:
-				if (act & DO_NOFUNC) {
-					cmdp = NULL;
-					continue;
-				}
-				break;
-			case CMDBUILTIN:
-				if ((act & DO_ALTBLTIN) || builtinloc >= 0) {
-					cmdp = NULL;
-					continue;
-				}
-				break;
-			}
-			/* if not invalidated by cd, we're done */
-			if (cmdp->rehash == 0)
-				goto success;
-		} while (0);
-	}
-
-	/* If %builtin not in path, check for builtin next */
-	if ((act & DO_ALTPATH ? !(act & DO_ALTBLTIN) : builtinloc < 0) &&
-	    (bltin = find_builtin(name)) != 0)
-		goto builtin_success;
-
-	/* We have to search path. */
-	prev = -1;		/* where to start */
-	if (cmdp) {		/* doing a rehash */
-		if (cmdp->cmdtype == CMDBUILTIN)
-			prev = builtinloc;
-		else
-			prev = cmdp->param.index;
-	}
-
-	e = ENOENT;
-	idx = -1;
-loop:
-	while ((fullname = padvance(&path, name)) != NULL) {
-		stunalloc(fullname);
-		idx++;
-		if (pathopt) {
-			if (prefix("builtin", pathopt)) {
-				if ((bltin = find_builtin(name)) == 0)
-					goto loop;
-				goto builtin_success;
-			} else if (prefix("func", pathopt)) {
-				/* handled below */
-			} else {
-				/* ignore unimplemented options */
-				goto loop;
-			}
-		}
-		/* if rehash, don't redo absolute path names */
-		if (fullname[0] == '/' && idx <= prev) {
-			if (idx < prev)
-				goto loop;
-			TRACE(("searchexec \"%s\": no change\n", name));
-			goto success;
-		}
-#ifdef PC_EXE_EXTS
-		while (stat_pc_exec_exts(fullname, &statb, has_ext) < 0) {
-#else
-		while (stat(fullname, &statb) < 0) {
-#endif
-#ifdef SYSV
-			if (errno == EINTR)
-				continue;
-#endif
-			if (errno != ENOENT && errno != ENOTDIR)
-				e = errno;
-
-			goto loop;
-		}
-		e = EACCES;	/* if we fail, this will be the error */
-		if (!S_ISREG(statb.st_mode))
-			goto loop;
-		if (pathopt) {		/* this is a %func directory */
-			if (act & DO_NOFUNC)
-				goto loop;
-			stalloc(strlen(fullname) + 1);
-			readcmdfile(fullname);
-			if ((cmdp = cmdlookup(name, 0)) == NULL ||
-			    cmdp->cmdtype != CMDFUNCTION)
-				error("%s not defined in %s", name, fullname);
-			stunalloc(fullname);
-			goto success;
-		}
-#ifdef notdef
-		/* XXX this code stops root executing stuff, and is buggy
-		   if you need a group from the group list. */
-		if (statb.st_uid == geteuid()) {
-			if ((statb.st_mode & 0100) == 0)
-				goto loop;
-		} else if (statb.st_gid == getegid()) {
-			if ((statb.st_mode & 010) == 0)
-				goto loop;
-		} else {
-			if ((statb.st_mode & 01) == 0)
-				goto loop;
-		}
-#endif
-		TRACE(("searchexec \"%s\" returns \"%s\"\n", name, fullname));
-		INTOFF;
-		if (act & DO_ALTPATH) {
-			stalloc(strlen(fullname) + 1);
-			cmdp = &loc_cmd;
-		} else
-			cmdp = cmdlookup(name, 1);
-		cmdp->cmdtype = CMDNORMAL;
-		cmdp->param.index = idx;
-		INTON;
-		goto success;
-	}
-
-	/* We failed.  If there was an entry for this command, delete it */
-	if (cmdp)
-		delete_cmd_entry();
-	if (act & DO_ERR)
-		outfmt(out2, "%s: %s\n", name, errmsg(e, E_EXEC));
-	entry->cmdtype = CMDUNKNOWN;
-	return;
-
-builtin_success:
-	INTOFF;
-	if (act & DO_ALTPATH)
-		cmdp = &loc_cmd;
-	else
-		cmdp = cmdlookup(name, 1);
-	if (cmdp->cmdtype == CMDFUNCTION)
-		/* DO_NOFUNC must have been set */
-		cmdp = &loc_cmd;
-	cmdp->cmdtype = CMDBUILTIN;
-	cmdp->param.bltin = bltin;
-	INTON;
-success:
-	cmdp->rehash = 0;
-	entry->cmdtype = cmdp->cmdtype;
-	entry->u = cmdp->param;
-}
-
-
-
-/*
- * Search the table of builtin commands.
- */
-
-int
-(*find_builtin(name))(int, char **)
-	char *name;
-{
-	const struct builtincmd *bp;
-
-	for (bp = builtincmd ; bp->name ; bp++) {
-		if (*bp->name == *name && equal(bp->name, name))
-			return bp->builtin;
-	}
-	return 0;
-}
-
-int
-(*find_splbltin(name))(int, char **)
-	char *name;
-{
-	const struct builtincmd *bp;
-
-	for (bp = splbltincmd ; bp->name ; bp++) {
-		if (*bp->name == *name && equal(bp->name, name))
-			return bp->builtin;
-	}
-	return 0;
-}
-
-/*
- * At shell startup put special builtins into hash table.
- * ensures they are executed first (see posix).
- * We stop functions being added with the same name
- * (as they are impossible to call)
- */
-
-void
-hash_special_builtins(void)
-{
-	const struct builtincmd *bp;
-	struct tblentry *cmdp;
-
-	for (bp = splbltincmd ; bp->name ; bp++) {
-		cmdp = cmdlookup(bp->name, 1);
-		cmdp->cmdtype = CMDSPLBLTIN;
-		cmdp->param.bltin = bp->builtin;
-	}
-}
-
-
-
-/*
- * Called when a cd is done.  Marks all commands so the next time they
- * are executed they will be rehashed.
- */
-
-void
-hashcd(void)
-{
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-
-	for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
-		for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-			if (cmdp->cmdtype == CMDNORMAL
-			 || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
-				cmdp->rehash = 1;
-		}
-	}
-}
-
-
-
-/*
- * Fix command hash table when PATH changed.
- * Called before PATH is changed.  The argument is the new value of PATH;
- * pathval() still returns the old value at this point.
- * Called with interrupts off.
- */
-
-void
-changepath(const char *newval)
-{
-	const char *old, *new;
-	int idx;
-	int firstchange;
-	int bltin;
-
-	old = pathval();
-	new = newval;
-	firstchange = 9999;	/* assume no change */
-	idx = 0;
-	bltin = -1;
-	for (;;) {
-		if (*old != *new) {
-			firstchange = idx;
-#ifdef PC_PATH_SEP
-			if ((*old == '\0' && *new == ';')
-			 || (*old == ';' && *new == '\0'))
-#else
-			if ((*old == '\0' && *new == ':')
-			 || (*old == ':' && *new == '\0'))
-#endif
-				firstchange++;
-			old = new;	/* ignore subsequent differences */
-		}
-		if (*new == '\0')
-			break;
-		if (*new == '%' && bltin < 0 && prefix("builtin", new + 1))
-			bltin = idx;
-#ifdef PC_PATH_SEP
-		if (*new == ';') {
-#else
-		if (*new == ':') {
-#endif
-			idx++;
-		}
-		new++, old++;
-	}
-	if (builtinloc < 0 && bltin >= 0)
-		builtinloc = bltin;		/* zap builtins */
-	if (builtinloc >= 0 && bltin < 0)
-		firstchange = 0;
-	clearcmdentry(firstchange);
-	builtinloc = bltin;
-}
-
-
-/*
- * Clear out command entries.  The argument specifies the first entry in
- * PATH which has changed.
- */
-
-STATIC void
-clearcmdentry(int firstchange)
-{
-	struct tblentry **tblp;
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-
-	INTOFF;
-	for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
-		pp = tblp;
-		while ((cmdp = *pp) != NULL) {
-			if ((cmdp->cmdtype == CMDNORMAL &&
-			     cmdp->param.index >= firstchange)
-			 || (cmdp->cmdtype == CMDBUILTIN &&
-			     builtinloc >= firstchange)) {
-				*pp = cmdp->next;
-				ckfree(cmdp);
-			} else {
-				pp = &cmdp->next;
-			}
-		}
-	}
-	INTON;
-}
-
-
-/*
- * Delete all functions.
- */
-
-#ifdef mkinit
-MKINIT void deletefuncs(void);
-MKINIT void hash_special_builtins(void);
-
-INIT {
-	hash_special_builtins();
-}
-
-SHELLPROC {
-	deletefuncs();
-}
-#endif
-
-void
-deletefuncs(void)
-{
-	struct tblentry **tblp;
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-
-	INTOFF;
-	for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
-		pp = tblp;
-		while ((cmdp = *pp) != NULL) {
-			if (cmdp->cmdtype == CMDFUNCTION) {
-				*pp = cmdp->next;
-				freefunc(cmdp->param.func);
-				ckfree(cmdp);
-			} else {
-				pp = &cmdp->next;
-			}
-		}
-	}
-	INTON;
-}
-
-
-
-/*
- * Locate a command in the command hash table.  If "add" is nonzero,
- * add the command to the table if it is not already present.  The
- * variable "lastcmdentry" is set to point to the address of the link
- * pointing to the entry, so that delete_cmd_entry can delete the
- * entry.
- */
-
-struct tblentry **lastcmdentry;
-
-
-STATIC struct tblentry *
-cmdlookup(const char *name, int add)
-{
-	int hashval;
-	const char *p;
-	struct tblentry *cmdp;
-	struct tblentry **pp;
-
-	p = name;
-	hashval = *p << 4;
-	while (*p)
-		hashval += *p++;
-	hashval &= 0x7FFF;
-	pp = &cmdtable[hashval % CMDTABLESIZE];
-	for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-		if (equal(cmdp->cmdname, name))
-			break;
-		pp = &cmdp->next;
-	}
-	if (add && cmdp == NULL) {
-		INTOFF;
-		cmdp = *pp = ckmalloc(sizeof (struct tblentry) - ARB
-					+ strlen(name) + 1);
-		cmdp->next = NULL;
-		cmdp->cmdtype = CMDUNKNOWN;
-		cmdp->rehash = 0;
-		strcpy(cmdp->cmdname, name);
-		INTON;
-	}
-	lastcmdentry = pp;
-	return cmdp;
-}
-
-/*
- * Delete the command entry returned on the last lookup.
- */
-
-STATIC void
-delete_cmd_entry(void)
-{
-	struct tblentry *cmdp;
-
-	INTOFF;
-	cmdp = *lastcmdentry;
-	*lastcmdentry = cmdp->next;
-	ckfree(cmdp);
-	INTON;
-}
-
-
-
-#ifdef notdef
-void
-getcmdentry(char *name, struct cmdentry *entry)
-{
-	struct tblentry *cmdp = cmdlookup(name, 0);
-
-	if (cmdp) {
-		entry->u = cmdp->param;
-		entry->cmdtype = cmdp->cmdtype;
-	} else {
-		entry->cmdtype = CMDUNKNOWN;
-		entry->u.index = 0;
-	}
-}
-#endif
-
-
-/*
- * Add a new command entry, replacing any existing command entry for
- * the same name - except special builtins.
- */
-
-STATIC void
-addcmdentry(char *name, struct cmdentry *entry)
-{
-	struct tblentry *cmdp;
-
-	INTOFF;
-	cmdp = cmdlookup(name, 1);
-	if (cmdp->cmdtype != CMDSPLBLTIN) {
-		if (cmdp->cmdtype == CMDFUNCTION) {
-			freefunc(cmdp->param.func);
-		}
-		cmdp->cmdtype = entry->cmdtype;
-		cmdp->param = entry->u;
-	}
-	INTON;
-}
-
-
-/*
- * Define a shell function.
- */
-
-void
-defun(char *name, union node *func)
-{
-	struct cmdentry entry;
-
-	INTOFF;
-	entry.cmdtype = CMDFUNCTION;
-	entry.u.func = copyfunc(func);
-	addcmdentry(name, &entry);
-	INTON;
-}
-
-
-/*
- * Delete a function if it exists.
- */
-
-int
-unsetfunc(char *name)
-{
-	struct tblentry *cmdp;
-
-	if ((cmdp = cmdlookup(name, 0)) != NULL &&
-	    cmdp->cmdtype == CMDFUNCTION) {
-		freefunc(cmdp->param.func);
-		delete_cmd_entry();
-		return (0);
-	}
-	return (1);
-}
-
-/*
- * Locate and print what a word is...
- * also used for 'command -[v|V]'
- */
-
-int
-typecmd(int argc, char **argv)
-{
-	struct cmdentry entry;
-	struct tblentry *cmdp;
-	char * const *pp;
-	struct alias *ap;
-	int err = 0;
-	char *arg;
-	int c;
-	int V_flag = 0;
-	int v_flag = 0;
-	int p_flag = 0;
-
-	while ((c = nextopt("vVp")) != 0) {
-		switch (c) {
-		case 'v': v_flag = 1; break;
-		case 'V': V_flag = 1; break;
-		case 'p': p_flag = 1; break;
-		}
-	}
-
-	if (p_flag && (v_flag || V_flag))
-		error("cannot specify -p with -v or -V");
-
-	while ((arg = *argptr++)) {
-		if (!v_flag)
-			out1str(arg);
-		/* First look at the keywords */
-		for (pp = parsekwd; *pp; pp++)
-			if (**pp == *arg && equal(*pp, arg))
-				break;
-
-		if (*pp) {
-			if (v_flag)
-				err = 1;
-			else
-				out1str(" is a shell keyword\n");
-			continue;
-		}
-
-		/* Then look at the aliases */
-		if ((ap = lookupalias(arg, 1)) != NULL) {
-			if (!v_flag)
-				out1fmt(" is an alias for \n");
-			out1fmt("%s\n", ap->val);
-			continue;
-		}
-
-		/* Then check if it is a tracked alias */
-		if ((cmdp = cmdlookup(arg, 0)) != NULL) {
-			entry.cmdtype = cmdp->cmdtype;
-			entry.u = cmdp->param;
-		} else {
-			/* Finally use brute force */
-			find_command(arg, &entry, DO_ABS, pathval());
-		}
-
-		switch (entry.cmdtype) {
-		case CMDNORMAL: {
-			if (strchr(arg, '/') == NULL) {
-				const char *path = pathval();
-				char *name;
-				int j = entry.u.index;
-				do {
-					name = padvance(&path, arg);
-					stunalloc(name);
-				} while (--j >= 0);
-				if (!v_flag)
-					out1fmt(" is%s ",
-					    cmdp ? " a tracked alias for" : "");
-				out1fmt("%s\n", name);
-			} else {
-				if (access(arg, X_OK) == 0) {
-					if (!v_flag)
-						out1fmt(" is ");
-					out1fmt("%s\n", arg);
-				} else {
-					if (!v_flag)
-						out1fmt(": %s\n",
-						    strerror(errno));
-					else
-						err = 126;
-				}
-			}
- 			break;
-		}
-		case CMDFUNCTION:
-			if (!v_flag)
-				out1str(" is a shell function\n");
-			else
-				out1fmt("%s\n", arg);
-			break;
-
-		case CMDBUILTIN:
-			if (!v_flag)
-				out1str(" is a shell builtin\n");
-			else
-				out1fmt("%s\n", arg);
-			break;
-
-		case CMDSPLBLTIN:
-			if (!v_flag)
-				out1str(" is a special shell builtin\n");
-			else
-				out1fmt("%s\n", arg);
-			break;
-
-		default:
-			if (!v_flag)
-				out1str(": not found\n");
-			err = 127;
-			break;
-		}
-	}
-	return err;
-}
diff --git a/src/ash/exec.h b/src/ash/exec.h
deleted file mode 100644
index 26fd09c..0000000
--- a/src/ash/exec.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*	$NetBSD: exec.h,v 1.21 2003/08/07 09:05:31 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)exec.h	8.3 (Berkeley) 6/8/95
- */
-
-/* values of cmdtype */
-#define CMDUNKNOWN	-1	/* no entry in table for command */
-#define CMDNORMAL	0	/* command is an executable program */
-#define CMDFUNCTION	1	/* command is a shell function */
-#define CMDBUILTIN	2	/* command is a shell builtin */
-#define CMDSPLBLTIN	3	/* command is a special shell builtin */
-
-
-struct cmdentry {
-	int cmdtype;
-	union param {
-		int index;
-		int (*bltin)(int, char**);
-		union node *func;
-	} u;
-};
-
-
-/* action to find_command() */
-#define DO_ERR		0x01	/* prints errors */
-#define DO_ABS		0x02	/* checks absolute paths */
-#define DO_NOFUNC	0x04	/* don't return shell functions, for command */
-#define DO_ALTPATH	0x08	/* using alternate path */
-#define DO_ALTBLTIN	0x20	/* %builtin in alt. path */
-
-extern const char *pathopt;	/* set by padvance */
-
-void shellexec(char **, char **, const char *, int, int)
-    __attribute__((__noreturn__));
-char *padvance(const char **, const char *);
-int hashcmd(int, char **);
-void find_command(char *, struct cmdentry *, int, const char *);
-int (*find_builtin(char *))(int, char **);
-int (*find_splbltin(char *))(int, char **);
-void hashcd(void);
-void changepath(const char *);
-void deletefuncs(void);
-void getcmdentry(char *, struct cmdentry *);
-void addcmdentry(char *, struct cmdentry *);
-void defun(char *, union node *);
-int unsetfunc(char *);
-int typecmd(int, char **);
-void hash_special_builtins(void);
diff --git a/src/ash/expand.c b/src/ash/expand.c
deleted file mode 100644
index 4c54d34..0000000
--- a/src/ash/expand.c
+++ /dev/null
@@ -1,1569 +0,0 @@
-/*	$NetBSD: expand.c,v 1.71 2005/06/01 15:41:19 lukem Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)expand.c	8.5 (Berkeley) 5/15/95";
-#else
-__RCSID("$NetBSD: expand.c,v 1.71 2005/06/01 15:41:19 lukem Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#ifdef __sun__
-#include <iso/limits_iso.h>
-#endif
-
-/*
- * Routines to expand arguments to commands.  We have to deal with
- * backquotes, shell variables, and file metacharacters.
- */
-
-#include "shell.h"
-#include "main.h"
-#include "nodes.h"
-#include "eval.h"
-#include "expand.h"
-#include "syntax.h"
-#include "parser.h"
-#include "jobs.h"
-#include "options.h"
-#include "var.h"
-#include "input.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#include "show.h"
-
-/*
- * Structure specifying which parts of the string should be searched
- * for IFS characters.
- */
-
-struct ifsregion {
-	struct ifsregion *next;	/* next region in list */
-	int begoff;		/* offset of start of region */
-	int endoff;		/* offset of end of region */
-	int inquotes;		/* search for nul bytes only */
-};
-
-
-char *expdest;			/* output of current string */
-struct nodelist *argbackq;	/* list of back quote expressions */
-struct ifsregion ifsfirst;	/* first struct in list of ifs regions */
-struct ifsregion *ifslastp;	/* last struct in list */
-struct arglist exparg;		/* holds expanded arg list */
-
-STATIC void argstr(char *, int);
-STATIC char *exptilde(char *, int);
-STATIC void expbackq(union node *, int, int);
-STATIC int subevalvar(char *, char *, int, int, int, int);
-STATIC char *evalvar(char *, int);
-STATIC int varisset(char *, int);
-STATIC void varvalue(char *, int, int, int);
-STATIC void recordregion(int, int, int);
-STATIC void removerecordregions(int);
-STATIC void ifsbreakup(char *, struct arglist *);
-STATIC void ifsfree(void);
-STATIC void expandmeta(struct strlist *, int);
-STATIC void expmeta(char *, char *);
-STATIC void addfname(char *);
-STATIC struct strlist *expsort(struct strlist *);
-STATIC struct strlist *msort(struct strlist *, int);
-STATIC int pmatch(char *, char *, int);
-STATIC char *cvtnum(int, char *);
-
-/*
- * Expand shell variables and backquotes inside a here document.
- */
-
-void
-expandhere(union node *arg, int fd)
-{
-	herefd = fd;
-	expandarg(arg, (struct arglist *)NULL, 0);
-	xwrite(fd, stackblock(), expdest - stackblock());
-}
-
-
-/*
- * Perform variable substitution and command substitution on an argument,
- * placing the resulting list of arguments in arglist.  If EXP_FULL is true,
- * perform splitting and file name expansion.  When arglist is NULL, perform
- * here document expansion.
- */
-
-void
-expandarg(union node *arg, struct arglist *arglist, int flag)
-{
-	struct strlist *sp;
-	char *p;
-
-	argbackq = arg->narg.backquote;
-	STARTSTACKSTR(expdest);
-	ifsfirst.next = NULL;
-	ifslastp = NULL;
-	argstr(arg->narg.text, flag);
-	if (arglist == NULL) {
-		return;			/* here document expanded */
-	}
-	STPUTC('\0', expdest);
-	p = grabstackstr(expdest);
-	exparg.lastp = &exparg.list;
-	/*
-	 * TODO - EXP_REDIR
-	 */
-	if (flag & EXP_FULL) {
-		ifsbreakup(p, &exparg);
-		*exparg.lastp = NULL;
-		exparg.lastp = &exparg.list;
-		expandmeta(exparg.list, flag);
-	} else {
-		if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
-			rmescapes(p);
-		sp = (struct strlist *)stalloc(sizeof (struct strlist));
-		sp->text = p;
-		*exparg.lastp = sp;
-		exparg.lastp = &sp->next;
-	}
-	ifsfree();
-	*exparg.lastp = NULL;
-	if (exparg.list) {
-		*arglist->lastp = exparg.list;
-		arglist->lastp = exparg.lastp;
-	}
-}
-
-
-
-/*
- * Perform variable and command substitution.
- * If EXP_FULL is set, output CTLESC characters to allow for further processing.
- * Otherwise treat $@ like $* since no splitting will be performed.
- */
-
-STATIC void
-argstr(char *p, int flag)
-{
-	char c;
-	int quotes = flag & (EXP_FULL | EXP_CASE);	/* do CTLESC */
-	int firsteq = 1;
-	const char *ifs = NULL;
-	int ifs_split = EXP_IFS_SPLIT;
-
-	if (flag & EXP_IFS_SPLIT)
-		ifs = ifsset() ? ifsval() : " \t\n";
-
-	if (*p == '~' && (flag & (EXP_TILDE | EXP_VARTILDE)))
-		p = exptilde(p, flag);
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-		case CTLENDVAR: /* end of expanding yyy in ${xxx-yyy} */
-			return;
-		case CTLQUOTEMARK:
-			/* "$@" syntax adherence hack */
-			if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
-				break;
-			if ((flag & EXP_FULL) != 0)
-				STPUTC(c, expdest);
-			ifs_split = 0;
-			break;
-		case CTLQUOTEEND:
-			ifs_split = EXP_IFS_SPLIT;
-			break;
-		case CTLESC:
-			if (quotes)
-				STPUTC(c, expdest);
-			c = *p++;
-			STPUTC(c, expdest);
-			break;
-		case CTLVAR:
-			p = evalvar(p, (flag & ~EXP_IFS_SPLIT) | (flag & ifs_split));
-			break;
-		case CTLBACKQ:
-		case CTLBACKQ|CTLQUOTE:
-			expbackq(argbackq->n, c & CTLQUOTE, flag);
-			argbackq = argbackq->next;
-			break;
-		case CTLENDARI:
-			expari(flag);
-			break;
-		case ':':
-		case '=':
-			/*
-			 * sort of a hack - expand tildes in variable
-			 * assignments (after the first '=' and after ':'s).
-			 */
-			STPUTC(c, expdest);
-			if (flag & EXP_VARTILDE && *p == '~') {
-				if (c == '=') {
-					if (firsteq)
-						firsteq = 0;
-					else
-						break;
-				}
-				p = exptilde(p, flag);
-			}
-			break;
-		default:
-			STPUTC(c, expdest);
-			if (flag & EXP_IFS_SPLIT & ifs_split && strchr(ifs, c) != NULL) {
-				/* We need to get the output split here... */
-				recordregion(expdest - stackblock() - 1,
-						expdest - stackblock(), 0);
-			}
-			break;
-		}
-	}
-}
-
-STATIC char *
-exptilde(char *p, int flag)
-{
-	char c, *startp = p;
-	struct passwd *pw;
-	const char *home;
-	int quotes = flag & (EXP_FULL | EXP_CASE);
-
-	while ((c = *p) != '\0') {
-		switch(c) {
-		case CTLESC:
-			return (startp);
-		case CTLQUOTEMARK:
-			return (startp);
-		case ':':
-			if (flag & EXP_VARTILDE)
-				goto done;
-			break;
-		case '/':
-			goto done;
-		}
-		p++;
-	}
-done:
-	*p = '\0';
-	if (*(startp+1) == '\0') {
-		if ((home = lookupvar("HOME")) == NULL)
-			goto lose;
-	} else {
-		if ((pw = getpwnam(startp+1)) == NULL)
-			goto lose;
-		home = pw->pw_dir;
-	}
-	if (*home == '\0')
-		goto lose;
-	*p = c;
-	while ((c = *home++) != '\0') {
-		if (quotes && SQSYNTAX[(int)c] == CCTL)
-			STPUTC(CTLESC, expdest);
-		STPUTC(c, expdest);
-	}
-	return (p);
-lose:
-	*p = c;
-	return (startp);
-}
-
-
-STATIC void
-removerecordregions(int endoff)
-{
-	if (ifslastp == NULL)
-		return;
-
-	if (ifsfirst.endoff > endoff) {
-		while (ifsfirst.next != NULL) {
-			struct ifsregion *ifsp;
-			INTOFF;
-			ifsp = ifsfirst.next->next;
-			ckfree(ifsfirst.next);
-			ifsfirst.next = ifsp;
-			INTON;
-		}
-		if (ifsfirst.begoff > endoff)
-			ifslastp = NULL;
-		else {
-			ifslastp = &ifsfirst;
-			ifsfirst.endoff = endoff;
-		}
-		return;
-	}
-
-	ifslastp = &ifsfirst;
-	while (ifslastp->next && ifslastp->next->begoff < endoff)
-		ifslastp=ifslastp->next;
-	while (ifslastp->next != NULL) {
-		struct ifsregion *ifsp;
-		INTOFF;
-		ifsp = ifslastp->next->next;
-		ckfree(ifslastp->next);
-		ifslastp->next = ifsp;
-		INTON;
-	}
-	if (ifslastp->endoff > endoff)
-		ifslastp->endoff = endoff;
-}
-
-
-/*
- * Expand arithmetic expression.  Backup to start of expression,
- * evaluate, place result in (backed up) result, adjust string position.
- */
-void
-expari(int flag)
-{
-	char *p, *start;
-	int result;
-	int begoff;
-	int quotes = flag & (EXP_FULL | EXP_CASE);
-	int quoted;
-
-	/*	ifsfree(); */
-
-	/*
-	 * This routine is slightly over-complicated for
-	 * efficiency.  First we make sure there is
-	 * enough space for the result, which may be bigger
-	 * than the expression if we add exponentation.  Next we
-	 * scan backwards looking for the start of arithmetic.  If the
-	 * next previous character is a CTLESC character, then we
-	 * have to rescan starting from the beginning since CTLESC
-	 * characters have to be processed left to right.
-	 */
-#if INT_MAX / 1000000000 >= 10 || INT_MIN / 1000000000 <= -10
-#error "integers with more than 10 digits are not supported"
-#endif
-	CHECKSTRSPACE(12 - 2, expdest);
-	USTPUTC('\0', expdest);
-	start = stackblock();
-	p = expdest - 1;
-	while (*p != CTLARI && p >= start)
-		--p;
-	if (*p != CTLARI)
-		error("missing CTLARI (shouldn't happen)");
-	if (p > start && *(p-1) == CTLESC)
-		for (p = start; *p != CTLARI; p++)
-			if (*p == CTLESC)
-				p++;
-
-	if (p[1] == '"')
-		quoted=1;
-	else
-		quoted=0;
-	begoff = p - start;
-	removerecordregions(begoff);
-	if (quotes)
-		rmescapes(p+2);
-	result = arith(p+2);
-	fmtstr(p, 12, "%d", result);
-
-	while (*p++)
-		;
-
-	if (quoted == 0)
-		recordregion(begoff, p - 1 - start, 0);
-	result = expdest - p + 1;
-	STADJUST(-result, expdest);
-}
-
-
-/*
- * Expand stuff in backwards quotes.
- */
-
-STATIC void
-expbackq(union node *cmd, int quoted, int flag)
-{
-	struct backcmd in;
-	int i;
-	char buf[128];
-	char *p;
-	char *dest = expdest;
-	struct ifsregion saveifs, *savelastp;
-	struct nodelist *saveargbackq;
-	char lastc;
-	int startloc = dest - stackblock();
-	char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
-	int saveherefd;
-	int quotes = flag & (EXP_FULL | EXP_CASE);
-
-	INTOFF;
-	saveifs = ifsfirst;
-	savelastp = ifslastp;
-	saveargbackq = argbackq;
-	saveherefd = herefd;
-	herefd = -1;
-	p = grabstackstr(dest);
-	evalbackcmd(cmd, &in);
-	ungrabstackstr(p, dest);
-	ifsfirst = saveifs;
-	ifslastp = savelastp;
-	argbackq = saveargbackq;
-	herefd = saveherefd;
-
-	p = in.buf;
-	lastc = '\0';
-	for (;;) {
-		if (--in.nleft < 0) {
-			if (in.fd < 0)
-				break;
-			while ((i = read(in.fd, buf, sizeof buf)) < 0 && errno == EINTR);
-			TRACE(("expbackq: read returns %d\n", i));
-			if (i <= 0)
-				break;
-			p = buf;
-			in.nleft = i - 1;
-		}
-		lastc = *p++;
-		if (lastc != '\0') {
-			if (quotes && syntax[(int)lastc] == CCTL)
-				STPUTC(CTLESC, dest);
-			STPUTC(lastc, dest);
-		}
-	}
-
-	/* Eat all trailing newlines */
-	p = stackblock() + startloc;
-	while (dest > p && dest[-1] == '\n')
-		STUNPUTC(dest);
-
-	if (in.fd >= 0)
-		close(in.fd);
-	if (in.buf)
-		ckfree(in.buf);
-	if (in.jp)
-		back_exitstatus = waitforjob(in.jp);
-	if (quoted == 0)
-		recordregion(startloc, dest - stackblock(), 0);
-	TRACE(("evalbackq: size=%d: \"%.*s\"\n",
-		(dest - stackblock()) - startloc,
-		(dest - stackblock()) - startloc,
-		stackblock() + startloc));
-	expdest = dest;
-	INTON;
-}
-
-
-
-STATIC int
-subevalvar(char *p, char *str, int strloc, int subtype, int startloc, int varflags)
-{
-	char *startp;
-	char *loc = NULL;
-	char *q;
-	int c = 0;
-	int saveherefd = herefd;
-	struct nodelist *saveargbackq = argbackq;
-	int amount;
-
-	herefd = -1;
-	argstr(p, 0);
-	STACKSTRNUL(expdest);
-	herefd = saveherefd;
-	argbackq = saveargbackq;
-	startp = stackblock() + startloc;
-	if (str == NULL)
-	    str = stackblock() + strloc;
-
-	switch (subtype) {
-	case VSASSIGN:
-		setvar(str, startp, 0);
-		amount = startp - expdest;
-		STADJUST(amount, expdest);
-		varflags &= ~VSNUL;
-		if (c != 0)
-			*loc = c;
-		return 1;
-
-	case VSQUESTION:
-		if (*p != CTLENDVAR) {
-			outfmt(&errout, "%s\n", startp);
-			error((char *)NULL);
-		}
-		error("%.*s: parameter %snot set", p - str - 1,
-		      str, (varflags & VSNUL) ? "null or "
-					      : nullstr);
-		/* NOTREACHED */
-
-	case VSTRIMLEFT:
-		for (loc = startp; loc < str; loc++) {
-			c = *loc;
-			*loc = '\0';
-			if (patmatch(str, startp, varflags & VSQUOTE))
-				goto recordleft;
-			*loc = c;
-			if ((varflags & VSQUOTE) && *loc == CTLESC)
-			        loc++;
-		}
-		return 0;
-
-	case VSTRIMLEFTMAX:
-		for (loc = str - 1; loc >= startp;) {
-			c = *loc;
-			*loc = '\0';
-			if (patmatch(str, startp, varflags & VSQUOTE))
-				goto recordleft;
-			*loc = c;
-			loc--;
-			if ((varflags & VSQUOTE) && loc > startp &&
-			    *(loc - 1) == CTLESC) {
-				for (q = startp; q < loc; q++)
-					if (*q == CTLESC)
-						q++;
-				if (q > loc)
-					loc--;
-			}
-		}
-		return 0;
-
-	case VSTRIMRIGHT:
-	        for (loc = str - 1; loc >= startp;) {
-			if (patmatch(str, loc, varflags & VSQUOTE))
-				goto recordright;
-			loc--;
-			if ((varflags & VSQUOTE) && loc > startp &&
-			    *(loc - 1) == CTLESC) {
-				for (q = startp; q < loc; q++)
-					if (*q == CTLESC)
-						q++;
-				if (q > loc)
-					loc--;
-			}
-		}
-		return 0;
-
-	case VSTRIMRIGHTMAX:
-		for (loc = startp; loc < str - 1; loc++) {
-			if (patmatch(str, loc, varflags & VSQUOTE))
-				goto recordright;
-			if ((varflags & VSQUOTE) && *loc == CTLESC)
-			        loc++;
-		}
-		return 0;
-
-	default:
-		abort();
-	}
-
-recordleft:
-	*loc = c;
-	amount = ((str - 1) - (loc - startp)) - expdest;
-	STADJUST(amount, expdest);
-	while (loc != str - 1)
-		*startp++ = *loc++;
-	return 1;
-
-recordright:
-	amount = loc - expdest;
-	STADJUST(amount, expdest);
-	STPUTC('\0', expdest);
-	STADJUST(-1, expdest);
-	return 1;
-}
-
-
-/*
- * Expand a variable, and return a pointer to the next character in the
- * input string.
- */
-
-STATIC char *
-evalvar(char *p, int flag)
-{
-	int subtype;
-	int varflags;
-	char *var;
-	char *val;
-	int patloc;
-	int c;
-	int set;
-	int special;
-	int startloc;
-	int varlen;
-	int apply_ifs;
-	int quotes = flag & (EXP_FULL | EXP_CASE);
-
-	varflags = (unsigned char)*p++;
-	subtype = varflags & VSTYPE;
-	var = p;
-	special = !is_name(*p);
-	p = strchr(p, '=') + 1;
-
-again: /* jump here after setting a variable with ${var=text} */
-	if (special) {
-		set = varisset(var, varflags & VSNUL);
-		val = NULL;
-	} else {
-		val = lookupvar(var);
-		if (val == NULL || ((varflags & VSNUL) && val[0] == '\0')) {
-			val = NULL;
-			set = 0;
-		} else
-			set = 1;
-	}
-
-	varlen = 0;
-	startloc = expdest - stackblock();
-
-	if (!set && uflag) {
-		switch (subtype) {
-		case VSNORMAL:
-		case VSTRIMLEFT:
-		case VSTRIMLEFTMAX:
-		case VSTRIMRIGHT:
-		case VSTRIMRIGHTMAX:
-		case VSLENGTH:
-			error("%.*s: parameter not set", p - var - 1, var);
-			/* NOTREACHED */
-		}
-	}
-
-	if (set && subtype != VSPLUS) {
-		/* insert the value of the variable */
-		if (special) {
-			varvalue(var, varflags & VSQUOTE, subtype, flag);
-			if (subtype == VSLENGTH) {
-				varlen = expdest - stackblock() - startloc;
-				STADJUST(-varlen, expdest);
-			}
-		} else {
-			char const *syntax = (varflags & VSQUOTE) ? DQSYNTAX
-								  : BASESYNTAX;
-
-			if (subtype == VSLENGTH) {
-				for (;*val; val++)
-					varlen++;
-			} else {
-				while (*val) {
-					if (quotes && syntax[(int)*val] == CCTL)
-						STPUTC(CTLESC, expdest);
-					STPUTC(*val++, expdest);
-				}
-
-			}
-		}
-	}
-
-
-	apply_ifs = ((varflags & VSQUOTE) == 0 ||
-		(*var == '@' && shellparam.nparam != 1));
-
-	switch (subtype) {
-	case VSLENGTH:
-		expdest = cvtnum(varlen, expdest);
-		break;
-
-	case VSNORMAL:
-		break;
-
-	case VSPLUS:
-		set = !set;
-		/* FALLTHROUGH */
-	case VSMINUS:
-		if (!set) {
-		        argstr(p, flag | (apply_ifs ? EXP_IFS_SPLIT : 0));
-			/*
-			 * ${x-a b c} doesn't get split, but removing the
-			 * 'apply_ifs = 0' apparantly breaks ${1+"$@"}..
-			 * ${x-'a b' c} should generate 2 args.
-			 */
-			/* We should have marked stuff already */
-			apply_ifs = 0;
-		}
-		break;
-
-	case VSTRIMLEFT:
-	case VSTRIMLEFTMAX:
-	case VSTRIMRIGHT:
-	case VSTRIMRIGHTMAX:
-		if (!set)
-			break;
-		/*
-		 * Terminate the string and start recording the pattern
-		 * right after it
-		 */
-		STPUTC('\0', expdest);
-		patloc = expdest - stackblock();
-		if (subevalvar(p, NULL, patloc, subtype,
-			       startloc, varflags) == 0) {
-			int amount = (expdest - stackblock() - patloc) + 1;
-			STADJUST(-amount, expdest);
-		}
-		/* Remove any recorded regions beyond start of variable */
-		removerecordregions(startloc);
-		apply_ifs = 1;
-		break;
-
-	case VSASSIGN:
-	case VSQUESTION:
-		if (set)
-			break;
-		if (subevalvar(p, var, 0, subtype, startloc, varflags)) {
-			varflags &= ~VSNUL;
-			/*
-			 * Remove any recorded regions beyond
-			 * start of variable
-			 */
-			removerecordregions(startloc);
-			goto again;
-		}
-		apply_ifs = 0;
-		break;
-
-	default:
-		abort();
-	}
-
-	if (apply_ifs)
-		recordregion(startloc, expdest - stackblock(),
-			     varflags & VSQUOTE);
-
-	if (subtype != VSNORMAL) {	/* skip to end of alternative */
-		int nesting = 1;
-		for (;;) {
-			if ((c = *p++) == CTLESC)
-				p++;
-			else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) {
-				if (set)
-					argbackq = argbackq->next;
-			} else if (c == CTLVAR) {
-				if ((*p++ & VSTYPE) != VSNORMAL)
-					nesting++;
-			} else if (c == CTLENDVAR) {
-				if (--nesting == 0)
-					break;
-			}
-		}
-	}
-	return p;
-}
-
-
-
-/*
- * Test whether a specialized variable is set.
- */
-
-STATIC int
-varisset(char *name, int nulok)
-{
-	if (*name == '!')
-		return backgndpid != -1;
-	else if (*name == '@' || *name == '*') {
-		if (*shellparam.p == NULL)
-			return 0;
-
-		if (nulok) {
-			char **av;
-
-			for (av = shellparam.p; *av; av++)
-				if (**av != '\0')
-					return 1;
-			return 0;
-		}
-	} else if (is_digit(*name)) {
-		char *ap;
-		int num = atoi(name);
-
-		if (num > shellparam.nparam)
-			return 0;
-
-		if (num == 0)
-			ap = arg0;
-		else
-			ap = shellparam.p[num - 1];
-
-		if (nulok && (ap == NULL || *ap == '\0'))
-			return 0;
-	}
-	return 1;
-}
-
-
-
-/*
- * Add the value of a specialized variable to the stack string.
- */
-
-STATIC void
-varvalue(char *name, int quoted, int subtype, int flag)
-{
-	int num;
-	char *p;
-	int i;
-	char sep;
-	char **ap;
-	char const *syntax;
-
-#define STRTODEST(p) \
-	do {\
-	if (flag & (EXP_FULL | EXP_CASE) && subtype != VSLENGTH) { \
-		syntax = quoted? DQSYNTAX : BASESYNTAX; \
-		while (*p) { \
-			if (syntax[(int)*p] == CCTL) \
-				STPUTC(CTLESC, expdest); \
-			STPUTC(*p++, expdest); \
-		} \
-	} else \
-		while (*p) \
-			STPUTC(*p++, expdest); \
-	} while (0)
-
-
-	switch (*name) {
-	case '$':
-		num = rootpid;
-		goto numvar;
-	case '?':
-		num = exitstatus;
-		goto numvar;
-	case '#':
-		num = shellparam.nparam;
-		goto numvar;
-	case '!':
-		num = backgndpid;
-numvar:
-		expdest = cvtnum(num, expdest);
-		break;
-	case '-':
-		for (i = 0; optlist[i].name; i++) {
-			if (optlist[i].val)
-				STPUTC(optlist[i].letter, expdest);
-		}
-		break;
-	case '@':
-		if (flag & EXP_FULL && quoted) {
-			for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
-				STRTODEST(p);
-				if (*ap)
-					STPUTC('\0', expdest);
-			}
-			break;
-		}
-		/* fall through */
-	case '*':
-		if (ifsset() != 0)
-			sep = ifsval()[0];
-		else
-			sep = ' ';
-		for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
-			STRTODEST(p);
-			if (*ap && sep)
-				STPUTC(sep, expdest);
-		}
-		break;
-	case '0':
-		p = arg0;
-		STRTODEST(p);
-		break;
-	default:
-		if (is_digit(*name)) {
-			num = atoi(name);
-			if (num > 0 && num <= shellparam.nparam) {
-				p = shellparam.p[num - 1];
-				STRTODEST(p);
-			}
-		}
-		break;
-	}
-}
-
-
-
-/*
- * Record the fact that we have to scan this region of the
- * string for IFS characters.
- */
-
-STATIC void
-recordregion(int start, int end, int inquotes)
-{
-	struct ifsregion *ifsp;
-
-	if (ifslastp == NULL) {
-		ifsp = &ifsfirst;
-	} else {
-		if (ifslastp->endoff == start
-		    && ifslastp->inquotes == inquotes) {
-			/* extend previous area */
-			ifslastp->endoff = end;
-			return;
-		}
-		ifsp = (struct ifsregion *)ckmalloc(sizeof (struct ifsregion));
-		ifslastp->next = ifsp;
-	}
-	ifslastp = ifsp;
-	ifslastp->next = NULL;
-	ifslastp->begoff = start;
-	ifslastp->endoff = end;
-	ifslastp->inquotes = inquotes;
-}
-
-
-
-/*
- * Break the argument string into pieces based upon IFS and add the
- * strings to the argument list.  The regions of the string to be
- * searched for IFS characters have been stored by recordregion.
- */
-STATIC void
-ifsbreakup(char *string, struct arglist *arglist)
-{
-	struct ifsregion *ifsp;
-	struct strlist *sp;
-	char *start;
-	char *p;
-	char *q;
-	const char *ifs;
-	const char *ifsspc;
-	int inquotes;
-
-	start = string;
-	ifsspc = NULL;
-	inquotes = 0;
-
-	if (ifslastp == NULL) {
-		/* Return entire argument, IFS doesn't apply to any of it */
-		sp = (struct strlist *)stalloc(sizeof *sp);
-		sp->text = start;
-		*arglist->lastp = sp;
-		arglist->lastp = &sp->next;
-		return;
-	}
-
-	ifs = ifsset() ? ifsval() : " \t\n";
-
-	for (ifsp = &ifsfirst; ifsp != NULL; ifsp = ifsp->next) {
-		p = string + ifsp->begoff;
-		inquotes = ifsp->inquotes;
-		ifsspc = NULL;
-		while (p < string + ifsp->endoff) {
-			q = p;
-			if (*p == CTLESC)
-				p++;
-			if (inquotes) {
-				/* Only NULs (probably from "$@") end args */
-				if (*p != 0) {
-					p++;
-					continue;
-				}
-			} else {
-				if (!strchr(ifs, *p)) {
-					p++;
-					continue;
-				}
-				ifsspc = strchr(" \t\n", *p);
-
-				/* Ignore IFS whitespace at start */
-				if (q == start && ifsspc != NULL) {
-					p++;
-					start = p;
-					continue;
-				}
-			}
-
-			/* Save this argument... */
-			*q = '\0';
-			sp = (struct strlist *)stalloc(sizeof *sp);
-			sp->text = start;
-			*arglist->lastp = sp;
-			arglist->lastp = &sp->next;
-			p++;
-
-			if (ifsspc != NULL) {
-				/* Ignore further trailing IFS whitespace */
-				for (; p < string + ifsp->endoff; p++) {
-					q = p;
-					if (*p == CTLESC)
-						p++;
-					if (strchr(ifs, *p) == NULL) {
-						p = q;
-						break;
-					}
-					if (strchr(" \t\n", *p) == NULL) {
-						p++;
-						break;
-					}
-				}
-			}
-			start = p;
-		}
-	}
-
-	/*
-	 * Save anything left as an argument.
-	 * Traditionally we have treated 'IFS=':'; set -- x$IFS' as
-	 * generating 2 arguments, the second of which is empty.
-	 * Some recent clarification of the Posix spec say that it
-	 * should only generate one....
-	 */
-	if (*start /* || (!ifsspc && start > string) */) {
-		sp = (struct strlist *)stalloc(sizeof *sp);
-		sp->text = start;
-		*arglist->lastp = sp;
-		arglist->lastp = &sp->next;
-	}
-}
-
-STATIC void
-ifsfree(void)
-{
-	while (ifsfirst.next != NULL) {
-		struct ifsregion *ifsp;
-		INTOFF;
-		ifsp = ifsfirst.next->next;
-		ckfree(ifsfirst.next);
-		ifsfirst.next = ifsp;
-		INTON;
-	}
-	ifslastp = NULL;
-	ifsfirst.next = NULL;
-}
-
-
-
-/*
- * Expand shell metacharacters.  At this point, the only control characters
- * should be escapes.  The results are stored in the list exparg.
- */
-
-char *expdir;
-
-
-STATIC void
-expandmeta(struct strlist *str, int flag)
-{
-	char *p;
-	struct strlist **savelastp;
-	struct strlist *sp;
-	char c;
-	/* TODO - EXP_REDIR */
-
-	while (str) {
-		if (fflag)
-			goto nometa;
-		p = str->text;
-		for (;;) {			/* fast check for meta chars */
-			if ((c = *p++) == '\0')
-				goto nometa;
-			if (c == '*' || c == '?' || c == '[' || c == '!')
-				break;
-		}
-		savelastp = exparg.lastp;
-		INTOFF;
-		if (expdir == NULL) {
-			int i = strlen(str->text);
-			expdir = ckmalloc(i < 2048 ? 2048 : i); /* XXX */
-		}
-
-		expmeta(expdir, str->text);
-		ckfree(expdir);
-		expdir = NULL;
-		INTON;
-		if (exparg.lastp == savelastp) {
-			/*
-			 * no matches
-			 */
-nometa:
-			*exparg.lastp = str;
-			rmescapes(str->text);
-			exparg.lastp = &str->next;
-		} else {
-			*exparg.lastp = NULL;
-			*savelastp = sp = expsort(*savelastp);
-			while (sp->next != NULL)
-				sp = sp->next;
-			exparg.lastp = &sp->next;
-		}
-		str = str->next;
-	}
-}
-
-
-/*
- * Do metacharacter (i.e. *, ?, [...]) expansion.
- */
-
-STATIC void
-expmeta(char *enddir, char *name)
-{
-	char *p;
-	const char *cp;
-	char *q;
-	char *start;
-	char *endname;
-	int metaflag;
-	struct stat statb;
-	DIR *dirp;
-	struct dirent *dp;
-	int atend;
-	int matchdot;
-
-	metaflag = 0;
-	start = name;
-	for (p = name ; ; p++) {
-		if (*p == '*' || *p == '?')
-			metaflag = 1;
-		else if (*p == '[') {
-			q = p + 1;
-			if (*q == '!')
-				q++;
-			for (;;) {
-				while (*q == CTLQUOTEMARK)
-					q++;
-				if (*q == CTLESC)
-					q++;
-				if (*q == '/' || *q == '\0')
-					break;
-				if (*++q == ']') {
-					metaflag = 1;
-					break;
-				}
-			}
-		} else if (*p == '!' && p[1] == '!'	&& (p == name || p[-1] == '/')) {
-			metaflag = 1;
-		} else if (*p == '\0')
-			break;
-		else if (*p == CTLQUOTEMARK)
-			continue;
-		else if (*p == CTLESC)
-			p++;
-		if (*p == '/') {
-			if (metaflag)
-				break;
-			start = p + 1;
-		}
-	}
-	if (metaflag == 0) {	/* we've reached the end of the file name */
-		if (enddir != expdir)
-			metaflag++;
-		for (p = name ; ; p++) {
-			if (*p == CTLQUOTEMARK)
-				continue;
-			if (*p == CTLESC)
-				p++;
-			*enddir++ = *p;
-			if (*p == '\0')
-				break;
-		}
-		if (metaflag == 0 || lstat(expdir, &statb) >= 0)
-			addfname(expdir);
-		return;
-	}
-	endname = p;
-	if (start != name) {
-		p = name;
-		while (p < start) {
-			while (*p == CTLQUOTEMARK)
-				p++;
-			if (*p == CTLESC)
-				p++;
-			*enddir++ = *p++;
-		}
-	}
-	if (enddir == expdir) {
-		cp = ".";
-	} else if (enddir == expdir + 1 && *expdir == '/') {
-		cp = "/";
-	} else {
-		cp = expdir;
-		enddir[-1] = '\0';
-	}
-	if ((dirp = opendir(cp)) == NULL)
-		return;
-	if (enddir != expdir)
-		enddir[-1] = '/';
-	if (*endname == 0) {
-		atend = 1;
-	} else {
-		atend = 0;
-		*endname++ = '\0';
-	}
-	matchdot = 0;
-	p = start;
-	while (*p == CTLQUOTEMARK)
-		p++;
-	if (*p == CTLESC)
-		p++;
-	if (*p == '.')
-		matchdot++;
-	while (! int_pending() && (dp = readdir(dirp)) != NULL) {
-		if (dp->d_name[0] == '.' && ! matchdot)
-			continue;
-		if (patmatch(start, dp->d_name, 0)) {
-			if (atend) {
-				scopy(dp->d_name, enddir);
-				addfname(expdir);
-			} else {
-				for (p = enddir, cp = dp->d_name;
-				     (*p++ = *cp++) != '\0';)
-					continue;
-				p[-1] = '/';
-				expmeta(p, endname);
-			}
-		}
-	}
-	closedir(dirp);
-	if (! atend)
-		endname[-1] = '/';
-}
-
-
-/*
- * Add a file name to the list.
- */
-
-STATIC void
-addfname(char *name)
-{
-	char *p;
-	struct strlist *sp;
-
-	p = stalloc(strlen(name) + 1);
-	scopy(name, p);
-	sp = (struct strlist *)stalloc(sizeof *sp);
-	sp->text = p;
-	*exparg.lastp = sp;
-	exparg.lastp = &sp->next;
-}
-
-
-/*
- * Sort the results of file name expansion.  It calculates the number of
- * strings to sort and then calls msort (short for merge sort) to do the
- * work.
- */
-
-STATIC struct strlist *
-expsort(struct strlist *str)
-{
-	int len;
-	struct strlist *sp;
-
-	len = 0;
-	for (sp = str ; sp ; sp = sp->next)
-		len++;
-	return msort(str, len);
-}
-
-
-STATIC struct strlist *
-msort(struct strlist *list, int len)
-{
-	struct strlist *p, *q = NULL;
-	struct strlist **lpp;
-	int half;
-	int n;
-
-	if (len <= 1)
-		return list;
-	half = len >> 1;
-	p = list;
-	for (n = half ; --n >= 0 ; ) {
-		q = p;
-		p = p->next;
-	}
-	q->next = NULL;			/* terminate first half of list */
-	q = msort(list, half);		/* sort first half of list */
-	p = msort(p, len - half);		/* sort second half */
-	lpp = &list;
-	for (;;) {
-		if (strcmp(p->text, q->text) < 0) {
-			*lpp = p;
-			lpp = &p->next;
-			if ((p = *lpp) == NULL) {
-				*lpp = q;
-				break;
-			}
-		} else {
-			*lpp = q;
-			lpp = &q->next;
-			if ((q = *lpp) == NULL) {
-				*lpp = p;
-				break;
-			}
-		}
-	}
-	return list;
-}
-
-
-
-/*
- * Returns true if the pattern matches the string.
- */
-
-int
-patmatch(char *pattern, char *string, int squoted)
-{
-#ifdef notdef
-	if (pattern[0] == '!' && pattern[1] == '!')
-		return 1 - pmatch(pattern + 2, string);
-	else
-#endif
-		return pmatch(pattern, string, squoted);
-}
-
-
-STATIC int
-pmatch(char *pattern, char *string, int squoted)
-{
-	char *p, *q;
-	char c;
-
-	p = pattern;
-	q = string;
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-			goto breakloop;
-		case CTLESC:
-			if (squoted && *q == CTLESC)
-				q++;
-			if (*q++ != *p++)
-				return 0;
-			break;
-		case CTLQUOTEMARK:
-			continue;
-		case '?':
-			if (squoted && *q == CTLESC)
-				q++;
-			if (*q++ == '\0')
-				return 0;
-			break;
-		case '*':
-			c = *p;
-			while (c == CTLQUOTEMARK || c == '*')
-				c = *++p;
-			if (c != CTLESC &&  c != CTLQUOTEMARK &&
-			    c != '?' && c != '*' && c != '[') {
-				while (*q != c) {
-					if (squoted && *q == CTLESC &&
-					    q[1] == c)
-						break;
-					if (*q == '\0')
-						return 0;
-					if (squoted && *q == CTLESC)
-						q++;
-					q++;
-				}
-			}
-			do {
-				if (pmatch(p, q, squoted))
-					return 1;
-				if (squoted && *q == CTLESC)
-					q++;
-			} while (*q++ != '\0');
-			return 0;
-		case '[': {
-			char *endp;
-			int invert, found;
-			char chr;
-
-			endp = p;
-			if (*endp == '!')
-				endp++;
-			for (;;) {
-				while (*endp == CTLQUOTEMARK)
-					endp++;
-				if (*endp == '\0')
-					goto dft;		/* no matching ] */
-				if (*endp == CTLESC)
-					endp++;
-				if (*++endp == ']')
-					break;
-			}
-			invert = 0;
-			if (*p == '!') {
-				invert++;
-				p++;
-			}
-			found = 0;
-			chr = *q++;
-			if (squoted && chr == CTLESC)
-				chr = *q++;
-			if (chr == '\0')
-				return 0;
-			c = *p++;
-			do {
-				if (c == CTLQUOTEMARK)
-					continue;
-				if (c == CTLESC)
-					c = *p++;
-				if (*p == '-' && p[1] != ']') {
-					p++;
-					while (*p == CTLQUOTEMARK)
-						p++;
-					if (*p == CTLESC)
-						p++;
-					if (chr >= c && chr <= *p)
-						found = 1;
-					p++;
-				} else {
-					if (chr == c)
-						found = 1;
-				}
-			} while ((c = *p++) != ']');
-			if (found == invert)
-				return 0;
-			break;
-		}
-dft:	        default:
-			if (squoted && *q == CTLESC)
-				q++;
-			if (*q++ != c)
-				return 0;
-			break;
-		}
-	}
-breakloop:
-	if (*q != '\0')
-		return 0;
-	return 1;
-}
-
-
-
-/*
- * Remove any CTLESC characters from a string.
- */
-
-void
-rmescapes(char *str)
-{
-	char *p, *q;
-
-	p = str;
-	while (*p != CTLESC && *p != CTLQUOTEMARK) {
-		if (*p++ == '\0')
-			return;
-	}
-	q = p;
-	while (*p) {
-		if (*p == CTLQUOTEMARK) {
-			p++;
-			continue;
-		}
-		if (*p == CTLESC)
-			p++;
-		*q++ = *p++;
-	}
-	*q = '\0';
-}
-
-
-
-/*
- * See if a pattern matches in a case statement.
- */
-
-int
-casematch(union node *pattern, char *val)
-{
-	struct stackmark smark;
-	int result;
-	char *p;
-
-	setstackmark(&smark);
-	argbackq = pattern->narg.backquote;
-	STARTSTACKSTR(expdest);
-	ifslastp = NULL;
-	argstr(pattern->narg.text, EXP_TILDE | EXP_CASE);
-	STPUTC('\0', expdest);
-	p = grabstackstr(expdest);
-	result = patmatch(p, val, 0);
-	popstackmark(&smark);
-	return result;
-}
-
-/*
- * Our own itoa().
- */
-
-STATIC char *
-cvtnum(int num, char *buf)
-{
-	char temp[32];
-	int neg = num < 0;
-	char *p = temp + 31;
-
-	temp[31] = '\0';
-
-	do {
-		*--p = num % 10 + '0';
-	} while ((num /= 10) != 0);
-
-	if (neg)
-		*--p = '-';
-
-	while (*p)
-		STPUTC(*p++, buf);
-	return buf;
-}
-
-/*
- * Do most of the work for wordexp(3).
- */
-
-int
-wordexpcmd(int argc, char **argv)
-{
-	size_t len;
-	int i;
-
-	out1fmt("%d", argc - 1);
-	out1c('\0');
-	for (i = 1, len = 0; i < argc; i++)
-		len += strlen(argv[i]);
-	out1fmt("%zd", len);
-	out1c('\0');
-	for (i = 1; i < argc; i++) {
-		out1str(argv[i]);
-		out1c('\0');
-	}
-	return (0);
-}
diff --git a/src/ash/expand.h b/src/ash/expand.h
deleted file mode 100644
index 1ea876d..0000000
--- a/src/ash/expand.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*	$NetBSD: expand.h,v 1.16 2004/07/13 15:05:59 seb Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)expand.h	8.2 (Berkeley) 5/4/95
- */
-
-struct strlist {
-	struct strlist *next;
-	char *text;
-};
-
-
-struct arglist {
-	struct strlist *list;
-	struct strlist **lastp;
-};
-
-/*
- * expandarg() flags
- */
-#define EXP_FULL	0x1	/* perform word splitting & file globbing */
-#define EXP_TILDE	0x2	/* do normal tilde expansion */
-#define	EXP_VARTILDE	0x4	/* expand tildes in an assignment */
-#define	EXP_REDIR	0x8	/* file glob for a redirection (1 match only) */
-#define EXP_CASE	0x10	/* keeps quotes around for CASE pattern */
-#define EXP_IFS_SPLIT	0x20	/* need to record arguments for ifs breakup */
-
-
-union node;
-void expandhere(union node *, int);
-void expandarg(union node *, struct arglist *, int);
-void expari(int);
-int patmatch(char *, char *, int);
-void rmescapes(char *);
-int casematch(union node *, char *);
-int wordexpcmd(int, char **);
-
-/* From arith.y */
-int arith(const char *);
-int expcmd(int , char **);
-void arith_lex_reset(void);
-int yylex(void);
diff --git a/src/ash/funcs/cmv b/src/ash/funcs/cmv
deleted file mode 100644
index 667f846..0000000
--- a/src/ash/funcs/cmv
+++ /dev/null
@@ -1,50 +0,0 @@
-#	$NetBSD: cmv,v 1.7 1995/05/11 21:31:05 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)cmv	8.2 (Berkeley) 5/4/95
-
-# Conditional move--don't replace an existing file.
-
-cmv() {
-	if test $# != 2
-	then	echo "cmv: arg count"
-		return 2
-	fi
-	if test -f "$2" -o -w "$2"
-	then	echo "$2 exists"
-		return 2
-	fi
-	/bin/mv "$1" "$2"
-}
diff --git a/src/ash/funcs/dirs b/src/ash/funcs/dirs
deleted file mode 100644
index 68bb317..0000000
--- a/src/ash/funcs/dirs
+++ /dev/null
@@ -1,74 +0,0 @@
-#	$NetBSD: dirs,v 1.7 1995/05/11 21:31:08 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)dirs	8.2 (Berkeley) 5/4/95
-
-# pushd, popd, and dirs --- written by Chris Bertin
-# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
-# as modified by Patrick Elam of GTRI and Kenneth Almquist at UW
-
-pushd () {
-	SAVE=`pwd`
-	if [ "$1" = "" ] 
-	then	if [ "$DSTACK" = "" ]
-		then	echo "pushd: directory stack empty."
-			return 1
-		fi
-		set $DSTACK
-		cd $1 || return
-		shift 1
-		DSTACK="$*"
-	else	cd $1 > /dev/null || return
-	fi
-	DSTACK="$SAVE $DSTACK"
-	dirs
-}
-
-popd () {
-	if [ "$DSTACK" = "" ] 
-	then	echo "popd: directory stack empty."
-		return 1
-	fi
-	set $DSTACK
-	cd $1
-	shift
-	DSTACK=$*
-	dirs
-}
-
-dirs () {
-	echo "`pwd` $DSTACK"
-	return 0
-}
diff --git a/src/ash/funcs/kill b/src/ash/funcs/kill
deleted file mode 100644
index 75b0180..0000000
--- a/src/ash/funcs/kill
+++ /dev/null
@@ -1,50 +0,0 @@
-#	$NetBSD: kill,v 1.7 1995/05/11 21:31:10 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)kill	8.2 (Berkeley) 5/4/95
-
-# Convert job names to process ids and then run /bin/kill.
-
-kill() {
-	local args x
-	args=
-	for x in "$@"
-	do	case $x in
-		%*)	x=`jobid "$x"` ;;
-		esac
-		args="$args $x"
-	done
-	/bin/kill $args
-}
diff --git a/src/ash/funcs/login b/src/ash/funcs/login
deleted file mode 100644
index 7ae08b2..0000000
--- a/src/ash/funcs/login
+++ /dev/null
@@ -1,39 +0,0 @@
-#	$NetBSD: login,v 1.7 1995/05/11 21:31:11 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)login	8.2 (Berkeley) 5/4/95
-
-# replaces the login builtin in the BSD shell
-login () exec login "$@"
diff --git a/src/ash/funcs/newgrp b/src/ash/funcs/newgrp
deleted file mode 100644
index 796a4f1..0000000
--- a/src/ash/funcs/newgrp
+++ /dev/null
@@ -1,38 +0,0 @@
-#	$NetBSD: newgrp,v 1.7 1995/05/11 21:31:12 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)newgrp	8.2 (Berkeley) 5/4/95
-
-newgrp() exec newgrp "$@"
diff --git a/src/ash/funcs/popd b/src/ash/funcs/popd
deleted file mode 100644
index b2b65d5..0000000
--- a/src/ash/funcs/popd
+++ /dev/null
@@ -1,74 +0,0 @@
-#	$NetBSD: popd,v 1.7 1995/05/11 21:31:13 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)popd	8.2 (Berkeley) 5/4/95
-
-# pushd, popd, and dirs --- written by Chris Bertin
-# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
-# as modified by Patrick Elam of GTRI and Kenneth Almquist at UW
-
-pushd () {
-	SAVE=`pwd`
-	if [ "$1" = "" ] 
-	then	if [ "$DSTACK" = "" ]
-		then	echo "pushd: directory stack empty."
-			return 1
-		fi
-		set $DSTACK
-		cd $1 || return
-		shift 1
-		DSTACK="$*"
-	else	cd $1 > /dev/null || return
-	fi
-	DSTACK="$SAVE $DSTACK"
-	dirs
-}
-
-popd () {
-	if [ "$DSTACK" = "" ] 
-	then	echo "popd: directory stack empty."
-		return 1
-	fi
-	set $DSTACK
-	cd $1
-	shift
-	DSTACK=$*
-	dirs
-}
-
-dirs () {
-	echo "`pwd` $DSTACK"
-	return 0
-}
diff --git a/src/ash/funcs/pushd b/src/ash/funcs/pushd
deleted file mode 100644
index b393038..0000000
--- a/src/ash/funcs/pushd
+++ /dev/null
@@ -1,74 +0,0 @@
-#	$NetBSD: pushd,v 1.7 1995/05/11 21:31:15 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)pushd	8.2 (Berkeley) 5/4/95
-
-# pushd, popd, and dirs --- written by Chris Bertin
-# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
-# as modified by Patrick Elam of GTRI and Kenneth Almquist at UW
-
-pushd () {
-	SAVE=`pwd`
-	if [ "$1" = "" ] 
-	then	if [ "$DSTACK" = "" ]
-		then	echo "pushd: directory stack empty."
-			return 1
-		fi
-		set $DSTACK
-		cd $1 || return
-		shift 1
-		DSTACK="$*"
-	else	cd $1 > /dev/null || return
-	fi
-	DSTACK="$SAVE $DSTACK"
-	dirs
-}
-
-popd () {
-	if [ "$DSTACK" = "" ] 
-	then	echo "popd: directory stack empty."
-		return 1
-	fi
-	set $DSTACK
-	cd $1
-	shift
-	DSTACK=$*
-	dirs
-}
-
-dirs () {
-	echo "`pwd` $DSTACK"
-	return 0
-}
diff --git a/src/ash/funcs/suspend b/src/ash/funcs/suspend
deleted file mode 100644
index 8a4197d..0000000
--- a/src/ash/funcs/suspend
+++ /dev/null
@@ -1,42 +0,0 @@
-#	$NetBSD: suspend,v 1.7 1995/05/11 21:31:17 christos Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)suspend	8.2 (Berkeley) 5/4/95
-
-suspend() {
-	local -
-	set +j
-	kill -TSTP 0
-}
diff --git a/src/ash/generated/arith.c b/src/ash/generated/arith.c
deleted file mode 100644
index 1054e7e..0000000
--- a/src/ash/generated/arith.c
+++ /dev/null
@@ -1,666 +0,0 @@
-#ifndef lint
-/*static char yysccsid[] = "from: @(#)yaccpar	1.9 (Berkeley) 02/21/93";*/
-static char yyrcsid[] = "$Id: skeleton.c,v 1.2 1997/06/23 02:51:17 tdukes Exp $";
-#endif
-#define YYBYACC 1
-#define YYMAJOR 1
-#define YYMINOR 9
-#define yyclearin (yychar=(-1))
-#define yyerrok (yyerrflag=0)
-#define YYRECOVERING (yyerrflag!=0)
-#define YYPREFIX "yy"
-/*	$NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)arith.y	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: arith.y,v 1.17 2003/09/17 17:33:36 jmmv Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#include "expand.h"
-#include "shell.h"
-#include "error.h"
-#include "output.h"
-#include "memalloc.h"
-
-const char *arith_buf, *arith_startbuf;
-
-void yyerror(const char *);
-#ifdef TESTARITH
-int main(int , char *[]);
-int error(char *);
-#endif
-
-#define ARITH_NUM 257
-#define ARITH_LPAREN 258
-#define ARITH_RPAREN 259
-#define ARITH_OR 260
-#define ARITH_AND 261
-#define ARITH_BOR 262
-#define ARITH_BXOR 263
-#define ARITH_BAND 264
-#define ARITH_EQ 265
-#define ARITH_NE 266
-#define ARITH_LT 267
-#define ARITH_GT 268
-#define ARITH_GE 269
-#define ARITH_LE 270
-#define ARITH_LSHIFT 271
-#define ARITH_RSHIFT 272
-#define ARITH_ADD 273
-#define ARITH_SUB 274
-#define ARITH_MUL 275
-#define ARITH_DIV 276
-#define ARITH_REM 277
-#define ARITH_UNARYMINUS 278
-#define ARITH_UNARYPLUS 279
-#define ARITH_NOT 280
-#define ARITH_BNOT 281
-#define YYERRCODE 256
-short yylhs[] = {                                        -1,
-    0,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    1,    1,    1,
-};
-short yylen[] = {                                         2,
-    1,    3,    3,    3,    3,    3,    3,    3,    3,    3,
-    3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
-    2,    2,    2,    2,    1,
-};
-short yydefred[] = {                                      0,
-   25,    0,    0,    0,    0,    0,    0,    0,    0,   24,
-   23,   21,   22,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    2,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,   18,   19,   20,
-};
-short yydgoto[] = {                                       7,
-    8,
-};
-short yysindex[] = {                                   -255,
-    0, -255, -255, -255, -255, -255,    0,  -67,  -85,    0,
-    0,    0,    0, -255, -255, -255, -255, -255, -255, -255,
- -255, -255, -255, -255, -255, -255, -255, -255, -255, -255,
- -255,    0,  -50,  -34,  -19,  141, -261, -233, -233, -223,
- -223, -223, -223, -253, -253, -248, -248,    0,    0,    0,
-};
-short yyrindex[] = {                                      0,
-    0,    0,    0,    0,    0,    0,    0,   30,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,  143,  140,  136,  131,  125,  109,  117,   61,
-   73,   85,   97,   33,   47,    1,   17,    0,    0,    0,
-};
-short yygindex[] = {                                      0,
-  142,
-};
-#define YYTABLESIZE 418
-short yytable[] = {                                       0,
-   16,    1,    2,   19,   20,   21,   22,   23,   24,   25,
-   26,   27,   28,   29,   30,   31,   17,    3,    4,   27,
-   28,   29,   30,   31,    5,    6,   29,   30,   31,    1,
-    0,    0,   14,   21,   22,   23,   24,   25,   26,   27,
-   28,   29,   30,   31,    0,    0,   15,   25,   26,   27,
-   28,   29,   30,   31,    0,    0,    0,    0,    0,    0,
-   11,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    9,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,   10,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,   12,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    8,    0,
-    0,    0,    0,    0,    0,    0,   13,    0,    0,    0,
-    0,    0,    0,    0,    7,    0,    0,    0,    0,    0,
-    6,    0,    0,    0,    0,    5,    0,    0,    0,    4,
-    0,    0,    3,    9,   10,   11,   12,   13,    0,    0,
-    0,    0,    0,    0,    0,   33,   34,   35,   36,   37,
-   38,   39,   40,   41,   42,   43,   44,   45,   46,   47,
-   48,   49,   50,   32,   14,   15,   16,   17,   18,   19,
-   20,   21,   22,   23,   24,   25,   26,   27,   28,   29,
-   30,   31,   14,   15,   16,   17,   18,   19,   20,   21,
-   22,   23,   24,   25,   26,   27,   28,   29,   30,   31,
-   15,   16,   17,   18,   19,   20,   21,   22,   23,   24,
-   25,   26,   27,   28,   29,   30,   31,   16,   17,   18,
-   19,   20,   21,   22,   23,   24,   25,   26,   27,   28,
-   29,   30,   31,   17,   18,   19,   20,   21,   22,   23,
-   24,   25,   26,   27,   28,   29,   30,   31,    0,   16,
-   16,   16,   16,   16,   16,   16,   16,   16,   16,   16,
-   16,   16,   16,   16,   16,   17,   17,   17,   17,   17,
-   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
-   17,   14,   14,   14,   14,   14,   14,   14,   14,   14,
-   14,   14,   14,   14,   14,   15,   15,   15,   15,   15,
-   15,   15,   15,   15,   15,   15,   15,   15,   15,   11,
-   11,   11,   11,   11,   11,   11,   11,   11,   11,   11,
-   11,    9,    9,    9,    9,    9,    9,    9,    9,    9,
-    9,    9,    9,   10,   10,   10,   10,   10,   10,   10,
-   10,   10,   10,   10,   10,   12,   12,   12,   12,   12,
-   12,   12,   12,   12,   12,   12,   12,    8,    8,    8,
-    8,    8,    8,    8,    8,   13,   13,   13,   13,   13,
-   13,   13,   13,    7,    7,    7,    7,    7,    7,    6,
-    6,    6,    6,    6,    5,    5,    5,    5,    4,    4,
-    4,    3,    3,    0,   18,   19,   20,   21,   22,   23,
-   24,   25,   26,   27,   28,   29,   30,   31,
-};
-short yycheck[] = {                                      -1,
-    0,  257,  258,  265,  266,  267,  268,  269,  270,  271,
-  272,  273,  274,  275,  276,  277,    0,  273,  274,  273,
-  274,  275,  276,  277,  280,  281,  275,  276,  277,    0,
-   -1,   -1,    0,  267,  268,  269,  270,  271,  272,  273,
-  274,  275,  276,  277,   -1,   -1,    0,  271,  272,  273,
-  274,  275,  276,  277,   -1,   -1,   -1,   -1,   -1,   -1,
-    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,
-   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,
-   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
-    0,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,    0,
-   -1,   -1,    0,    2,    3,    4,    5,    6,   -1,   -1,
-   -1,   -1,   -1,   -1,   -1,   14,   15,   16,   17,   18,
-   19,   20,   21,   22,   23,   24,   25,   26,   27,   28,
-   29,   30,   31,  259,  260,  261,  262,  263,  264,  265,
-  266,  267,  268,  269,  270,  271,  272,  273,  274,  275,
-  276,  277,  260,  261,  262,  263,  264,  265,  266,  267,
-  268,  269,  270,  271,  272,  273,  274,  275,  276,  277,
-  261,  262,  263,  264,  265,  266,  267,  268,  269,  270,
-  271,  272,  273,  274,  275,  276,  277,  262,  263,  264,
-  265,  266,  267,  268,  269,  270,  271,  272,  273,  274,
-  275,  276,  277,  263,  264,  265,  266,  267,  268,  269,
-  270,  271,  272,  273,  274,  275,  276,  277,   -1,  259,
-  260,  261,  262,  263,  264,  265,  266,  267,  268,  269,
-  270,  271,  272,  273,  274,  259,  260,  261,  262,  263,
-  264,  265,  266,  267,  268,  269,  270,  271,  272,  273,
-  274,  259,  260,  261,  262,  263,  264,  265,  266,  267,
-  268,  269,  270,  271,  272,  259,  260,  261,  262,  263,
-  264,  265,  266,  267,  268,  269,  270,  271,  272,  259,
-  260,  261,  262,  263,  264,  265,  266,  267,  268,  269,
-  270,  259,  260,  261,  262,  263,  264,  265,  266,  267,
-  268,  269,  270,  259,  260,  261,  262,  263,  264,  265,
-  266,  267,  268,  269,  270,  259,  260,  261,  262,  263,
-  264,  265,  266,  267,  268,  269,  270,  259,  260,  261,
-  262,  263,  264,  265,  266,  259,  260,  261,  262,  263,
-  264,  265,  266,  259,  260,  261,  262,  263,  264,  259,
-  260,  261,  262,  263,  259,  260,  261,  262,  259,  260,
-  261,  259,  260,   -1,  264,  265,  266,  267,  268,  269,
-  270,  271,  272,  273,  274,  275,  276,  277,
-};
-#define YYFINAL 7
-#ifndef YYDEBUG
-#define YYDEBUG 0
-#endif
-#define YYMAXTOKEN 281
-#if YYDEBUG
-char *yyname[] = {
-"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"ARITH_NUM","ARITH_LPAREN",
-"ARITH_RPAREN","ARITH_OR","ARITH_AND","ARITH_BOR","ARITH_BXOR","ARITH_BAND",
-"ARITH_EQ","ARITH_NE","ARITH_LT","ARITH_GT","ARITH_GE","ARITH_LE",
-"ARITH_LSHIFT","ARITH_RSHIFT","ARITH_ADD","ARITH_SUB","ARITH_MUL","ARITH_DIV",
-"ARITH_REM","ARITH_UNARYMINUS","ARITH_UNARYPLUS","ARITH_NOT","ARITH_BNOT",
-};
-char *yyrule[] = {
-"$accept : exp",
-"exp : expr",
-"expr : ARITH_LPAREN expr ARITH_RPAREN",
-"expr : expr ARITH_OR expr",
-"expr : expr ARITH_AND expr",
-"expr : expr ARITH_BOR expr",
-"expr : expr ARITH_BXOR expr",
-"expr : expr ARITH_BAND expr",
-"expr : expr ARITH_EQ expr",
-"expr : expr ARITH_GT expr",
-"expr : expr ARITH_GE expr",
-"expr : expr ARITH_LT expr",
-"expr : expr ARITH_LE expr",
-"expr : expr ARITH_NE expr",
-"expr : expr ARITH_LSHIFT expr",
-"expr : expr ARITH_RSHIFT expr",
-"expr : expr ARITH_ADD expr",
-"expr : expr ARITH_SUB expr",
-"expr : expr ARITH_MUL expr",
-"expr : expr ARITH_DIV expr",
-"expr : expr ARITH_REM expr",
-"expr : ARITH_NOT expr",
-"expr : ARITH_BNOT expr",
-"expr : ARITH_SUB expr",
-"expr : ARITH_ADD expr",
-"expr : ARITH_NUM",
-};
-#endif
-#ifndef YYSTYPE
-typedef int YYSTYPE;
-#endif
-#ifdef YYSTACKSIZE
-#undef YYMAXDEPTH
-#define YYMAXDEPTH YYSTACKSIZE
-#else
-#ifdef YYMAXDEPTH
-#define YYSTACKSIZE YYMAXDEPTH
-#else
-#define YYSTACKSIZE 500
-#define YYMAXDEPTH 500
-#endif
-#endif
-int yydebug;
-int yynerrs;
-int yyerrflag;
-int yychar;
-short *yyssp;
-YYSTYPE *yyvsp;
-YYSTYPE yyval;
-YYSTYPE yylval;
-short yyss[YYSTACKSIZE];
-YYSTYPE yyvs[YYSTACKSIZE];
-#define yystacksize YYSTACKSIZE
-int
-arith(s)
-	const char *s;
-{
-	long result;
-
-	arith_buf = arith_startbuf = s;
-
-	INTOFF;
-	result = yyparse();
-	arith_lex_reset();	/* reprime lex */
-	INTON;
-
-	return (result);
-}
-
-
-/*
- *  The exp(1) builtin.
- */
-int
-expcmd(argc, argv)
-	int argc;
-	char **argv;
-{
-	const char *p;
-	char *concat;
-	char **ap;
-	long i;
-
-	if (argc > 1) {
-		p = argv[1];
-		if (argc > 2) {
-			/*
-			 * concatenate arguments
-			 */
-			STARTSTACKSTR(concat);
-			ap = argv + 2;
-			for (;;) {
-				while (*p)
-					STPUTC(*p++, concat);
-				if ((p = *ap++) == NULL)
-					break;
-				STPUTC(' ', concat);
-			}
-			STPUTC('\0', concat);
-			p = grabstackstr(concat);
-		}
-	} else
-		p = "";
-
-	i = arith(p);
-
-	out1fmt("%ld\n", i);
-	return (! i);
-}
-
-/*************************/
-#ifdef TEST_ARITH
-#include <stdio.h>
-main(argc, argv)
-	char *argv[];
-{
-	printf("%d\n", exp(argv[1]));
-}
-error(s)
-	char *s;
-{
-	fprintf(stderr, "exp: %s\n", s);
-	exit(1);
-}
-#endif
-
-void
-yyerror(s)
-	const char *s;
-{
-
-	yyerrok;
-	yyclearin;
-	arith_lex_reset();	/* reprime lex */
-	error("arithmetic expression: %s: \"%s\"", s, arith_startbuf);
-	/* NOTREACHED */
-}
-#define YYABORT goto yyabort
-#define YYREJECT goto yyabort
-#define YYACCEPT goto yyaccept
-#define YYERROR goto yyerrlab
-#ifdef __cplusplus
-extern "C" { 
-char * getenv();
-int yylex();
-int yyparse();
-}
-
-#endif
-int
-#if defined(__STDC__)
-yyparse(void)
-#else
-yyparse()
-#endif
-{
-    register int yym, yyn, yystate;
-#if YYDEBUG
-    register char *yys;
-#ifndef __cplusplus
-    extern char *getenv();
-#endif
-
-    if (yys = getenv("YYDEBUG"))
-    {
-        yyn = *yys;
-        if (yyn >= '0' && yyn <= '9')
-            yydebug = yyn - '0';
-    }
-#endif
-
-    yynerrs = 0;
-    yyerrflag = 0;
-    yychar = (-1);
-
-    yyssp = yyss;
-    yyvsp = yyvs;
-    *yyssp = yystate = 0;
-
-yyloop:
-    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
-    if (yychar < 0)
-    {
-        if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
-        if (yydebug)
-        {
-            yys = 0;
-            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-            if (!yys) yys = "illegal-symbol";
-            printf("%sdebug: state %d, reading %d (%s)\n",
-                    YYPREFIX, yystate, yychar, yys);
-        }
-#endif
-    }
-    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
-    {
-#if YYDEBUG
-        if (yydebug)
-            printf("%sdebug: state %d, shifting to state %d\n",
-                    YYPREFIX, yystate, yytable[yyn]);
-#endif
-        if (yyssp >= yyss + yystacksize - 1)
-        {
-            goto yyoverflow;
-        }
-        *++yyssp = yystate = yytable[yyn];
-        *++yyvsp = yylval;
-        yychar = (-1);
-        if (yyerrflag > 0)  --yyerrflag;
-        goto yyloop;
-    }
-    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
-    {
-        yyn = yytable[yyn];
-        goto yyreduce;
-    }
-    if (yyerrflag) goto yyinrecovery;
-    yyerror("syntax error");
-#ifdef lint
-    goto yyerrlab;
-#endif
-yyerrlab:
-    ++yynerrs;
-yyinrecovery:
-    if (yyerrflag < 3)
-    {
-        yyerrflag = 3;
-        for (;;)
-        {
-            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
-                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
-            {
-#if YYDEBUG
-                if (yydebug)
-                    printf("%sdebug: state %d, error recovery shifting\
- to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
-#endif
-                if (yyssp >= yyss + yystacksize - 1)
-                {
-                    goto yyoverflow;
-                }
-                *++yyssp = yystate = yytable[yyn];
-                *++yyvsp = yylval;
-                goto yyloop;
-            }
-            else
-            {
-#if YYDEBUG
-                if (yydebug)
-                    printf("%sdebug: error recovery discarding state %d\n",
-                            YYPREFIX, *yyssp);
-#endif
-                if (yyssp <= yyss) goto yyabort;
-                --yyssp;
-                --yyvsp;
-            }
-        }
-    }
-    else
-    {
-        if (yychar == 0) goto yyabort;
-#if YYDEBUG
-        if (yydebug)
-        {
-            yys = 0;
-            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-            if (!yys) yys = "illegal-symbol";
-            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
-                    YYPREFIX, yystate, yychar, yys);
-        }
-#endif
-        yychar = (-1);
-        goto yyloop;
-    }
-yyreduce:
-#if YYDEBUG
-    if (yydebug)
-        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
-                YYPREFIX, yystate, yyn, yyrule[yyn]);
-#endif
-    yym = yylen[yyn];
-    yyval = yyvsp[1-yym];
-    switch (yyn)
-    {
-case 1:
-{
-			return (yyvsp[0]);
-		}
-break;
-case 2:
-{ yyval = yyvsp[-1]; }
-break;
-case 3:
-{ yyval = yyvsp[-2] ? yyvsp[-2] : yyvsp[0] ? yyvsp[0] : 0; }
-break;
-case 4:
-{ yyval = yyvsp[-2] ? ( yyvsp[0] ? yyvsp[0] : 0 ) : 0; }
-break;
-case 5:
-{ yyval = yyvsp[-2] | yyvsp[0]; }
-break;
-case 6:
-{ yyval = yyvsp[-2] ^ yyvsp[0]; }
-break;
-case 7:
-{ yyval = yyvsp[-2] & yyvsp[0]; }
-break;
-case 8:
-{ yyval = yyvsp[-2] == yyvsp[0]; }
-break;
-case 9:
-{ yyval = yyvsp[-2] > yyvsp[0]; }
-break;
-case 10:
-{ yyval = yyvsp[-2] >= yyvsp[0]; }
-break;
-case 11:
-{ yyval = yyvsp[-2] < yyvsp[0]; }
-break;
-case 12:
-{ yyval = yyvsp[-2] <= yyvsp[0]; }
-break;
-case 13:
-{ yyval = yyvsp[-2] != yyvsp[0]; }
-break;
-case 14:
-{ yyval = yyvsp[-2] << yyvsp[0]; }
-break;
-case 15:
-{ yyval = yyvsp[-2] >> yyvsp[0]; }
-break;
-case 16:
-{ yyval = yyvsp[-2] + yyvsp[0]; }
-break;
-case 17:
-{ yyval = yyvsp[-2] - yyvsp[0]; }
-break;
-case 18:
-{ yyval = yyvsp[-2] * yyvsp[0]; }
-break;
-case 19:
-{
-			if (yyvsp[0] == 0)
-				yyerror("division by zero");
-			yyval = yyvsp[-2] / yyvsp[0];
-			}
-break;
-case 20:
-{
-			if (yyvsp[0] == 0)
-				yyerror("division by zero");
-			yyval = yyvsp[-2] % yyvsp[0];
-			}
-break;
-case 21:
-{ yyval = !(yyvsp[0]); }
-break;
-case 22:
-{ yyval = ~(yyvsp[0]); }
-break;
-case 23:
-{ yyval = -(yyvsp[0]); }
-break;
-case 24:
-{ yyval = yyvsp[0]; }
-break;
-    }
-    yyssp -= yym;
-    yystate = *yyssp;
-    yyvsp -= yym;
-    yym = yylhs[yyn];
-    if (yystate == 0 && yym == 0)
-    {
-#if YYDEBUG
-        if (yydebug)
-            printf("%sdebug: after reduction, shifting from state 0 to\
- state %d\n", YYPREFIX, YYFINAL);
-#endif
-        yystate = YYFINAL;
-        *++yyssp = YYFINAL;
-        *++yyvsp = yyval;
-        if (yychar < 0)
-        {
-            if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
-            if (yydebug)
-            {
-                yys = 0;
-                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-                if (!yys) yys = "illegal-symbol";
-                printf("%sdebug: state %d, reading %d (%s)\n",
-                        YYPREFIX, YYFINAL, yychar, yys);
-            }
-#endif
-        }
-        if (yychar == 0) goto yyaccept;
-        goto yyloop;
-    }
-    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
-        yystate = yytable[yyn];
-    else
-        yystate = yydgoto[yym];
-#if YYDEBUG
-    if (yydebug)
-        printf("%sdebug: after reduction, shifting from state %d \
-to state %d\n", YYPREFIX, *yyssp, yystate);
-#endif
-    if (yyssp >= yyss + yystacksize - 1)
-    {
-        goto yyoverflow;
-    }
-    *++yyssp = yystate;
-    *++yyvsp = yyval;
-    goto yyloop;
-yyoverflow:
-    yyerror("yacc stack overflow");
-yyabort:
-    return (1);
-yyaccept:
-    return (0);
-}
diff --git a/src/ash/generated/arith.h b/src/ash/generated/arith.h
deleted file mode 100644
index e1c5356..0000000
--- a/src/ash/generated/arith.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#define ARITH_NUM 257
-#define ARITH_LPAREN 258
-#define ARITH_RPAREN 259
-#define ARITH_OR 260
-#define ARITH_AND 261
-#define ARITH_BOR 262
-#define ARITH_BXOR 263
-#define ARITH_BAND 264
-#define ARITH_EQ 265
-#define ARITH_NE 266
-#define ARITH_LT 267
-#define ARITH_GT 268
-#define ARITH_GE 269
-#define ARITH_LE 270
-#define ARITH_LSHIFT 271
-#define ARITH_RSHIFT 272
-#define ARITH_ADD 273
-#define ARITH_SUB 274
-#define ARITH_MUL 275
-#define ARITH_DIV 276
-#define ARITH_REM 277
-#define ARITH_UNARYMINUS 278
-#define ARITH_UNARYPLUS 279
-#define ARITH_NOT 280
-#define ARITH_BNOT 281
diff --git a/src/ash/generated/arith_lex.c b/src/ash/generated/arith_lex.c
deleted file mode 100644
index 284a506..0000000
--- a/src/ash/generated/arith_lex.c
+++ /dev/null
@@ -1,1724 +0,0 @@
-#line 2 "/home/bird/Coding/kBuild/svn/trunk/out/linux.x86/debug/obj/src/ash/arith_lex.c"
-/* A lexical scanner generated by flex */
-
-/* Scanner skeleton version:
- * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $
- */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-
-#include <stdio.h>
-#include <unistd.h>
-
-
-/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
-#ifdef c_plusplus
-#ifndef __cplusplus
-#define __cplusplus
-#endif
-#endif
-
-
-#ifdef __cplusplus
-
-#include <stdlib.h>
-
-/* Use prototypes in function declarations. */
-#define YY_USE_PROTOS
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else	/* ! __cplusplus */
-
-#if __STDC__
-
-#define YY_USE_PROTOS
-#define YY_USE_CONST
-
-#endif	/* __STDC__ */
-#endif	/* ! __cplusplus */
-
-#ifdef __TURBOC__
- #pragma warn -rch
- #pragma warn -use
-#include <io.h>
-#include <stdlib.h>
-#define YY_USE_CONST
-#define YY_USE_PROTOS
-#endif
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-
-#ifdef YY_USE_PROTOS
-#define YY_PROTO(proto) proto
-#else
-#define YY_PROTO(proto) ()
-#endif
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index.  If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-
-/* Enter a start condition.  This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN yy_start = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state.  The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START ((yy_start - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE yyrestart( yyin )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#define YY_BUF_SIZE 16384
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-
-extern int yyleng;
-extern FILE *yyin, *yyout;
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
-/* The funky do-while in the following #define is used to turn the definition
- * int a single C statement (which needs a semi-colon terminator).  This
- * avoids problems with code like:
- *
- * 	if ( condition_holds )
- *		yyless( 5 );
- *	else
- *		do_something_else();
- *
- * Prior to using the do-while the compiler would get upset at the
- * "else" because it interpreted the "if" statement as being all
- * done when it reached the ';' after the yyless() call.
- */
-
-/* Return all but the first 'n' matched characters back to the input stream. */
-
-#define yyless(n) \
-	do \
-		{ \
-		/* Undo effects of setting up yytext. */ \
-		*yy_cp = yy_hold_char; \
-		YY_RESTORE_YY_MORE_OFFSET \
-		yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
-		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
-		} \
-	while ( 0 )
-
-#define unput(c) yyunput( c, yytext_ptr )
-
-/* The following is because we cannot portably get our hands on size_t
- * (without autoconf's help, which isn't available because we want
- * flex-generated scanners to compile on their own).
- */
-typedef unsigned int yy_size_t;
-
-
-struct yy_buffer_state
-	{
-	FILE *yy_input_file;
-
-	char *yy_ch_buf;		/* input buffer */
-	char *yy_buf_pos;		/* current position in input buffer */
-
-	/* Size of input buffer in bytes, not including room for EOB
-	 * characters.
-	 */
-	yy_size_t yy_buf_size;
-
-	/* Number of characters read into yy_ch_buf, not including EOB
-	 * characters.
-	 */
-	int yy_n_chars;
-
-	/* Whether we "own" the buffer - i.e., we know we created it,
-	 * and can realloc() it to grow it, and should free() it to
-	 * delete it.
-	 */
-	int yy_is_our_buffer;
-
-	/* Whether this is an "interactive" input source; if so, and
-	 * if we're using stdio for input, then we want to use getc()
-	 * instead of fread(), to make sure we stop fetching input after
-	 * each newline.
-	 */
-	int yy_is_interactive;
-
-	/* Whether we're considered to be at the beginning of a line.
-	 * If so, '^' rules will be active on the next match, otherwise
-	 * not.
-	 */
-	int yy_at_bol;
-
-	/* Whether to try to fill the input buffer when we reach the
-	 * end of it.
-	 */
-	int yy_fill_buffer;
-
-	int yy_buffer_status;
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
-	/* When an EOF's been seen but there's still some text to process
-	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
-	 * shouldn't try reading from the input source any more.  We might
-	 * still have a bunch of tokens to match, though, because of
-	 * possible backing-up.
-	 *
-	 * When we actually see the EOF, we change the status to "new"
-	 * (via yyrestart()), so that the user can continue scanning by
-	 * just pointing yyin at a new input file.
-	 */
-#define YY_BUFFER_EOF_PENDING 2
-	};
-
-static YY_BUFFER_STATE yy_current_buffer = 0;
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- */
-#define YY_CURRENT_BUFFER yy_current_buffer
-
-
-/* yy_hold_char holds the character lost when yytext is formed. */
-static char yy_hold_char;
-
-static int yy_n_chars;		/* number of characters read into yy_ch_buf */
-
-
-int yyleng;
-
-/* Points to current character in buffer. */
-static char *yy_c_buf_p = (char *) 0;
-static int yy_init = 1;		/* whether we need to initialize */
-static int yy_start = 0;	/* start state number */
-
-/* Flag which is used to allow yywrap()'s to do buffer switches
- * instead of setting up a fresh yyin.  A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-
-void yyrestart YY_PROTO(( FILE *input_file ));
-
-void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
-void yy_load_buffer_state YY_PROTO(( void ));
-YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
-void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
-void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
-void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
-#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
-
-YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
-YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
-YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
-
-static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
-static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
-static void yy_flex_free YY_PROTO(( void * ));
-
-#define yy_new_buffer yy_create_buffer
-
-#define yy_set_interactive(is_interactive) \
-	{ \
-	if ( ! yy_current_buffer ) \
-		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
-	yy_current_buffer->yy_is_interactive = is_interactive; \
-	}
-
-#define yy_set_bol(at_bol) \
-	{ \
-	if ( ! yy_current_buffer ) \
-		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
-	yy_current_buffer->yy_at_bol = at_bol; \
-	}
-
-#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
-
-
-#define yywrap() 1
-#define YY_SKIP_YYWRAP
-typedef unsigned char YY_CHAR;
-FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
-typedef int yy_state_type;
-extern char *yytext;
-#define yytext_ptr yytext
-
-static yy_state_type yy_get_previous_state YY_PROTO(( void ));
-static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
-static int yy_get_next_buffer YY_PROTO(( void ));
-static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up yytext.
- */
-#define YY_DO_BEFORE_ACTION \
-	yytext_ptr = yy_bp; \
-	yyleng = (int) (yy_cp - yy_bp); \
-	yy_hold_char = *yy_cp; \
-	*yy_cp = '\0'; \
-	yy_c_buf_p = yy_cp;
-
-#define YY_NUM_RULES 29
-#define YY_END_OF_BUFFER 30
-static yyconst short int yy_accept[39] =
-    {   0,
-        0,    0,   30,   28,    1,    1,   27,   23,   12,    6,
-        7,   21,   24,   25,   22,    3,    4,   17,   28,   15,
-        5,   11,   10,   26,   14,    9,    3,    0,    4,   19,
-       18,   13,   16,   20,    5,    8,    2,    0
-    } ;
-
-static yyconst int yy_ec[256] =
-    {   0,
-        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    2,    4,    1,    1,    1,    5,    6,    1,    7,
-        8,    9,   10,    1,   11,    1,   12,   13,   14,   14,
-       14,   14,   14,   14,   14,   15,   15,    1,    1,   16,
-       17,   18,    1,    1,   19,   19,   19,   19,   19,   19,
-       20,   20,   20,   20,   20,   20,   20,   20,   20,   20,
-       20,   20,   20,   20,   20,   20,   20,   20,   20,   20,
-        1,    1,    1,   21,   20,    1,   19,   19,   19,   19,
-
-       19,   19,   20,   20,   20,   20,   20,   20,   20,   20,
-       20,   20,   20,   20,   20,   20,   20,   20,   20,   22,
-       20,   20,    1,   23,    1,   24,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1
-    } ;
-
-static yyconst int yy_meta[25] =
-    {   0,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    2,    2,    2,    1,    1,    1,    2,    3,
-        1,    3,    1,    1
-    } ;
-
-static yyconst short int yy_base[41] =
-    {   0,
-        0,    0,   47,   48,   48,   48,   29,   48,   39,   48,
-       48,   48,   48,   48,   48,   12,   14,   14,   27,   15,
-        0,   48,   20,   48,   48,   48,   22,    0,   24,   48,
-       48,   48,   48,   48,    0,   48,    0,   48,   38,   40
-    } ;
-
-static yyconst short int yy_def[41] =
-    {   0,
-       38,    1,   38,   38,   38,   38,   38,   38,   38,   38,
-       38,   38,   38,   38,   38,   38,   38,   38,   38,   38,
-       39,   38,   38,   38,   38,   38,   38,   40,   38,   38,
-       38,   38,   38,   38,   39,   38,   40,    0,   38,   38
-    } ;
-
-static yyconst short int yy_nxt[73] =
-    {   0,
-        4,    5,    6,    7,    8,    9,   10,   11,   12,   13,
-       14,   15,   16,   17,   17,   18,   19,   20,   21,   21,
-       22,   21,   23,   24,   27,   27,   29,   29,   29,   30,
-       31,   33,   34,   28,   27,   27,   29,   29,   29,   35,
-       35,   37,   36,   32,   26,   25,   38,    3,   38,   38,
-       38,   38,   38,   38,   38,   38,   38,   38,   38,   38,
-       38,   38,   38,   38,   38,   38,   38,   38,   38,   38,
-       38,   38
-    } ;
-
-static yyconst short int yy_chk[73] =
-    {   0,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,   16,   16,   17,   17,   17,   18,
-       18,   20,   20,   16,   27,   27,   29,   29,   29,   39,
-       39,   40,   23,   19,    9,    7,    3,   38,   38,   38,
-       38,   38,   38,   38,   38,   38,   38,   38,   38,   38,
-       38,   38,   38,   38,   38,   38,   38,   38,   38,   38,
-       38,   38
-    } ;
-
-static yy_state_type yy_last_accepting_state;
-static char *yy_last_accepting_cpos;
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-char *yytext;
-#line 1 "arith_lex.l"
-#define INITIAL 0
-#line 3 "arith_lex.l"
-/*	$NetBSD: arith_lex.l,v 1.13 2005/03/21 22:37:09 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)arith_lex.l	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: arith_lex.l,v 1.13 2005/03/21 22:37:09 dsl Exp $");
-#endif
-#endif /* not lint */
-
-#include <unistd.h>
-#include "arith.h"
-#include "error.h"
-#include "expand.h"
-#include "var.h"
-
-extern int yylval;
-extern char *arith_buf, *arith_startbuf;
-#undef YY_INPUT
-#define YY_INPUT(buf,result,max) \
-	result = (*buf = *arith_buf++) ? 1 : YY_NULL;
-#define YY_NO_UNPUT
-#line 448 "/home/bird/Coding/kBuild/svn/trunk/out/linux.x86/debug/obj/src/ash/arith_lex.c"
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int yywrap YY_PROTO(( void ));
-#else
-extern int yywrap YY_PROTO(( void ));
-#endif
-#endif
-
-#ifndef YY_NO_UNPUT
-static void yyunput YY_PROTO(( int c, char *buf_ptr ));
-#endif
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen YY_PROTO(( yyconst char * ));
-#endif
-
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
-static int yyinput YY_PROTO(( void ));
-#else
-static int input YY_PROTO(( void ));
-#endif
-#endif
-
-#if YY_STACK_USED
-static int yy_start_stack_ptr = 0;
-static int yy_start_stack_depth = 0;
-static int *yy_start_stack = 0;
-#ifndef YY_NO_PUSH_STATE
-static void yy_push_state YY_PROTO(( int new_state ));
-#endif
-#ifndef YY_NO_POP_STATE
-static void yy_pop_state YY_PROTO(( void ));
-#endif
-#ifndef YY_NO_TOP_STATE
-static int yy_top_state YY_PROTO(( void ));
-#endif
-
-#else
-#define YY_NO_PUSH_STATE 1
-#define YY_NO_POP_STATE 1
-#define YY_NO_TOP_STATE 1
-#endif
-
-#ifdef YY_MALLOC_DECL
-YY_MALLOC_DECL
-#else
-#if __STDC__
-#ifndef __cplusplus
-#include <stdlib.h>
-#endif
-#else
-/* Just try to get by without declaring the routines.  This will fail
- * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
- * or sizeof(void*) != sizeof(int).
- */
-#endif
-#endif
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-
-#ifndef ECHO
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
-#endif
-
-/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-	if ( yy_current_buffer->yy_is_interactive ) \
-		{ \
-		int c = '*', n; \
-		for ( n = 0; n < max_size && \
-			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
-			buf[n] = (char) c; \
-		if ( c == '\n' ) \
-			buf[n++] = (char) c; \
-		if ( c == EOF && ferror( yyin ) ) \
-			YY_FATAL_ERROR( "input in flex scanner failed" ); \
-		result = n; \
-		} \
-	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
-		  && ferror( yyin ) ) \
-		YY_FATAL_ERROR( "input in flex scanner failed" );
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
-#endif
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL int yylex YY_PROTO(( void ))
-#endif
-
-/* Code executed at the beginning of each rule, after yytext and yyleng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-#define YY_RULE_SETUP \
-	YY_USER_ACTION
-
-YY_DECL
-	{
-	register yy_state_type yy_current_state;
-	register char *yy_cp = NULL, *yy_bp = NULL;
-	register int yy_act;
-
-#line 60 "arith_lex.l"
-
-#line 601 "/home/bird/Coding/kBuild/svn/trunk/out/linux.x86/debug/obj/src/ash/arith_lex.c"
-
-	if ( yy_init )
-		{
-		yy_init = 0;
-
-#ifdef YY_USER_INIT
-		YY_USER_INIT;
-#endif
-
-		if ( ! yy_start )
-			yy_start = 1;	/* first start state */
-
-		if ( ! yyin )
-			yyin = stdin;
-
-		if ( ! yyout )
-			yyout = stdout;
-
-		if ( ! yy_current_buffer )
-			yy_current_buffer =
-				yy_create_buffer( yyin, YY_BUF_SIZE );
-
-		yy_load_buffer_state();
-		}
-
-	while ( 1 )		/* loops until end-of-file is reached */
-		{
-		yy_cp = yy_c_buf_p;
-
-		/* Support of yytext. */
-		*yy_cp = yy_hold_char;
-
-		/* yy_bp points to the position in yy_ch_buf of the start of
-		 * the current run.
-		 */
-		yy_bp = yy_cp;
-
-		yy_current_state = yy_start;
-yy_match:
-		do
-			{
-			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
-			if ( yy_accept[yy_current_state] )
-				{
-				yy_last_accepting_state = yy_current_state;
-				yy_last_accepting_cpos = yy_cp;
-				}
-			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
-				{
-				yy_current_state = (int) yy_def[yy_current_state];
-				if ( yy_current_state >= 39 )
-					yy_c = yy_meta[(unsigned int) yy_c];
-				}
-			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-			++yy_cp;
-			}
-		while ( yy_base[yy_current_state] != 48 );
-
-yy_find_action:
-		yy_act = yy_accept[yy_current_state];
-		if ( yy_act == 0 )
-			{ /* have to back up */
-			yy_cp = yy_last_accepting_cpos;
-			yy_current_state = yy_last_accepting_state;
-			yy_act = yy_accept[yy_current_state];
-			}
-
-		YY_DO_BEFORE_ACTION;
-
-
-do_action:	/* This label is used only to access EOF actions. */
-
-
-		switch ( yy_act )
-	{ /* beginning of action switch */
-			case 0: /* must back up */
-			/* undo the effects of YY_DO_BEFORE_ACTION */
-			*yy_cp = yy_hold_char;
-			yy_cp = yy_last_accepting_cpos;
-			yy_current_state = yy_last_accepting_state;
-			goto yy_find_action;
-
-case 1:
-YY_RULE_SETUP
-#line 61 "arith_lex.l"
-{ ; }
-	YY_BREAK
-case 2:
-YY_RULE_SETUP
-#line 62 "arith_lex.l"
-{ yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
-	YY_BREAK
-case 3:
-YY_RULE_SETUP
-#line 63 "arith_lex.l"
-{ yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
-	YY_BREAK
-case 4:
-YY_RULE_SETUP
-#line 64 "arith_lex.l"
-{ yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
-	YY_BREAK
-case 5:
-YY_RULE_SETUP
-#line 65 "arith_lex.l"
-{ char *v = lookupvar(yytext);
-			if (v) {
-				yylval = strtol(v, &v, 0);
-				if (*v == 0)
-					return ARITH_NUM;
-			}
-			error("arith: syntax error: \"%s\"", arith_startbuf);
-		}
-	YY_BREAK
-case 6:
-YY_RULE_SETUP
-#line 73 "arith_lex.l"
-{ return(ARITH_LPAREN); }
-	YY_BREAK
-case 7:
-YY_RULE_SETUP
-#line 74 "arith_lex.l"
-{ return(ARITH_RPAREN); }
-	YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 75 "arith_lex.l"
-{ return(ARITH_OR); }
-	YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 76 "arith_lex.l"
-{ return(ARITH_AND); }
-	YY_BREAK
-case 10:
-YY_RULE_SETUP
-#line 77 "arith_lex.l"
-{ return(ARITH_BOR); }
-	YY_BREAK
-case 11:
-YY_RULE_SETUP
-#line 78 "arith_lex.l"
-{ return(ARITH_BXOR); }
-	YY_BREAK
-case 12:
-YY_RULE_SETUP
-#line 79 "arith_lex.l"
-{ return(ARITH_BAND); }
-	YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 80 "arith_lex.l"
-{ return(ARITH_EQ); }
-	YY_BREAK
-case 14:
-YY_RULE_SETUP
-#line 81 "arith_lex.l"
-{ return(ARITH_NE); }
-	YY_BREAK
-case 15:
-YY_RULE_SETUP
-#line 82 "arith_lex.l"
-{ return(ARITH_GT); }
-	YY_BREAK
-case 16:
-YY_RULE_SETUP
-#line 83 "arith_lex.l"
-{ return(ARITH_GE); }
-	YY_BREAK
-case 17:
-YY_RULE_SETUP
-#line 84 "arith_lex.l"
-{ return(ARITH_LT); }
-	YY_BREAK
-case 18:
-YY_RULE_SETUP
-#line 85 "arith_lex.l"
-{ return(ARITH_LE); }
-	YY_BREAK
-case 19:
-YY_RULE_SETUP
-#line 86 "arith_lex.l"
-{ return(ARITH_LSHIFT); }
-	YY_BREAK
-case 20:
-YY_RULE_SETUP
-#line 87 "arith_lex.l"
-{ return(ARITH_RSHIFT); }
-	YY_BREAK
-case 21:
-YY_RULE_SETUP
-#line 88 "arith_lex.l"
-{ return(ARITH_MUL); }
-	YY_BREAK
-case 22:
-YY_RULE_SETUP
-#line 89 "arith_lex.l"
-{ return(ARITH_DIV); }
-	YY_BREAK
-case 23:
-YY_RULE_SETUP
-#line 90 "arith_lex.l"
-{ return(ARITH_REM); }
-	YY_BREAK
-case 24:
-YY_RULE_SETUP
-#line 91 "arith_lex.l"
-{ return(ARITH_ADD); }
-	YY_BREAK
-case 25:
-YY_RULE_SETUP
-#line 92 "arith_lex.l"
-{ return(ARITH_SUB); }
-	YY_BREAK
-case 26:
-YY_RULE_SETUP
-#line 93 "arith_lex.l"
-{ return(ARITH_BNOT); }
-	YY_BREAK
-case 27:
-YY_RULE_SETUP
-#line 94 "arith_lex.l"
-{ return(ARITH_NOT); }
-	YY_BREAK
-case 28:
-YY_RULE_SETUP
-#line 95 "arith_lex.l"
-{ error("arith: syntax error: \"%s\"", arith_startbuf); }
-	YY_BREAK
-case 29:
-YY_RULE_SETUP
-#line 96 "arith_lex.l"
-ECHO;
-	YY_BREAK
-#line 836 "/home/bird/Coding/kBuild/svn/trunk/out/linux.x86/debug/obj/src/ash/arith_lex.c"
-case YY_STATE_EOF(INITIAL):
-	yyterminate();
-
-	case YY_END_OF_BUFFER:
-		{
-		/* Amount of text matched not including the EOB char. */
-		int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
-
-		/* Undo the effects of YY_DO_BEFORE_ACTION. */
-		*yy_cp = yy_hold_char;
-		YY_RESTORE_YY_MORE_OFFSET
-
-		if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
-			{
-			/* We're scanning a new file or input source.  It's
-			 * possible that this happened because the user
-			 * just pointed yyin at a new source and called
-			 * yylex().  If so, then we have to assure
-			 * consistency between yy_current_buffer and our
-			 * globals.  Here is the right place to do so, because
-			 * this is the first action (other than possibly a
-			 * back-up) that will match for the new input source.
-			 */
-			yy_n_chars = yy_current_buffer->yy_n_chars;
-			yy_current_buffer->yy_input_file = yyin;
-			yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
-			}
-
-		/* Note that here we test for yy_c_buf_p "<=" to the position
-		 * of the first EOB in the buffer, since yy_c_buf_p will
-		 * already have been incremented past the NUL character
-		 * (since all states make transitions on EOB to the
-		 * end-of-buffer state).  Contrast this with the test
-		 * in input().
-		 */
-		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
-			{ /* This was really a NUL. */
-			yy_state_type yy_next_state;
-
-			yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
-
-			yy_current_state = yy_get_previous_state();
-
-			/* Okay, we're now positioned to make the NUL
-			 * transition.  We couldn't have
-			 * yy_get_previous_state() go ahead and do it
-			 * for us because it doesn't know how to deal
-			 * with the possibility of jamming (and we don't
-			 * want to build jamming into it because then it
-			 * will run more slowly).
-			 */
-
-			yy_next_state = yy_try_NUL_trans( yy_current_state );
-
-			yy_bp = yytext_ptr + YY_MORE_ADJ;
-
-			if ( yy_next_state )
-				{
-				/* Consume the NUL. */
-				yy_cp = ++yy_c_buf_p;
-				yy_current_state = yy_next_state;
-				goto yy_match;
-				}
-
-			else
-				{
-				yy_cp = yy_c_buf_p;
-				goto yy_find_action;
-				}
-			}
-
-		else switch ( yy_get_next_buffer() )
-			{
-			case EOB_ACT_END_OF_FILE:
-				{
-				yy_did_buffer_switch_on_eof = 0;
-
-				if ( yywrap() )
-					{
-					/* Note: because we've taken care in
-					 * yy_get_next_buffer() to have set up
-					 * yytext, we can now set up
-					 * yy_c_buf_p so that if some total
-					 * hoser (like flex itself) wants to
-					 * call the scanner after we return the
-					 * YY_NULL, it'll still work - another
-					 * YY_NULL will get returned.
-					 */
-					yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
-
-					yy_act = YY_STATE_EOF(YY_START);
-					goto do_action;
-					}
-
-				else
-					{
-					if ( ! yy_did_buffer_switch_on_eof )
-						YY_NEW_FILE;
-					}
-				break;
-				}
-
-			case EOB_ACT_CONTINUE_SCAN:
-				yy_c_buf_p =
-					yytext_ptr + yy_amount_of_matched_text;
-
-				yy_current_state = yy_get_previous_state();
-
-				yy_cp = yy_c_buf_p;
-				yy_bp = yytext_ptr + YY_MORE_ADJ;
-				goto yy_match;
-
-			case EOB_ACT_LAST_MATCH:
-				yy_c_buf_p =
-				&yy_current_buffer->yy_ch_buf[yy_n_chars];
-
-				yy_current_state = yy_get_previous_state();
-
-				yy_cp = yy_c_buf_p;
-				yy_bp = yytext_ptr + YY_MORE_ADJ;
-				goto yy_find_action;
-			}
-		break;
-		}
-
-	default:
-		YY_FATAL_ERROR(
-			"fatal flex scanner internal error--no action found" );
-	} /* end of action switch */
-		} /* end of scanning one token */
-	} /* end of yylex */
-
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- *	EOB_ACT_LAST_MATCH -
- *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- *	EOB_ACT_END_OF_FILE - end of file
- */
-
-static int yy_get_next_buffer()
-	{
-	register char *dest = yy_current_buffer->yy_ch_buf;
-	register char *source = yytext_ptr;
-	register int number_to_move, i;
-	int ret_val;
-
-	if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
-		YY_FATAL_ERROR(
-		"fatal flex scanner internal error--end of buffer missed" );
-
-	if ( yy_current_buffer->yy_fill_buffer == 0 )
-		{ /* Don't try to fill the buffer, so this is an EOF. */
-		if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
-			{
-			/* We matched a single character, the EOB, so
-			 * treat this as a final EOF.
-			 */
-			return EOB_ACT_END_OF_FILE;
-			}
-
-		else
-			{
-			/* We matched some text prior to the EOB, first
-			 * process it.
-			 */
-			return EOB_ACT_LAST_MATCH;
-			}
-		}
-
-	/* Try to read more data. */
-
-	/* First move last chars to start of buffer. */
-	number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
-
-	for ( i = 0; i < number_to_move; ++i )
-		*(dest++) = *(source++);
-
-	if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
-		/* don't do the read, it's not guaranteed to return an EOF,
-		 * just force an EOF
-		 */
-		yy_current_buffer->yy_n_chars = yy_n_chars = 0;
-
-	else
-		{
-		int num_to_read =
-			yy_current_buffer->yy_buf_size - number_to_move - 1;
-
-		while ( num_to_read <= 0 )
-			{ /* Not enough room in the buffer - grow it. */
-#ifdef YY_USES_REJECT
-			YY_FATAL_ERROR(
-"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
-#else
-
-			/* just a shorter name for the current buffer */
-			YY_BUFFER_STATE b = yy_current_buffer;
-
-			int yy_c_buf_p_offset =
-				(int) (yy_c_buf_p - b->yy_ch_buf);
-
-			if ( b->yy_is_our_buffer )
-				{
-				int new_size = b->yy_buf_size * 2;
-
-				if ( new_size <= 0 )
-					b->yy_buf_size += b->yy_buf_size / 8;
-				else
-					b->yy_buf_size *= 2;
-
-				b->yy_ch_buf = (char *)
-					/* Include room in for 2 EOB chars. */
-					yy_flex_realloc( (void *) b->yy_ch_buf,
-							 b->yy_buf_size + 2 );
-				}
-			else
-				/* Can't grow it, we don't own it. */
-				b->yy_ch_buf = 0;
-
-			if ( ! b->yy_ch_buf )
-				YY_FATAL_ERROR(
-				"fatal error - scanner input buffer overflow" );
-
-			yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
-
-			num_to_read = yy_current_buffer->yy_buf_size -
-						number_to_move - 1;
-#endif
-			}
-
-		if ( num_to_read > YY_READ_BUF_SIZE )
-			num_to_read = YY_READ_BUF_SIZE;
-
-		/* Read in more data. */
-		YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
-			yy_n_chars, num_to_read );
-
-		yy_current_buffer->yy_n_chars = yy_n_chars;
-		}
-
-	if ( yy_n_chars == 0 )
-		{
-		if ( number_to_move == YY_MORE_ADJ )
-			{
-			ret_val = EOB_ACT_END_OF_FILE;
-			yyrestart( yyin );
-			}
-
-		else
-			{
-			ret_val = EOB_ACT_LAST_MATCH;
-			yy_current_buffer->yy_buffer_status =
-				YY_BUFFER_EOF_PENDING;
-			}
-		}
-
-	else
-		ret_val = EOB_ACT_CONTINUE_SCAN;
-
-	yy_n_chars += number_to_move;
-	yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
-	yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
-
-	yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
-
-	return ret_val;
-	}
-
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
-static yy_state_type yy_get_previous_state()
-	{
-	register yy_state_type yy_current_state;
-	register char *yy_cp;
-
-	yy_current_state = yy_start;
-
-	for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
-		{
-		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
-		if ( yy_accept[yy_current_state] )
-			{
-			yy_last_accepting_state = yy_current_state;
-			yy_last_accepting_cpos = yy_cp;
-			}
-		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
-			{
-			yy_current_state = (int) yy_def[yy_current_state];
-			if ( yy_current_state >= 39 )
-				yy_c = yy_meta[(unsigned int) yy_c];
-			}
-		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-		}
-
-	return yy_current_state;
-	}
-
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- *	next_state = yy_try_NUL_trans( current_state );
- */
-
-#ifdef YY_USE_PROTOS
-static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
-#else
-static yy_state_type yy_try_NUL_trans( yy_current_state )
-yy_state_type yy_current_state;
-#endif
-	{
-	register int yy_is_jam;
-	register char *yy_cp = yy_c_buf_p;
-
-	register YY_CHAR yy_c = 1;
-	if ( yy_accept[yy_current_state] )
-		{
-		yy_last_accepting_state = yy_current_state;
-		yy_last_accepting_cpos = yy_cp;
-		}
-	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
-		{
-		yy_current_state = (int) yy_def[yy_current_state];
-		if ( yy_current_state >= 39 )
-			yy_c = yy_meta[(unsigned int) yy_c];
-		}
-	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-	yy_is_jam = (yy_current_state == 38);
-
-	return yy_is_jam ? 0 : yy_current_state;
-	}
-
-
-#ifndef YY_NO_UNPUT
-#ifdef YY_USE_PROTOS
-static void yyunput( int c, register char *yy_bp )
-#else
-static void yyunput( c, yy_bp )
-int c;
-register char *yy_bp;
-#endif
-	{
-	register char *yy_cp = yy_c_buf_p;
-
-	/* undo effects of setting up yytext */
-	*yy_cp = yy_hold_char;
-
-	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
-		{ /* need to shift things up to make room */
-		/* +2 for EOB chars. */
-		register int number_to_move = yy_n_chars + 2;
-		register char *dest = &yy_current_buffer->yy_ch_buf[
-					yy_current_buffer->yy_buf_size + 2];
-		register char *source =
-				&yy_current_buffer->yy_ch_buf[number_to_move];
-
-		while ( source > yy_current_buffer->yy_ch_buf )
-			*--dest = *--source;
-
-		yy_cp += (int) (dest - source);
-		yy_bp += (int) (dest - source);
-		yy_current_buffer->yy_n_chars =
-			yy_n_chars = yy_current_buffer->yy_buf_size;
-
-		if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
-			YY_FATAL_ERROR( "flex scanner push-back overflow" );
-		}
-
-	*--yy_cp = (char) c;
-
-
-	yytext_ptr = yy_bp;
-	yy_hold_char = *yy_cp;
-	yy_c_buf_p = yy_cp;
-	}
-#endif	/* ifndef YY_NO_UNPUT */
-
-
-#ifdef __cplusplus
-static int yyinput()
-#else
-static int input()
-#endif
-	{
-	int c;
-
-	*yy_c_buf_p = yy_hold_char;
-
-	if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
-		{
-		/* yy_c_buf_p now points to the character we want to return.
-		 * If this occurs *before* the EOB characters, then it's a
-		 * valid NUL; if not, then we've hit the end of the buffer.
-		 */
-		if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
-			/* This was really a NUL. */
-			*yy_c_buf_p = '\0';
-
-		else
-			{ /* need more input */
-			int offset = yy_c_buf_p - yytext_ptr;
-			++yy_c_buf_p;
-
-			switch ( yy_get_next_buffer() )
-				{
-				case EOB_ACT_LAST_MATCH:
-					/* This happens because yy_g_n_b()
-					 * sees that we've accumulated a
-					 * token and flags that we need to
-					 * try matching the token before
-					 * proceeding.  But for input(),
-					 * there's no matching to consider.
-					 * So convert the EOB_ACT_LAST_MATCH
-					 * to EOB_ACT_END_OF_FILE.
-					 */
-
-					/* Reset buffer status. */
-					yyrestart( yyin );
-
-					/* fall through */
-
-				case EOB_ACT_END_OF_FILE:
-					{
-					if ( yywrap() )
-						return EOF;
-
-					if ( ! yy_did_buffer_switch_on_eof )
-						YY_NEW_FILE;
-#ifdef __cplusplus
-					return yyinput();
-#else
-					return input();
-#endif
-					}
-
-				case EOB_ACT_CONTINUE_SCAN:
-					yy_c_buf_p = yytext_ptr + offset;
-					break;
-				}
-			}
-		}
-
-	c = *(unsigned char *) yy_c_buf_p;	/* cast for 8-bit char's */
-	*yy_c_buf_p = '\0';	/* preserve yytext */
-	yy_hold_char = *++yy_c_buf_p;
-
-
-	return c;
-	}
-
-
-#ifdef YY_USE_PROTOS
-void yyrestart( FILE *input_file )
-#else
-void yyrestart( input_file )
-FILE *input_file;
-#endif
-	{
-	if ( ! yy_current_buffer )
-		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
-
-	yy_init_buffer( yy_current_buffer, input_file );
-	yy_load_buffer_state();
-	}
-
-
-#ifdef YY_USE_PROTOS
-void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
-#else
-void yy_switch_to_buffer( new_buffer )
-YY_BUFFER_STATE new_buffer;
-#endif
-	{
-	if ( yy_current_buffer == new_buffer )
-		return;
-
-	if ( yy_current_buffer )
-		{
-		/* Flush out information for old buffer. */
-		*yy_c_buf_p = yy_hold_char;
-		yy_current_buffer->yy_buf_pos = yy_c_buf_p;
-		yy_current_buffer->yy_n_chars = yy_n_chars;
-		}
-
-	yy_current_buffer = new_buffer;
-	yy_load_buffer_state();
-
-	/* We don't actually know whether we did this switch during
-	 * EOF (yywrap()) processing, but the only time this flag
-	 * is looked at is after yywrap() is called, so it's safe
-	 * to go ahead and always set it.
-	 */
-	yy_did_buffer_switch_on_eof = 1;
-	}
-
-
-#ifdef YY_USE_PROTOS
-void yy_load_buffer_state( void )
-#else
-void yy_load_buffer_state()
-#endif
-	{
-	yy_n_chars = yy_current_buffer->yy_n_chars;
-	yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
-	yyin = yy_current_buffer->yy_input_file;
-	yy_hold_char = *yy_c_buf_p;
-	}
-
-
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
-#else
-YY_BUFFER_STATE yy_create_buffer( file, size )
-FILE *file;
-int size;
-#endif
-	{
-	YY_BUFFER_STATE b;
-
-	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
-	if ( ! b )
-		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
-	b->yy_buf_size = size;
-
-	/* yy_ch_buf has to be 2 characters longer than the size given because
-	 * we need to put in 2 end-of-buffer characters.
-	 */
-	b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
-	if ( ! b->yy_ch_buf )
-		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
-
-	b->yy_is_our_buffer = 1;
-
-	yy_init_buffer( b, file );
-
-	return b;
-	}
-
-
-#ifdef YY_USE_PROTOS
-void yy_delete_buffer( YY_BUFFER_STATE b )
-#else
-void yy_delete_buffer( b )
-YY_BUFFER_STATE b;
-#endif
-	{
-	if ( ! b )
-		return;
-
-	if ( b == yy_current_buffer )
-		yy_current_buffer = (YY_BUFFER_STATE) 0;
-
-	if ( b->yy_is_our_buffer )
-		yy_flex_free( (void *) b->yy_ch_buf );
-
-	yy_flex_free( (void *) b );
-	}
-
-
-
-#ifdef YY_USE_PROTOS
-void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
-#else
-void yy_init_buffer( b, file )
-YY_BUFFER_STATE b;
-FILE *file;
-#endif
-
-
-	{
-	yy_flush_buffer( b );
-
-	b->yy_input_file = file;
-	b->yy_fill_buffer = 1;
-
-#if YY_ALWAYS_INTERACTIVE
-	b->yy_is_interactive = 1;
-#else
-#if YY_NEVER_INTERACTIVE
-	b->yy_is_interactive = 0;
-#else
-	b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
-#endif
-#endif
-	}
-
-
-#ifdef YY_USE_PROTOS
-void yy_flush_buffer( YY_BUFFER_STATE b )
-#else
-void yy_flush_buffer( b )
-YY_BUFFER_STATE b;
-#endif
-
-	{
-	if ( ! b )
-		return;
-
-	b->yy_n_chars = 0;
-
-	/* We always need two end-of-buffer characters.  The first causes
-	 * a transition to the end-of-buffer state.  The second causes
-	 * a jam in that state.
-	 */
-	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
-	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
-	b->yy_buf_pos = &b->yy_ch_buf[0];
-
-	b->yy_at_bol = 1;
-	b->yy_buffer_status = YY_BUFFER_NEW;
-
-	if ( b == yy_current_buffer )
-		yy_load_buffer_state();
-	}
-
-
-#ifndef YY_NO_SCAN_BUFFER
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
-#else
-YY_BUFFER_STATE yy_scan_buffer( base, size )
-char *base;
-yy_size_t size;
-#endif
-	{
-	YY_BUFFER_STATE b;
-
-	if ( size < 2 ||
-	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
-	     base[size-1] != YY_END_OF_BUFFER_CHAR )
-		/* They forgot to leave room for the EOB's. */
-		return 0;
-
-	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
-	if ( ! b )
-		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
-
-	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
-	b->yy_buf_pos = b->yy_ch_buf = base;
-	b->yy_is_our_buffer = 0;
-	b->yy_input_file = 0;
-	b->yy_n_chars = b->yy_buf_size;
-	b->yy_is_interactive = 0;
-	b->yy_at_bol = 1;
-	b->yy_fill_buffer = 0;
-	b->yy_buffer_status = YY_BUFFER_NEW;
-
-	yy_switch_to_buffer( b );
-
-	return b;
-	}
-#endif
-
-
-#ifndef YY_NO_SCAN_STRING
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
-#else
-YY_BUFFER_STATE yy_scan_string( yy_str )
-yyconst char *yy_str;
-#endif
-	{
-	int len;
-	for ( len = 0; yy_str[len]; ++len )
-		;
-
-	return yy_scan_bytes( yy_str, len );
-	}
-#endif
-
-
-#ifndef YY_NO_SCAN_BYTES
-#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
-#else
-YY_BUFFER_STATE yy_scan_bytes( bytes, len )
-yyconst char *bytes;
-int len;
-#endif
-	{
-	YY_BUFFER_STATE b;
-	char *buf;
-	yy_size_t n;
-	int i;
-
-	/* Get memory for full buffer, including space for trailing EOB's. */
-	n = len + 2;
-	buf = (char *) yy_flex_alloc( n );
-	if ( ! buf )
-		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
-
-	for ( i = 0; i < len; ++i )
-		buf[i] = bytes[i];
-
-	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
-
-	b = yy_scan_buffer( buf, n );
-	if ( ! b )
-		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
-
-	/* It's okay to grow etc. this buffer, and we should throw it
-	 * away when we're done.
-	 */
-	b->yy_is_our_buffer = 1;
-
-	return b;
-	}
-#endif
-
-
-#ifndef YY_NO_PUSH_STATE
-#ifdef YY_USE_PROTOS
-static void yy_push_state( int new_state )
-#else
-static void yy_push_state( new_state )
-int new_state;
-#endif
-	{
-	if ( yy_start_stack_ptr >= yy_start_stack_depth )
-		{
-		yy_size_t new_size;
-
-		yy_start_stack_depth += YY_START_STACK_INCR;
-		new_size = yy_start_stack_depth * sizeof( int );
-
-		if ( ! yy_start_stack )
-			yy_start_stack = (int *) yy_flex_alloc( new_size );
-
-		else
-			yy_start_stack = (int *) yy_flex_realloc(
-					(void *) yy_start_stack, new_size );
-
-		if ( ! yy_start_stack )
-			YY_FATAL_ERROR(
-			"out of memory expanding start-condition stack" );
-		}
-
-	yy_start_stack[yy_start_stack_ptr++] = YY_START;
-
-	BEGIN(new_state);
-	}
-#endif
-
-
-#ifndef YY_NO_POP_STATE
-static void yy_pop_state()
-	{
-	if ( --yy_start_stack_ptr < 0 )
-		YY_FATAL_ERROR( "start-condition stack underflow" );
-
-	BEGIN(yy_start_stack[yy_start_stack_ptr]);
-	}
-#endif
-
-
-#ifndef YY_NO_TOP_STATE
-static int yy_top_state()
-	{
-	return yy_start_stack[yy_start_stack_ptr - 1];
-	}
-#endif
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-#ifdef YY_USE_PROTOS
-static void yy_fatal_error( yyconst char msg[] )
-#else
-static void yy_fatal_error( msg )
-char msg[];
-#endif
-	{
-	(void) fprintf( stderr, "%s\n", msg );
-	exit( YY_EXIT_FAILURE );
-	}
-
-
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
-	do \
-		{ \
-		/* Undo effects of setting up yytext. */ \
-		yytext[yyleng] = yy_hold_char; \
-		yy_c_buf_p = yytext + n; \
-		yy_hold_char = *yy_c_buf_p; \
-		*yy_c_buf_p = '\0'; \
-		yyleng = n; \
-		} \
-	while ( 0 )
-
-
-/* Internal utility routines. */
-
-#ifndef yytext_ptr
-#ifdef YY_USE_PROTOS
-static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
-#else
-static void yy_flex_strncpy( s1, s2, n )
-char *s1;
-yyconst char *s2;
-int n;
-#endif
-	{
-	register int i;
-	for ( i = 0; i < n; ++i )
-		s1[i] = s2[i];
-	}
-#endif
-
-#ifdef YY_NEED_STRLEN
-#ifdef YY_USE_PROTOS
-static int yy_flex_strlen( yyconst char *s )
-#else
-static int yy_flex_strlen( s )
-yyconst char *s;
-#endif
-	{
-	register int n;
-	for ( n = 0; s[n]; ++n )
-		;
-
-	return n;
-	}
-#endif
-
-
-#ifdef YY_USE_PROTOS
-static void *yy_flex_alloc( yy_size_t size )
-#else
-static void *yy_flex_alloc( size )
-yy_size_t size;
-#endif
-	{
-	return (void *) malloc( size );
-	}
-
-#ifdef YY_USE_PROTOS
-static void *yy_flex_realloc( void *ptr, yy_size_t size )
-#else
-static void *yy_flex_realloc( ptr, size )
-void *ptr;
-yy_size_t size;
-#endif
-	{
-	/* The cast to (char *) in the following accommodates both
-	 * implementations that use char* generic pointers, and those
-	 * that use void* generic pointers.  It works with the latter
-	 * because both ANSI C and C++ allow castless assignment from
-	 * any pointer type to void*, and deal with argument conversions
-	 * as though doing an assignment.
-	 */
-	return (void *) realloc( (char *) ptr, size );
-	}
-
-#ifdef YY_USE_PROTOS
-static void yy_flex_free( void *ptr )
-#else
-static void yy_flex_free( ptr )
-void *ptr;
-#endif
-	{
-	free( ptr );
-	}
-
-#if YY_MAIN
-int main()
-	{
-	yylex();
-	return 0;
-	}
-#endif
-#line 96 "arith_lex.l"
-
-
-void
-arith_lex_reset() {
-#ifdef YY_NEW_FILE
-	YY_NEW_FILE;
-#endif
-}
diff --git a/src/ash/generated/builtins.c b/src/ash/generated/builtins.c
deleted file mode 100644
index f9c2f60..0000000
--- a/src/ash/generated/builtins.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This file was generated by the mkbuiltins program.
- */
-
-#include "shell.h"
-#include "builtins.h"
-
-const struct builtincmd builtincmd[] = {
-
-	{ "command",	bltincmd },
-	{ "bg",	bgcmd },
-	{ "cd",	cdcmd },
-	{ "chdir",	cdcmd },
-	{ "echo",	echocmd },
-	{ "exp",	expcmd },
-	{ "let",	expcmd },
-	{ "false",	falsecmd },
-	{ "fc",	histcmd },
-	{ "inputrc",	inputrc },
-	{ "fg",	fgcmd },
-	{ "getopts",	getoptscmd },
-	{ "hash",	hashcmd },
-	{ "jobid",	jobidcmd },
-	{ "jobs",	jobscmd },
-	{ "local",	localcmd },
-#ifndef SMALL
-	{ "printf",	printfcmd },
-#endif
-	{ "pwd",	pwdcmd },
-	{ "read",	readcmd },
-	{ "setvar",	setvarcmd },
-	{ "true",	truecmd },
-	{ "type",	typecmd },
-	{ "umask",	umaskcmd },
-	{ "unalias",	unaliascmd },
-	{ "wait",	waitcmd },
-	{ "alias",	aliascmd },
-	{ "ulimit",	ulimitcmd },
-	{ "test",	testcmd },
-	{ "[",	testcmd },
-	{ "kill",	killcmd },
-	{ "wordexp",	wordexpcmd },
-	{ 0, 0 },
-};
-
-const struct builtincmd splbltincmd[] = {
-	{ "break",	breakcmd },
-	{ "continue",	breakcmd },
-	{ ".",	dotcmd },
-	{ "eval",	evalcmd },
-	{ "exec",	execcmd },
-	{ "exit",	exitcmd },
-	{ "export",	exportcmd },
-	{ "readonly",	exportcmd },
-	{ "return",	returncmd },
-	{ "set",	setcmd },
-	{ "shift",	shiftcmd },
-	{ "times",	timescmd },
-	{ "trap",	trapcmd },
-	{ ":",	truecmd },
-	{ "unset",	unsetcmd },
-	{ 0, 0 },
-};
diff --git a/src/ash/generated/builtins.h b/src/ash/generated/builtins.h
deleted file mode 100644
index 7d8f728..0000000
--- a/src/ash/generated/builtins.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * This file was generated by the mkbuiltins program.
- */
-
-#include <sys/cdefs.h>
-
-struct builtincmd {
-      const char *name;
-      int (*builtin)(int, char **);
-};
-
-extern const struct builtincmd builtincmd[];
-extern const struct builtincmd splbltincmd[];
-
-
-int bltincmd(int, char **);
-int bgcmd(int, char **);
-int breakcmd(int, char **);
-int cdcmd(int, char **);
-int dotcmd(int, char **);
-int echocmd(int, char **);
-int evalcmd(int, char **);
-int execcmd(int, char **);
-int exitcmd(int, char **);
-int expcmd(int, char **);
-int exportcmd(int, char **);
-int falsecmd(int, char **);
-int histcmd(int, char **);
-int inputrc(int, char **);
-int fgcmd(int, char **);
-int getoptscmd(int, char **);
-int hashcmd(int, char **);
-int jobidcmd(int, char **);
-int jobscmd(int, char **);
-int localcmd(int, char **);
-#ifndef SMALL
-int printfcmd(int, char **);
-#endif
-int pwdcmd(int, char **);
-int readcmd(int, char **);
-int returncmd(int, char **);
-int setcmd(int, char **);
-int setvarcmd(int, char **);
-int shiftcmd(int, char **);
-int timescmd(int, char **);
-int trapcmd(int, char **);
-int truecmd(int, char **);
-int typecmd(int, char **);
-int umaskcmd(int, char **);
-int unaliascmd(int, char **);
-int unsetcmd(int, char **);
-int waitcmd(int, char **);
-int aliascmd(int, char **);
-int ulimitcmd(int, char **);
-int testcmd(int, char **);
-int killcmd(int, char **);
-int wordexpcmd(int, char **);
diff --git a/src/ash/generated/init.c b/src/ash/generated/init.c
deleted file mode 100644
index 1de3c3d..0000000
--- a/src/ash/generated/init.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * This file was generated by the mkinit program.
- */
-
-#include "shell.h"
-#include "mystring.h"
-#include "init.h"
-#include "eval.h"
-#include <stdio.h>
-#include "input.h"
-#include "error.h"
-#include <stdlib.h>
-#include "options.h"
-#include "output.h"
-#include "memalloc.h"
-#include "redir.h"
-#include <signal.h>
-#include "trap.h"
-#include "var.h"
-
-
-
-#undef  ATABSIZE
-#define ATABSIZE 39
-#undef  MAXPWD
-#define MAXPWD 256
-#undef  ALL
-#define ALL (E_OPEN|E_CREAT|E_EXEC)
-#undef  EV_EXIT
-#define EV_EXIT 01		/* exit after evaluating tree */
-#undef  EV_TESTED
-#define EV_TESTED 02		/* exit status is checked; ignore -e flag */
-#undef  EV_BACKCMD
-#define EV_BACKCMD 04		/* command executing within back quotes */
-#undef  CMDTABLESIZE
-#define CMDTABLESIZE 31		/* should be prime */
-#undef  ARB
-#define ARB 1			/* actual size determined at run time */
-#undef  NEWARGS
-#define NEWARGS 5
-#undef  MAXHISTLOOPS
-#define MAXHISTLOOPS	4	/* max recursions through fc */
-#undef  DEFEDITOR
-#define DEFEDITOR	"ed"	/* default editor *should* be $EDITOR */
-#undef  editing
-#define editing (Eflag || Vflag)
-#undef  EOF_NLEFT
-#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
-#undef  MAXMBOXES
-#define MAXMBOXES 10
-#undef  PROFILE
-#define PROFILE 0
-#undef  SIGSSIZE
-#define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0]))
-#undef  MINSIZE
-#define MINSIZE 504		/* minimum size of a block */
-#undef  DEFINE_OPTIONS
-#define DEFINE_OPTIONS
-#undef  OUTBUFSIZ
-#define OUTBUFSIZ BUFSIZ
-#undef  BLOCK_OUT
-#define BLOCK_OUT -2		/* output to a fixed block of memory */
-#undef  MEM_OUT
-#define MEM_OUT -3		/* output to dynamically allocated memory */
-#undef  OUTPUT_ERR
-#define OUTPUT_ERR 01		/* error occurred on output */
-#undef  TEMPSIZE
-#define TEMPSIZE 24
-#undef  HAVE_VASPRINTF
-#define HAVE_VASPRINTF 1
-#undef  EOFMARKLEN
-#define EOFMARKLEN 79
-#undef  OPENBRACE
-#define OPENBRACE '{'
-#undef  CLOSEBRACE
-#define CLOSEBRACE '}'
-#undef  EMPTY
-#define EMPTY -2		/* marks an unused slot in redirtab */
-#undef  S_DFL
-#define S_DFL 1			/* default signal handling (SIG_DFL) */
-#undef  S_CATCH
-#define S_CATCH 2		/* signal is caught */
-#undef  S_IGN
-#define S_IGN 3			/* signal is ignored (SIG_IGN) */
-#undef  S_HARD_IGN
-#define S_HARD_IGN 4		/* signal is ignored permenantly */
-#undef  S_RESET
-#define S_RESET 5		/* temporary - to reset a hard ignored sig */
-#undef  INCL_BASE
-#define INCL_BASE
-#undef  LIBPATHSTRICT
-#define LIBPATHSTRICT 3
-#undef  QHINF_EXEINFO
-#define QHINF_EXEINFO       1 /* NE exeinfo. */
-#undef  QHINF_READRSRCTBL
-#define QHINF_READRSRCTBL   2 /* Reads from the resource table. */
-#undef  QHINF_READFILE
-#define QHINF_READFILE      3 /* Reads from the executable file. */
-#undef  QHINF_LIBPATHLENGTH
-#define QHINF_LIBPATHLENGTH 4 /* Gets the libpath length. */
-#undef  QHINF_LIBPATH
-#define QHINF_LIBPATH       5 /* Gets the entire libpath. */
-#undef  QHINF_FIXENTRY
-#define QHINF_FIXENTRY      6 /* NE only */
-#undef  QHINF_STE
-#define QHINF_STE           7 /* NE only */
-#undef  QHINF_MAPSEL
-#define QHINF_MAPSEL        8 /* NE only */
-#undef  VTABSIZE
-#define VTABSIZE 39
-#undef  VTABSIZE
-#define VTABSIZE 517
-#undef  main
-#define main echocmd
-#undef  main
-#define main killcmd
-
-
-
-extern void rmaliases(void);
-
-extern int loopnest;		/* current loop nesting level */
-
-extern void deletefuncs(void);
-extern void hash_special_builtins(void);
-
-struct strpush {
-	struct strpush *prev;	/* preceding string on stack */
-	char *prevstring;
-	int prevnleft;
-	int prevlleft;
-	struct alias *ap;	/* if push was associated with an alias */
-};
-
-struct parsefile {
-	struct parsefile *prev;	/* preceding file on stack */
-	int linno;		/* current line */
-	int fd;			/* file descriptor (or -1 if string) */
-	int nleft;		/* number of chars left in this line */
-	int lleft;		/* number of chars left in this buffer */
-	char *nextc;		/* next char in buffer */
-	char *buf;		/* input buffer */
-	struct strpush *strpush; /* for pushing strings at this level */
-	struct strpush basestrpush; /* so pushing one is fast */
-};
-
-extern int parselleft;		/* copy of parsefile->lleft */
-extern struct parsefile basepf;	/* top level input file */
-extern char basebuf[BUFSIZ];	/* buffer for top level input file */
-
-extern pid_t backgndpid;	/* pid of last background process */
-extern int jobctl;
-
-extern int tokpushback;		/* last token pushed back */
-extern int checkkwd;            /* 1 == check for kwds, 2 == also eat newlines */
-
-struct redirtab {
-	struct redirtab *next;
-	short renamed[10];
-};
-
-extern struct redirtab *redirlist;
-
-extern char sigmode[NSIG];	/* current value of signal */
-
-extern char **environ;
-
-
-
-/*
- * Initialization code.
- */
-
-void
-init() {
-
-      /* from exec.c: */
-      {
-	      hash_special_builtins();
-      }
-
-      /* from input.c: */
-      {
-	      basepf.nextc = basepf.buf = basebuf;
-      }
-
-      /* from var.c: */
-      {
-	      char **envp;
-
-	      initvar();
-	      for (envp = environ ; *envp ; envp++) {
-		      if (strchr(*envp, '=')) {
-			      setvareq(*envp, VEXPORT|VTEXTFIXED);
-		      }
-	      }
-      }
-}
-
-
-
-/*
- * This routine is called when an error or an interrupt occurs in an
- * interactive shell and control is returned to the main command loop.
- */
-
-void
-reset() {
-
-      /* from eval.c: */
-      {
-	      evalskip = 0;
-	      loopnest = 0;
-	      funcnest = 0;
-      }
-
-      /* from input.c: */
-      {
-	      if (exception != EXSHELLPROC)
-		      parselleft = parsenleft = 0;	/* clear input buffer */
-	      popallfiles();
-      }
-
-      /* from output.c: */
-      {
-	      out1 = &output;
-	      out2 = &errout;
-	      if (memout.buf != NULL) {
-		      ckfree(memout.buf);
-		      memout.buf = NULL;
-	      }
-      }
-
-      /* from parser.c: */
-      {
-	      tokpushback = 0;
-	      checkkwd = 0;
-      }
-
-      /* from redir.c: */
-      {
-	      while (redirlist)
-		      popredir();
-      }
-}
-
-
-
-/*
- * This routine is called to initialize the shell to run a shell procedure.
- */
-
-void
-initshellproc() {
-
-      /* from alias.c: */
-      {
-	      rmaliases();
-      }
-
-      /* from eval.c: */
-      {
-	      exitstatus = 0;
-      }
-
-      /* from exec.c: */
-      {
-	      deletefuncs();
-      }
-
-      /* from input.c: */
-      {
-	      popallfiles();
-      }
-
-      /* from jobs.c: */
-      {
-	      backgndpid = -1;
-#if JOBS
-	      jobctl = 0;
-#endif
-      }
-
-      /* from options.c: */
-      {
-	      int i;
-
-	      for (i = 0; optlist[i].name; i++)
-		      optlist[i].val = 0;
-	      optschanged();
-
-      }
-
-      /* from redir.c: */
-      {
-	      clearredir(0);
-      }
-
-      /* from trap.c: */
-      {
-	      char *sm;
-
-	      clear_traps(0);
-	      for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
-		      if (*sm == S_IGN)
-			      *sm = S_HARD_IGN;
-	      }
-      }
-
-      /* from var.c: */
-      {
-	      shprocvar();
-      }
-}
diff --git a/src/ash/generated/nodes.c b/src/ash/generated/nodes.c
deleted file mode 100644
index 8a2c718..0000000
--- a/src/ash/generated/nodes.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * This file was generated by mknodes.sh
- */
-
-/*	$NetBSD: nodes.c.pat,v 1.12 2004/06/15 22:57:27 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)nodes.c.pat	8.2 (Berkeley) 5/4/95
- */
-
-#include <stdlib.h>
-/*
- * Routine for dealing with parsed shell commands.
- */
-
-#include "shell.h"
-#include "nodes.h"
-#include "memalloc.h"
-#include "machdep.h"
-#include "mystring.h"
-
-
-int     funcblocksize;		/* size of structures in function */
-int     funcstringsize;		/* size of strings in node */
-pointer funcblock;		/* block to allocate function from */
-char   *funcstring;		/* block to allocate strings from */
-
-static const short nodesize[26] = {
-      SHELL_ALIGN(sizeof (struct nbinary)),
-      SHELL_ALIGN(sizeof (struct ncmd)),
-      SHELL_ALIGN(sizeof (struct npipe)),
-      SHELL_ALIGN(sizeof (struct nredir)),
-      SHELL_ALIGN(sizeof (struct nredir)),
-      SHELL_ALIGN(sizeof (struct nredir)),
-      SHELL_ALIGN(sizeof (struct nbinary)),
-      SHELL_ALIGN(sizeof (struct nbinary)),
-      SHELL_ALIGN(sizeof (struct nif)),
-      SHELL_ALIGN(sizeof (struct nbinary)),
-      SHELL_ALIGN(sizeof (struct nbinary)),
-      SHELL_ALIGN(sizeof (struct nfor)),
-      SHELL_ALIGN(sizeof (struct ncase)),
-      SHELL_ALIGN(sizeof (struct nclist)),
-      SHELL_ALIGN(sizeof (struct narg)),
-      SHELL_ALIGN(sizeof (struct narg)),
-      SHELL_ALIGN(sizeof (struct nfile)),
-      SHELL_ALIGN(sizeof (struct nfile)),
-      SHELL_ALIGN(sizeof (struct nfile)),
-      SHELL_ALIGN(sizeof (struct nfile)),
-      SHELL_ALIGN(sizeof (struct nfile)),
-      SHELL_ALIGN(sizeof (struct ndup)),
-      SHELL_ALIGN(sizeof (struct ndup)),
-      SHELL_ALIGN(sizeof (struct nhere)),
-      SHELL_ALIGN(sizeof (struct nhere)),
-      SHELL_ALIGN(sizeof (struct nnot)),
-};
-
-
-STATIC void calcsize(union node *);
-STATIC void sizenodelist(struct nodelist *);
-STATIC union node *copynode(union node *);
-STATIC struct nodelist *copynodelist(struct nodelist *);
-STATIC char *nodesavestr(char *);
-
-
-
-/*
- * Make a copy of a parse tree.
- */
-
-union node *
-copyfunc(n)
-	union node *n;
-{
-	if (n == NULL)
-		return NULL;
-	funcblocksize = 0;
-	funcstringsize = 0;
-	calcsize(n);
-	funcblock = ckmalloc(funcblocksize + funcstringsize);
-	funcstring = (char *) funcblock + funcblocksize;
-	return copynode(n);
-}
-
-
-
-STATIC void
-calcsize(n)
-	union node *n;
-{
-      if (n == NULL)
-	    return;
-      funcblocksize += nodesize[n->type];
-      switch (n->type) {
-      case NSEMI:
-      case NAND:
-      case NOR:
-      case NWHILE:
-      case NUNTIL:
-	    calcsize(n->nbinary.ch2);
-	    calcsize(n->nbinary.ch1);
-	    break;
-      case NCMD:
-	    calcsize(n->ncmd.redirect);
-	    calcsize(n->ncmd.args);
-	    break;
-      case NPIPE:
-	    sizenodelist(n->npipe.cmdlist);
-	    break;
-      case NREDIR:
-      case NBACKGND:
-      case NSUBSHELL:
-	    calcsize(n->nredir.redirect);
-	    calcsize(n->nredir.n);
-	    break;
-      case NIF:
-	    calcsize(n->nif.elsepart);
-	    calcsize(n->nif.ifpart);
-	    calcsize(n->nif.test);
-	    break;
-      case NFOR:
-	    funcstringsize += strlen(n->nfor.var) + 1;
-	    calcsize(n->nfor.body);
-	    calcsize(n->nfor.args);
-	    break;
-      case NCASE:
-	    calcsize(n->ncase.cases);
-	    calcsize(n->ncase.expr);
-	    break;
-      case NCLIST:
-	    calcsize(n->nclist.body);
-	    calcsize(n->nclist.pattern);
-	    calcsize(n->nclist.next);
-	    break;
-      case NDEFUN:
-      case NARG:
-	    sizenodelist(n->narg.backquote);
-	    funcstringsize += strlen(n->narg.text) + 1;
-	    calcsize(n->narg.next);
-	    break;
-      case NTO:
-      case NCLOBBER:
-      case NFROM:
-      case NFROMTO:
-      case NAPPEND:
-	    calcsize(n->nfile.fname);
-	    calcsize(n->nfile.next);
-	    break;
-      case NTOFD:
-      case NFROMFD:
-	    calcsize(n->ndup.vname);
-	    calcsize(n->ndup.next);
-	    break;
-      case NHERE:
-      case NXHERE:
-	    calcsize(n->nhere.doc);
-	    calcsize(n->nhere.next);
-	    break;
-      case NNOT:
-	    calcsize(n->nnot.com);
-	    break;
-      };
-}
-
-
-
-STATIC void
-sizenodelist(lp)
-	struct nodelist *lp;
-{
-	while (lp) {
-		funcblocksize += SHELL_ALIGN(sizeof(struct nodelist));
-		calcsize(lp->n);
-		lp = lp->next;
-	}
-}
-
-
-
-STATIC union node *
-copynode(n)
-	union node *n;
-{
-	union node *new;
-
-      if (n == NULL)
-	    return NULL;
-      new = funcblock;
-      funcblock = (char *) funcblock + nodesize[n->type];
-      switch (n->type) {
-      case NSEMI:
-      case NAND:
-      case NOR:
-      case NWHILE:
-      case NUNTIL:
-	    new->nbinary.ch2 = copynode(n->nbinary.ch2);
-	    new->nbinary.ch1 = copynode(n->nbinary.ch1);
-	    break;
-      case NCMD:
-	    new->ncmd.redirect = copynode(n->ncmd.redirect);
-	    new->ncmd.args = copynode(n->ncmd.args);
-	    new->ncmd.backgnd = n->ncmd.backgnd;
-	    break;
-      case NPIPE:
-	    new->npipe.cmdlist = copynodelist(n->npipe.cmdlist);
-	    new->npipe.backgnd = n->npipe.backgnd;
-	    break;
-      case NREDIR:
-      case NBACKGND:
-      case NSUBSHELL:
-	    new->nredir.redirect = copynode(n->nredir.redirect);
-	    new->nredir.n = copynode(n->nredir.n);
-	    break;
-      case NIF:
-	    new->nif.elsepart = copynode(n->nif.elsepart);
-	    new->nif.ifpart = copynode(n->nif.ifpart);
-	    new->nif.test = copynode(n->nif.test);
-	    break;
-      case NFOR:
-	    new->nfor.var = nodesavestr(n->nfor.var);
-	    new->nfor.body = copynode(n->nfor.body);
-	    new->nfor.args = copynode(n->nfor.args);
-	    break;
-      case NCASE:
-	    new->ncase.cases = copynode(n->ncase.cases);
-	    new->ncase.expr = copynode(n->ncase.expr);
-	    break;
-      case NCLIST:
-	    new->nclist.body = copynode(n->nclist.body);
-	    new->nclist.pattern = copynode(n->nclist.pattern);
-	    new->nclist.next = copynode(n->nclist.next);
-	    break;
-      case NDEFUN:
-      case NARG:
-	    new->narg.backquote = copynodelist(n->narg.backquote);
-	    new->narg.text = nodesavestr(n->narg.text);
-	    new->narg.next = copynode(n->narg.next);
-	    break;
-      case NTO:
-      case NCLOBBER:
-      case NFROM:
-      case NFROMTO:
-      case NAPPEND:
-	    new->nfile.fname = copynode(n->nfile.fname);
-	    new->nfile.fd = n->nfile.fd;
-	    new->nfile.next = copynode(n->nfile.next);
-	    break;
-      case NTOFD:
-      case NFROMFD:
-	    new->ndup.vname = copynode(n->ndup.vname);
-	    new->ndup.dupfd = n->ndup.dupfd;
-	    new->ndup.fd = n->ndup.fd;
-	    new->ndup.next = copynode(n->ndup.next);
-	    break;
-      case NHERE:
-      case NXHERE:
-	    new->nhere.doc = copynode(n->nhere.doc);
-	    new->nhere.fd = n->nhere.fd;
-	    new->nhere.next = copynode(n->nhere.next);
-	    break;
-      case NNOT:
-	    new->nnot.com = copynode(n->nnot.com);
-	    break;
-      };
-      new->type = n->type;
-	return new;
-}
-
-
-STATIC struct nodelist *
-copynodelist(lp)
-	struct nodelist *lp;
-{
-	struct nodelist *start;
-	struct nodelist **lpp;
-
-	lpp = &start;
-	while (lp) {
-		*lpp = funcblock;
-		funcblock = (char *) funcblock +
-		    SHELL_ALIGN(sizeof(struct nodelist));
-		(*lpp)->n = copynode(lp->n);
-		lp = lp->next;
-		lpp = &(*lpp)->next;
-	}
-	*lpp = NULL;
-	return start;
-}
-
-
-
-STATIC char *
-nodesavestr(s)
-	char   *s;
-{
-	register char *p = s;
-	register char *q = funcstring;
-	char   *rtn = funcstring;
-
-	while ((*q++ = *p++) != 0)
-		continue;
-	funcstring = q;
-	return rtn;
-}
-
-
-
-/*
- * Free a parse tree.
- */
-
-void
-freefunc(n)
-	union node *n;
-{
-	if (n)
-		ckfree(n);
-}
diff --git a/src/ash/generated/nodes.h b/src/ash/generated/nodes.h
deleted file mode 100644
index aa750ed..0000000
--- a/src/ash/generated/nodes.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * This file was generated by mknodes.sh
- */
-
-#define NSEMI 0
-#define NCMD 1
-#define NPIPE 2
-#define NREDIR 3
-#define NBACKGND 4
-#define NSUBSHELL 5
-#define NAND 6
-#define NOR 7
-#define NIF 8
-#define NWHILE 9
-#define NUNTIL 10
-#define NFOR 11
-#define NCASE 12
-#define NCLIST 13
-#define NDEFUN 14
-#define NARG 15
-#define NTO 16
-#define NCLOBBER 17
-#define NFROM 18
-#define NFROMTO 19
-#define NAPPEND 20
-#define NTOFD 21
-#define NFROMFD 22
-#define NHERE 23
-#define NXHERE 24
-#define NNOT 25
-
-
-
-struct nbinary {
-      int type;
-      union node *ch1;
-      union node *ch2;
-};
-
-
-struct ncmd {
-      int type;
-      int backgnd;
-      union node *args;
-      union node *redirect;
-};
-
-
-struct npipe {
-      int type;
-      int backgnd;
-      struct nodelist *cmdlist;
-};
-
-
-struct nredir {
-      int type;
-      union node *n;
-      union node *redirect;
-};
-
-
-struct nif {
-      int type;
-      union node *test;
-      union node *ifpart;
-      union node *elsepart;
-};
-
-
-struct nfor {
-      int type;
-      union node *args;
-      union node *body;
-      char *var;
-};
-
-
-struct ncase {
-      int type;
-      union node *expr;
-      union node *cases;
-};
-
-
-struct nclist {
-      int type;
-      union node *next;
-      union node *pattern;
-      union node *body;
-};
-
-
-struct narg {
-      int type;
-      union node *next;
-      char *text;
-      struct nodelist *backquote;
-};
-
-
-struct nfile {
-      int type;
-      union node *next;
-      int fd;
-      union node *fname;
-      char *expfname;
-};
-
-
-struct ndup {
-      int type;
-      union node *next;
-      int fd;
-      int dupfd;
-      union node *vname;
-};
-
-
-struct nhere {
-      int type;
-      union node *next;
-      int fd;
-      union node *doc;
-};
-
-
-struct nnot {
-      int type;
-      union node *com;
-};
-
-
-union node {
-      int type;
-      struct nbinary nbinary;
-      struct ncmd ncmd;
-      struct npipe npipe;
-      struct nredir nredir;
-      struct nif nif;
-      struct nfor nfor;
-      struct ncase ncase;
-      struct nclist nclist;
-      struct narg narg;
-      struct nfile nfile;
-      struct ndup ndup;
-      struct nhere nhere;
-      struct nnot nnot;
-};
-
-
-struct nodelist {
-	struct nodelist *next;
-	union node *n;
-};
-
-
-union node *copyfunc(union node *);
-void freefunc(union node *);
diff --git a/src/ash/generated/token.h b/src/ash/generated/token.h
deleted file mode 100644
index c961f01..0000000
--- a/src/ash/generated/token.h
+++ /dev/null
@@ -1,112 +0,0 @@
-#define TEOF 0
-#define TNL 1
-#define TSEMI 2
-#define TBACKGND 3
-#define TAND 4
-#define TOR 5
-#define TPIPE 6
-#define TLP 7
-#define TRP 8
-#define TENDCASE 9
-#define TENDBQUOTE 10
-#define TREDIR 11
-#define TWORD 12
-#define TIF 13
-#define TTHEN 14
-#define TELSE 15
-#define TELIF 16
-#define TFI 17
-#define TWHILE 18
-#define TUNTIL 19
-#define TFOR 20
-#define TDO 21
-#define TDONE 22
-#define TBEGIN 23
-#define TEND 24
-#define TCASE 25
-#define TESAC 26
-#define TNOT 27
-
-/* Array indicating which tokens mark the end of a list */
-const char tokendlist[] = {
-	1,
-	0,
-	0,
-	0,
-	0,
-	0,
-	0,
-	0,
-	1,
-	1,
-	1,
-	0,
-	0,
-	0,
-	1,
-	1,
-	1,
-	1,
-	0,
-	0,
-	0,
-	1,
-	1,
-	0,
-	1,
-	0,
-	1,
-	0,
-};
-
-const char *const tokname[] = {
-	"end of file",
-	"newline",
-	"\";\"",
-	"\"&\"",
-	"\"&&\"",
-	"\"||\"",
-	"\"|\"",
-	"\"(\"",
-	"\")\"",
-	"\";;\"",
-	"\"`\"",
-	"redirection",
-	"word",
-	"\"if\"",
-	"\"then\"",
-	"\"else\"",
-	"\"elif\"",
-	"\"fi\"",
-	"\"while\"",
-	"\"until\"",
-	"\"for\"",
-	"\"do\"",
-	"\"done\"",
-	"\"{\"",
-	"\"}\"",
-	"\"case\"",
-	"\"esac\"",
-	"\"!\"",
-};
-
-#define KWDOFFSET 13
-
-const char *const parsekwd[] = {
-	"if",
-	"then",
-	"else",
-	"elif",
-	"fi",
-	"while",
-	"until",
-	"for",
-	"do",
-	"done",
-	"{",
-	"}",
-	"case",
-	"esac",
-	"!",
-	0
-};
diff --git a/src/ash/histedit.c b/src/ash/histedit.c
deleted file mode 100644
index 7fa512d..0000000
--- a/src/ash/histedit.c
+++ /dev/null
@@ -1,550 +0,0 @@
-/*	$NetBSD: histedit.c,v 1.36 2005/05/09 11:35:19 christos Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)histedit.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: histedit.c,v 1.36 2005/05/09 11:35:19 christos Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-#ifndef __sun__
-#include <paths.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-/*
- * Editline and history functions (and glue).
- */
-#include "shell.h"
-#include "parser.h"
-#include "var.h"
-#include "options.h"
-#include "main.h"
-#include "output.h"
-#include "mystring.h"
-#include "myhistedit.h"
-#include "error.h"
-#ifndef SMALL
-#include "eval.h"
-#include "memalloc.h"
-
-#define MAXHISTLOOPS	4	/* max recursions through fc */
-#define DEFEDITOR	"ed"	/* default editor *should* be $EDITOR */
-
-History *hist;	/* history cookie */
-EditLine *el;	/* editline cookie */
-int displayhist;
-static FILE *el_in, *el_out;
-unsigned char _el_fn_complete(EditLine *, int);
-
-STATIC const char *fc_replace(const char *, char *, char *);
-
-#ifdef DEBUG
-extern FILE *tracefile;
-#endif
-
-/*
- * Set history and editing status.  Called whenever the status may
- * have changed (figures out what to do).
- */
-void
-histedit(void)
-{
-	FILE *el_err;
-
-#define editing (Eflag || Vflag)
-
-	if (iflag) {
-		if (!hist) {
-			/*
-			 * turn history on
-			 */
-			INTOFF;
-			hist = history_init();
-			INTON;
-
-			if (hist != NULL)
-				sethistsize(histsizeval());
-			else
-				out2str("sh: can't initialize history\n");
-		}
-		if (editing && !el && isatty(0)) { /* && isatty(2) ??? */
-			/*
-			 * turn editing on
-			 */
-			char *term, *shname;
-
-			INTOFF;
-			if (el_in == NULL)
-				el_in = fdopen(0, "r");
-			if (el_out == NULL)
-				el_out = fdopen(2, "w");
-			if (el_in == NULL || el_out == NULL)
-				goto bad;
-			el_err = el_out;
-#if DEBUG
-			if (tracefile)
-				el_err = tracefile;
-#endif
-			term = lookupvar("TERM");
-			if (term)
-				setenv("TERM", term, 1);
-			else
-				unsetenv("TERM");
-			shname = arg0;
-			if (shname[0] == '-')
-				shname++;
-			el = el_init(shname, el_in, el_out, el_err);
-			if (el != NULL) {
-				if (hist)
-					el_set(el, EL_HIST, history, hist);
-				el_set(el, EL_PROMPT, getprompt);
-				el_set(el, EL_SIGNAL, 1);
-				el_set(el, EL_ADDFN, "rl-complete",
-				    "ReadLine compatible completion function",
-				    _el_fn_complete);
-			} else {
-bad:
-				out2str("sh: can't initialize editing\n");
-			}
-			INTON;
-		} else if (!editing && el) {
-			INTOFF;
-			el_end(el);
-			el = NULL;
-			INTON;
-		}
-		if (el) {
-			if (Vflag)
-				el_set(el, EL_EDITOR, "vi");
-			else if (Eflag)
-				el_set(el, EL_EDITOR, "emacs");
-			el_set(el, EL_BIND, "^I",
-			    tabcomplete ? "rl-complete" : "ed-insert", NULL);
-			el_source(el, NULL);
-		}
-	} else {
-		INTOFF;
-		if (el) {	/* no editing if not interactive */
-			el_end(el);
-			el = NULL;
-		}
-		if (hist) {
-			history_end(hist);
-			hist = NULL;
-		}
-		INTON;
-	}
-}
-
-
-void
-sethistsize(const char *hs)
-{
-	int histsize;
-	HistEvent he;
-
-	if (hist != NULL) {
-		if (hs == NULL || *hs == '\0' ||
-		   (histsize = atoi(hs)) < 0)
-			histsize = 100;
-		history(hist, &he, H_SETSIZE, histsize);
-	}
-}
-
-void
-setterm(const char *term)
-{
-	if (el != NULL && term != NULL)
-		if (el_set(el, EL_TERMINAL, term) != 0) {
-			outfmt(out2, "sh: Can't set terminal type %s\n", term);
-			outfmt(out2, "sh: Using dumb terminal settings.\n");
-		}
-}
-
-int
-inputrc(argc, argv)
-	int argc;
-	char **argv;
-{
-	if (argc != 2) {
-		out2str("usage: inputrc file\n");
-		return 1;
-	}
-	if (el != NULL) {
-		if (el_source(el, argv[1])) {
-			out2str("inputrc: failed\n");
-			return 1;
-		} else
-			return 0;
-	} else {
-		out2str("sh: inputrc ignored, not editing\n");
-		return 1;
-	}
-}
-
-/*
- *  This command is provided since POSIX decided to standardize
- *  the Korn shell fc command.  Oh well...
- */
-int
-histcmd(int argc, char **argv)
-{
-	int ch;
-	const char *editor = NULL;
-	HistEvent he;
-	int lflg = 0, nflg = 0, rflg = 0, sflg = 0;
-	int i, retval;
-	const char *firststr, *laststr;
-	int first, last, direction;
-	char *pat = NULL, *repl;	/* ksh "fc old=new" crap */
-	static int active = 0;
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-	char editfile[MAXPATHLEN + 1];
-	FILE *efp;
-#ifdef __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &editor;
-	(void) &lflg;
-	(void) &nflg;
-	(void) &rflg;
-	(void) &sflg;
-	(void) &firststr;
-	(void) &laststr;
-	(void) &pat;
-	(void) &repl;
-	(void) &efp;
-	(void) &argc;
-	(void) &argv;
-#endif
-
-	if (hist == NULL)
-		error("history not active");
-
-	if (argc == 1)
-		error("missing history argument");
-
-	optreset = 1; optind = 1; /* initialize getopt */
-	while (not_fcnumber(argv[optind]) &&
-	      (ch = getopt(argc, argv, ":e:lnrs")) != -1)
-		switch ((char)ch) {
-		case 'e':
-			editor = optionarg;
-			break;
-		case 'l':
-			lflg = 1;
-			break;
-		case 'n':
-			nflg = 1;
-			break;
-		case 'r':
-			rflg = 1;
-			break;
-		case 's':
-			sflg = 1;
-			break;
-		case ':':
-			error("option -%c expects argument", optopt);
-			/* NOTREACHED */
-		case '?':
-		default:
-			error("unknown option: -%c", optopt);
-			/* NOTREACHED */
-		}
-	argc -= optind, argv += optind;
-
-	/*
-	 * If executing...
-	 */
-	if (lflg == 0 || editor || sflg) {
-		lflg = 0;	/* ignore */
-		editfile[0] = '\0';
-		/*
-		 * Catch interrupts to reset active counter and
-		 * cleanup temp files.
-		 */
-		if (setjmp(jmploc.loc)) {
-			active = 0;
-			if (*editfile)
-				unlink(editfile);
-			handler = savehandler;
-			longjmp(handler->loc, 1);
-		}
-		savehandler = handler;
-		handler = &jmploc;
-		if (++active > MAXHISTLOOPS) {
-			active = 0;
-			displayhist = 0;
-			error("called recursively too many times");
-		}
-		/*
-		 * Set editor.
-		 */
-		if (sflg == 0) {
-			if (editor == NULL &&
-			    (editor = bltinlookup("FCEDIT", 1)) == NULL &&
-			    (editor = bltinlookup("EDITOR", 1)) == NULL)
-				editor = DEFEDITOR;
-			if (editor[0] == '-' && editor[1] == '\0') {
-				sflg = 1;	/* no edit */
-				editor = NULL;
-			}
-		}
-	}
-
-	/*
-	 * If executing, parse [old=new] now
-	 */
-	if (lflg == 0 && argc > 0 &&
-	     ((repl = strchr(argv[0], '=')) != NULL)) {
-		pat = argv[0];
-		*repl++ = '\0';
-		argc--, argv++;
-	}
-	/*
-	 * determine [first] and [last]
-	 */
-	switch (argc) {
-	case 0:
-		firststr = lflg ? "-16" : "-1";
-		laststr = "-1";
-		break;
-	case 1:
-		firststr = argv[0];
-		laststr = lflg ? "-1" : argv[0];
-		break;
-	case 2:
-		firststr = argv[0];
-		laststr = argv[1];
-		break;
-	default:
-		error("too many args");
-		/* NOTREACHED */
-	}
-	/*
-	 * Turn into event numbers.
-	 */
-	first = str_to_event(firststr, 0);
-	last = str_to_event(laststr, 1);
-
-	if (rflg) {
-		i = last;
-		last = first;
-		first = i;
-	}
-	/*
-	 * XXX - this should not depend on the event numbers
-	 * always increasing.  Add sequence numbers or offset
-	 * to the history element in next (diskbased) release.
-	 */
-	direction = first < last ? H_PREV : H_NEXT;
-
-	/*
-	 * If editing, grab a temp file.
-	 */
-	if (editor) {
-		int fd;
-		INTOFF;		/* easier */
-		snprintf(editfile, sizeof(editfile), "%s_shXXXXXX", _PATH_TMP);
-		if ((fd = mkstemp(editfile)) < 0)
-			error("can't create temporary file %s", editfile);
-		if ((efp = fdopen(fd, "w")) == NULL) {
-			close(fd);
-			error("can't allocate stdio buffer for temp");
-		}
-	}
-
-	/*
-	 * Loop through selected history events.  If listing or executing,
-	 * do it now.  Otherwise, put into temp file and call the editor
-	 * after.
-	 *
-	 * The history interface needs rethinking, as the following
-	 * convolutions will demonstrate.
-	 */
-	history(hist, &he, H_FIRST);
-	retval = history(hist, &he, H_NEXT_EVENT, first);
-	for (;retval != -1; retval = history(hist, &he, direction)) {
-		if (lflg) {
-			if (!nflg)
-				out1fmt("%5d ", he.num);
-			out1str(he.str);
-		} else {
-			const char *s = pat ?
-			   fc_replace(he.str, pat, repl) : he.str;
-
-			if (sflg) {
-				if (displayhist) {
-					out2str(s);
-				}
-
-				evalstring(strcpy(stalloc(strlen(s) + 1), s), 0);
-				if (displayhist && hist) {
-					/*
-					 *  XXX what about recursive and
-					 *  relative histnums.
-					 */
-					history(hist, &he, H_ENTER, s);
-				}
-			} else
-				fputs(s, efp);
-		}
-		/*
-		 * At end?  (if we were to lose last, we'd sure be
-		 * messed up).
-		 */
-		if (he.num == last)
-			break;
-	}
-	if (editor) {
-		char *editcmd;
-
-		fclose(efp);
-		editcmd = stalloc(strlen(editor) + strlen(editfile) + 2);
-		sprintf(editcmd, "%s %s", editor, editfile);
-		evalstring(editcmd, 0);	/* XXX - should use no JC command */
-		INTON;
-		readcmdfile(editfile);	/* XXX - should read back - quick tst */
-		unlink(editfile);
-	}
-
-	if (lflg == 0 && active > 0)
-		--active;
-	if (displayhist)
-		displayhist = 0;
-	return 0;
-}
-
-STATIC const char *
-fc_replace(const char *s, char *p, char *r)
-{
-	char *dest;
-	int plen = strlen(p);
-
-	STARTSTACKSTR(dest);
-	while (*s) {
-		if (*s == *p && strncmp(s, p, plen) == 0) {
-			while (*r)
-				STPUTC(*r++, dest);
-			s += plen;
-			*p = '\0';	/* so no more matches */
-		} else
-			STPUTC(*s++, dest);
-	}
-	STACKSTRNUL(dest);
-	dest = grabstackstr(dest);
-
-	return (dest);
-}
-
-int
-not_fcnumber(char *s)
-{
-	if (s == NULL)
-		return 0;
-        if (*s == '-')
-                s++;
-	return (!is_number(s));
-}
-
-int
-str_to_event(const char *str, int last)
-{
-	HistEvent he;
-	const char *s = str;
-	int relative = 0;
-	int i, retval;
-
-	retval = history(hist, &he, H_FIRST);
-	switch (*s) {
-	case '-':
-		relative = 1;
-		/*FALLTHROUGH*/
-	case '+':
-		s++;
-	}
-	if (is_number(s)) {
-		i = atoi(s);
-		if (relative) {
-			while (retval != -1 && i--) {
-				retval = history(hist, &he, H_NEXT);
-			}
-			if (retval == -1)
-				retval = history(hist, &he, H_LAST);
-		} else {
-			retval = history(hist, &he, H_NEXT_EVENT, i);
-			if (retval == -1) {
-				/*
-				 * the notion of first and last is
-				 * backwards to that of the history package
-				 */
-				retval = history(hist, &he,
-						last ? H_FIRST : H_LAST);
-			}
-		}
-		if (retval == -1)
-			error("history number %s not found (internal error)",
-			       str);
-	} else {
-		/*
-		 * pattern
-		 */
-		retval = history(hist, &he, H_PREV_STR, str);
-		if (retval == -1)
-			error("history pattern not found: %s", str);
-	}
-	return (he.num);
-}
-#else
-int
-histcmd(int argc, char **argv)
-{
-	error("not compiled with history support");
-	/* NOTREACHED */
-}
-int
-inputrc(int argc, char **argv)
-{
-	error("not compiled with history support");
-	/* NOTREACHED */
-}
-#endif
diff --git a/src/ash/init.h b/src/ash/init.h
deleted file mode 100644
index 60d924e..0000000
--- a/src/ash/init.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*	$NetBSD: init.h,v 1.10 2003/08/07 09:05:32 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)init.h	8.2 (Berkeley) 5/4/95
- */
-
-void init(void);
-void reset(void);
-void initshellproc(void);
diff --git a/src/ash/input.c b/src/ash/input.c
deleted file mode 100644
index a231f4d..0000000
--- a/src/ash/input.c
+++ /dev/null
@@ -1,536 +0,0 @@
-/*	$NetBSD: input.c,v 1.39 2003/08/07 09:05:32 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)input.c	8.3 (Berkeley) 6/9/95";
-#else
-__RCSID("$NetBSD: input.c,v 1.39 2003/08/07 09:05:32 agc Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdio.h>	/* defines BUFSIZ */
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef __sun__
-#include <iso/limits_iso.h>
-#endif
-
-/*
- * This file implements the input routines used by the parser.
- */
-
-#include "shell.h"
-#include "redir.h"
-#include "syntax.h"
-#include "input.h"
-#include "output.h"
-#include "options.h"
-#include "memalloc.h"
-#include "error.h"
-#include "alias.h"
-#include "parser.h"
-#include "myhistedit.h"
-
-#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
-
-MKINIT
-struct strpush {
-	struct strpush *prev;	/* preceding string on stack */
-	char *prevstring;
-	int prevnleft;
-	int prevlleft;
-	struct alias *ap;	/* if push was associated with an alias */
-};
-
-/*
- * The parsefile structure pointed to by the global variable parsefile
- * contains information about the current file being read.
- */
-
-MKINIT
-struct parsefile {
-	struct parsefile *prev;	/* preceding file on stack */
-	int linno;		/* current line */
-	int fd;			/* file descriptor (or -1 if string) */
-	int nleft;		/* number of chars left in this line */
-	int lleft;		/* number of chars left in this buffer */
-	char *nextc;		/* next char in buffer */
-	char *buf;		/* input buffer */
-	struct strpush *strpush; /* for pushing strings at this level */
-	struct strpush basestrpush; /* so pushing one is fast */
-};
-
-
-int plinno = 1;			/* input line number */
-int parsenleft;			/* copy of parsefile->nleft */
-MKINIT int parselleft;		/* copy of parsefile->lleft */
-char *parsenextc;		/* copy of parsefile->nextc */
-MKINIT struct parsefile basepf;	/* top level input file */
-MKINIT char basebuf[BUFSIZ];	/* buffer for top level input file */
-struct parsefile *parsefile = &basepf;	/* current input file */
-int init_editline = 0;		/* editline library initialized? */
-int whichprompt;		/* 1 == PS1, 2 == PS2 */
-
-#ifndef SMALL
-EditLine *el;			/* cookie for editline package */
-#endif
-
-STATIC void pushfile(void);
-static int preadfd(void);
-
-#ifdef mkinit
-INCLUDE <stdio.h>
-INCLUDE "input.h"
-INCLUDE "error.h"
-
-INIT {
-	basepf.nextc = basepf.buf = basebuf;
-}
-
-RESET {
-	if (exception != EXSHELLPROC)
-		parselleft = parsenleft = 0;	/* clear input buffer */
-	popallfiles();
-}
-
-SHELLPROC {
-	popallfiles();
-}
-#endif
-
-
-/*
- * Read a line from the script.
- */
-
-char *
-pfgets(char *line, int len)
-{
-	char *p = line;
-	int nleft = len;
-	int c;
-
-	while (--nleft > 0) {
-		c = pgetc_macro();
-		if (c == PEOF) {
-			if (p == line)
-				return NULL;
-			break;
-		}
-		*p++ = c;
-		if (c == '\n')
-			break;
-	}
-	*p = '\0';
-	return line;
-}
-
-
-
-/*
- * Read a character from the script, returning PEOF on end of file.
- * Nul characters in the input are silently discarded.
- */
-
-int
-pgetc(void)
-{
-	return pgetc_macro();
-}
-
-
-static int
-preadfd(void)
-{
-	int nr;
-	char *buf =  parsefile->buf;
-	parsenextc = buf;
-
-retry:
-#ifndef SMALL
-	if (parsefile->fd == 0 && el) {
-		static const char *rl_cp;
-		static int el_len;
-
-		if (rl_cp == NULL)
-			rl_cp = el_gets(el, &el_len);
-		if (rl_cp == NULL)
-			nr = 0;
-		else {
-			nr = el_len;
-			if (nr > BUFSIZ - 8)
-				nr = BUFSIZ - 8;
-			memcpy(buf, rl_cp, nr);
-			if (nr != el_len) {
-				el_len -= nr;
-				rl_cp += nr;
-			} else
-				rl_cp = 0;
-		}
-
-	} else
-#endif
-		nr = read(parsefile->fd, buf, BUFSIZ - 8);
-
-
-	if (nr <= 0) {
-                if (nr < 0) {
-                        if (errno == EINTR)
-                                goto retry;
-                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
-                                int flags = fcntl(0, F_GETFL, 0);
-                                if (flags >= 0 && flags & O_NONBLOCK) {
-                                        flags &=~ O_NONBLOCK;
-                                        if (fcntl(0, F_SETFL, flags) >= 0) {
-						out2str("sh: turning off NDELAY mode\n");
-                                                goto retry;
-                                        }
-                                }
-                        }
-                }
-                nr = -1;
-	}
-	return nr;
-}
-
-/*
- * Refill the input buffer and return the next input character:
- *
- * 1) If a string was pushed back on the input, pop it;
- * 2) If an EOF was pushed back (parsenleft == EOF_NLEFT) or we are reading
- *    from a string so we can't refill the buffer, return EOF.
- * 3) If the is more stuff in this buffer, use it else call read to fill it.
- * 4) Process input up to the next newline, deleting nul characters.
- */
-
-int
-preadbuffer(void)
-{
-	char *p, *q;
-	int more;
-	int something;
-	char savec;
-
-	if (parsefile->strpush) {
-		popstring();
-		if (--parsenleft >= 0)
-			return (*parsenextc++);
-	}
-	if (parsenleft == EOF_NLEFT || parsefile->buf == NULL)
-		return PEOF;
-	flushout(&output);
-	flushout(&errout);
-
-again:
-	if (parselleft <= 0) {
-		if ((parselleft = preadfd()) == -1) {
-			parselleft = parsenleft = EOF_NLEFT;
-			return PEOF;
-		}
-	}
-
-	q = p = parsenextc;
-
-	/* delete nul characters */
-	something = 0;
-	for (more = 1; more;) {
-		switch (*p) {
-		case '\0':
-			p++;	/* Skip nul */
-			goto check;
-
-		case '\t':
-		case ' ':
-			break;
-
-		case '\n':
-			parsenleft = q - parsenextc;
-			more = 0; /* Stop processing here */
-			break;
-
-		default:
-			something = 1;
-			break;
-		}
-
-		*q++ = *p++;
-check:
-		if (--parselleft <= 0) {
-			parsenleft = q - parsenextc - 1;
-			if (parsenleft < 0)
-				goto again;
-			*q = '\0';
-			more = 0;
-		}
-	}
-
-	savec = *q;
-	*q = '\0';
-
-#ifndef SMALL
-	if (parsefile->fd == 0 && hist && something) {
-		HistEvent he;
-		INTOFF;
-		history(hist, &he, whichprompt == 1? H_ENTER : H_APPEND,
-		    parsenextc);
-		INTON;
-	}
-#endif
-
-	if (vflag) {
-		out2str(parsenextc);
-		flushout(out2);
-	}
-
-	*q = savec;
-
-	return *parsenextc++;
-}
-
-/*
- * Undo the last call to pgetc.  Only one character may be pushed back.
- * PEOF may be pushed back.
- */
-
-void
-pungetc(void)
-{
-	parsenleft++;
-	parsenextc--;
-}
-
-/*
- * Push a string back onto the input at this current parsefile level.
- * We handle aliases this way.
- */
-void
-pushstring(char *s, int len, void *ap)
-{
-	struct strpush *sp;
-
-	INTOFF;
-/*dprintf("*** calling pushstring: %s, %d\n", s, len);*/
-	if (parsefile->strpush) {
-		sp = ckmalloc(sizeof (struct strpush));
-		sp->prev = parsefile->strpush;
-		parsefile->strpush = sp;
-	} else
-		sp = parsefile->strpush = &(parsefile->basestrpush);
-	sp->prevstring = parsenextc;
-	sp->prevnleft = parsenleft;
-	sp->prevlleft = parselleft;
-	sp->ap = (struct alias *)ap;
-	if (ap)
-		((struct alias *)ap)->flag |= ALIASINUSE;
-	parsenextc = s;
-	parsenleft = len;
-	INTON;
-}
-
-void
-popstring(void)
-{
-	struct strpush *sp = parsefile->strpush;
-
-	INTOFF;
-	parsenextc = sp->prevstring;
-	parsenleft = sp->prevnleft;
-	parselleft = sp->prevlleft;
-/*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/
-	if (sp->ap)
-		sp->ap->flag &= ~ALIASINUSE;
-	parsefile->strpush = sp->prev;
-	if (sp != &(parsefile->basestrpush))
-		ckfree(sp);
-	INTON;
-}
-
-/*
- * Set the input to take input from a file.  If push is set, push the
- * old input onto the stack first.
- */
-
-void
-setinputfile(const char *fname, int push)
-{
-	int fd;
-	int fd2;
-
-	INTOFF;
-	if ((fd = open(fname, O_RDONLY)) < 0)
-		error("Can't open %s", fname);
-	if (fd < 10) {
-		fd2 = copyfd(fd, 10);
-		close(fd);
-		if (fd2 < 0)
-			error("Out of file descriptors");
-		fd = fd2;
-	}
-	setinputfd(fd, push);
-	INTON;
-}
-
-
-/*
- * Like setinputfile, but takes an open file descriptor.  Call this with
- * interrupts off.
- */
-
-void
-setinputfd(int fd, int push)
-{
-	(void) fcntl(fd, F_SETFD, FD_CLOEXEC);
-	if (push) {
-		pushfile();
-		parsefile->buf = ckmalloc(BUFSIZ);
-	}
-	if (parsefile->fd > 0)
-		close(parsefile->fd);
-	parsefile->fd = fd;
-	if (parsefile->buf == NULL)
-		parsefile->buf = ckmalloc(BUFSIZ);
-	parselleft = parsenleft = 0;
-	plinno = 1;
-}
-
-
-/*
- * Like setinputfile, but takes input from a string.
- */
-
-void
-setinputstring(char *string, int push)
-{
-	INTOFF;
-	if (push)
-		pushfile();
-	parsenextc = string;
-	parselleft = parsenleft = strlen(string);
-	parsefile->buf = NULL;
-	plinno = 1;
-	INTON;
-}
-
-
-
-/*
- * To handle the "." command, a stack of input files is used.  Pushfile
- * adds a new entry to the stack and popfile restores the previous level.
- */
-
-STATIC void
-pushfile(void)
-{
-	struct parsefile *pf;
-
-	parsefile->nleft = parsenleft;
-	parsefile->lleft = parselleft;
-	parsefile->nextc = parsenextc;
-	parsefile->linno = plinno;
-	pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile));
-	pf->prev = parsefile;
-	pf->fd = -1;
-	pf->strpush = NULL;
-	pf->basestrpush.prev = NULL;
-	parsefile = pf;
-}
-
-
-void
-popfile(void)
-{
-	struct parsefile *pf = parsefile;
-
-	INTOFF;
-	if (pf->fd >= 0)
-		close(pf->fd);
-	if (pf->buf)
-		ckfree(pf->buf);
-	while (pf->strpush)
-		popstring();
-	parsefile = pf->prev;
-	ckfree(pf);
-	parsenleft = parsefile->nleft;
-	parselleft = parsefile->lleft;
-	parsenextc = parsefile->nextc;
-	plinno = parsefile->linno;
-	INTON;
-}
-
-
-/*
- * Return to top level.
- */
-
-void
-popallfiles(void)
-{
-	while (parsefile != &basepf)
-		popfile();
-}
-
-
-
-/*
- * Close the file(s) that the shell is reading commands from.  Called
- * after a fork is done.
- *
- * Takes one arg, vfork, which tells it to not modify its global vars
- * as it is still running in the parent.
- *
- * This code is (probably) unnecessary as the 'close on exec' flag is
- * set and should be enough.  In the vfork case it is definitely wrong
- * to close the fds as another fork() may be done later to feed data
- * from a 'here' document into a pipe and we don't want to close the
- * pipe!
- */
-
-void
-closescript(int vforked)
-{
-	if (vforked)
-		return;
-	popallfiles();
-	if (parsefile->fd > 0) {
-		close(parsefile->fd);
-		parsefile->fd = 0;
-	}
-}
diff --git a/src/ash/input.h b/src/ash/input.h
deleted file mode 100644
index a9d3a12..0000000
--- a/src/ash/input.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*	$NetBSD: input.h,v 1.15 2003/08/07 09:05:33 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)input.h	8.2 (Berkeley) 5/4/95
- */
-
-/* PEOF (the end of file marker) is defined in syntax.h */
-
-/*
- * The input line number.  Input.c just defines this variable, and saves
- * and restores it when files are pushed and popped.  The user of this
- * package must set its value.
- */
-extern int plinno;
-extern int parsenleft;		/* number of characters left in input buffer */
-extern char *parsenextc;	/* next character in input buffer */
-extern int init_editline;	/* 0 == not setup, 1 == OK, -1 == failed */
-
-char *pfgets(char *, int);
-int pgetc(void);
-int preadbuffer(void);
-void pungetc(void);
-void pushstring(char *, int, void *);
-void popstring(void);
-void setinputfile(const char *, int);
-void setinputfd(int, int);
-void setinputstring(char *, int);
-void popfile(void);
-void popallfiles(void);
-void closescript(int);
-
-#define pgetc_macro()	(--parsenleft >= 0? *parsenextc++ : preadbuffer())
diff --git a/src/ash/jobs.c b/src/ash/jobs.c
deleted file mode 100644
index 146326a..0000000
--- a/src/ash/jobs.c
+++ /dev/null
@@ -1,1484 +0,0 @@
-/*	$NetBSD: jobs.c,v 1.63 2005/06/01 15:41:19 lukem Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#else
-#define _PATH_DEVNULL "/dev/null"
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)jobs.c	8.5 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: jobs.c,v 1.63 2005/06/01 15:41:19 lukem Exp $");
-#endif
-#endif /* not lint */
-
-#include <fcntl.h>
-#ifdef __sun__
-#define sys_siglist _sys_siglist
-#endif
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#ifndef __sun__
-#include <paths.h>
-#endif
-#include <sys/types.h>
-#include <sys/param.h>
-#if defined(BSD) || defined(__sun__)
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
-#include <sys/ioctl.h>
-
-#include "shell.h"
-#if JOBS
-#if OLD_TTY_DRIVER
-#include "sgtty.h"
-#else
-#include <termios.h>
-#endif
-#undef CEOF			/* syntax.h redefines this */
-#endif
-#include "redir.h"
-#include "show.h"
-#include "main.h"
-#include "parser.h"
-#include "nodes.h"
-#include "jobs.h"
-#include "options.h"
-#include "trap.h"
-#include "syntax.h"
-#include "input.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-
-
-static struct job *jobtab;		/* array of jobs */
-static int njobs;			/* size of array */
-static int jobs_invalid;		/* set in child */
-MKINIT pid_t backgndpid = -1;	/* pid of last background process */
-#if JOBS
-int initialpgrp;		/* pgrp of shell on invocation */
-static int curjob = -1;		/* current job */
-#endif
-static int ttyfd = -1;
-
-STATIC void restartjob(struct job *);
-STATIC void freejob(struct job *);
-STATIC struct job *getjob(const char *, int);
-STATIC int dowait(int, struct job *);
-STATIC int onsigchild(void);
-STATIC int waitproc(int, struct job *, int *);
-STATIC void cmdtxt(union node *);
-STATIC void cmdlist(union node *, int);
-STATIC void cmdputs(const char *);
-
-#ifdef OLD_TTY_DRIVER
-static pid_t tcgetpgrp(int fd);
-static int tcsetpgrp(int fd, pid_t pgrp);
-
-static pid_t
-tcgetpgrp(int fd)
-{
-	pid_t pgrp;
-	if (ioctl(fd, TIOCGPGRP, (char *)&pgrp) == -1)
-		return -1;
-	else
-		return pgrp;
-}
-
-static int
-tcsetpgrp(int fd, pid_tpgrp)
-{
-	return ioctl(fd, TIOCSPGRP, (char *)&pgrp);
-}
-#endif
-
-/*
- * Turn job control on and off.
- *
- * Note:  This code assumes that the third arg to ioctl is a character
- * pointer, which is true on Berkeley systems but not System V.  Since
- * System V doesn't have job control yet, this isn't a problem now.
- */
-
-MKINIT int jobctl;
-
-void
-setjobctl(int on)
-{
-#ifdef OLD_TTY_DRIVER
-	int ldisc;
-#endif
-
-	if (on == jobctl || rootshell == 0)
-		return;
-	if (on) {
-#if defined(FIOCLEX) || defined(FD_CLOEXEC)
-		int err;
-		int i;
-		if (ttyfd != -1)
-			close(ttyfd);
-		if ((ttyfd = open("/dev/tty", O_RDWR)) == -1) {
-			for (i = 0; i < 3; i++) {
-				if (isatty(i) && (ttyfd = dup(i)) != -1)
-					break;
-			}
-			if (i == 3)
-				goto out;
-		}
-		/* Move to a high fd */
-		for (i = 10; i > 2; i--) {
-			if ((err = fcntl(ttyfd, F_DUPFD, (1 << i) - 1)) != -1)
-				break;
-		}
-		if (err != -1) {
-			close(ttyfd);
-			ttyfd = err;
-		}
-#ifdef FIOCLEX
-		err = ioctl(ttyfd, FIOCLEX, 0);
-#elif FD_CLOEXEC
-		err = fcntl(ttyfd, F_SETFD,
-		    fcntl(ttyfd, F_GETFD, 0) | FD_CLOEXEC);
-#endif
-		if (err == -1) {
-			close(ttyfd);
-			ttyfd = -1;
-			goto out;
-		}
-#else
-		out2str("sh: Need FIOCLEX or FD_CLOEXEC to support job control");
-		goto out;
-#endif
-		do { /* while we are in the background */
-			if ((initialpgrp = tcgetpgrp(ttyfd)) < 0) {
-out:
-				out2str("sh: can't access tty; job control turned off\n");
-				mflag = 0;
-				return;
-			}
-			if (initialpgrp == -1)
-				initialpgrp = getpgrp();
-			else if (initialpgrp != getpgrp()) {
-				killpg(0, SIGTTIN);
-				continue;
-			}
-		} while (0);
-
-#ifdef OLD_TTY_DRIVER
-		if (ioctl(ttyfd, TIOCGETD, (char *)&ldisc) < 0
-		    || ldisc != NTTYDISC) {
-			out2str("sh: need new tty driver to run job control; job control turned off\n");
-			mflag = 0;
-			return;
-		}
-#endif
-		setsignal(SIGTSTP, 0);
-		setsignal(SIGTTOU, 0);
-		setsignal(SIGTTIN, 0);
-		if (getpgid(0) != rootpid && setpgid(0, rootpid) == -1)
-			error("Cannot set process group (%s) at %d",
-			    strerror(errno), __LINE__);
-		if (tcsetpgrp(ttyfd, rootpid) == -1)
-			error("Cannot set tty process group (%s) at %d",
-			    strerror(errno), __LINE__);
-	} else { /* turning job control off */
-		if (getpgid(0) != initialpgrp && setpgid(0, initialpgrp) == -1)
-			error("Cannot set process group (%s) at %d",
-			    strerror(errno), __LINE__);
-		if (tcsetpgrp(ttyfd, initialpgrp) == -1)
-			error("Cannot set tty process group (%s) at %d",
-			    strerror(errno), __LINE__);
-		close(ttyfd);
-		ttyfd = -1;
-		setsignal(SIGTSTP, 0);
-		setsignal(SIGTTOU, 0);
-		setsignal(SIGTTIN, 0);
-	}
-	jobctl = on;
-}
-
-
-#ifdef mkinit
-INCLUDE <stdlib.h>
-
-SHELLPROC {
-	backgndpid = -1;
-#if JOBS
-	jobctl = 0;
-#endif
-}
-
-#endif
-
-
-
-#if JOBS
-int
-fgcmd(int argc, char **argv)
-{
-	struct job *jp;
-	int i;
-	int status;
-
-	nextopt("");
-	jp = getjob(*argptr, 0);
-	if (jp->jobctl == 0)
-		error("job not created under job control");
-	out1fmt("%s", jp->ps[0].cmd);
-	for (i = 1; i < jp->nprocs; i++)
-		out1fmt(" | %s", jp->ps[i].cmd );
-	out1c('\n');
-	output_flushall();
-
-	for (i = 0; i < jp->nprocs; i++)
-	    if (tcsetpgrp(ttyfd, jp->ps[i].pid) != -1)
-		    break;
-
-	if (i >= jp->nprocs) {
-		error("Cannot set tty process group (%s) at %d",
-		    strerror(errno), __LINE__);
-	}
-	restartjob(jp);
-	INTOFF;
-	status = waitforjob(jp);
-	INTON;
-	return status;
-}
-
-static void
-set_curjob(struct job *jp, int mode)
-{
-	struct job *jp1, *jp2;
-	int i, ji;
-
-	ji = jp - jobtab;
-
-	/* first remove from list */
-	if (ji == curjob)
-		curjob = jp->prev_job;
-	else {
-		for (i = 0; i < njobs; i++) {
-			if (jobtab[i].prev_job != ji)
-				continue;
-			jobtab[i].prev_job = jp->prev_job;
-			break;
-		}
-	}
-
-	/* Then re-insert in correct position */
-	switch (mode) {
-	case 0:	/* job being deleted */
-		jp->prev_job = -1;
-		break;
-	case 1:	/* newly created job or backgrounded job,
-		   put after all stopped jobs. */
-		if (curjob != -1 && jobtab[curjob].state == JOBSTOPPED) {
-			for (jp1 = jobtab + curjob; ; jp1 = jp2) {
-				if (jp1->prev_job == -1)
-					break;
-				jp2 = jobtab + jp1->prev_job;
-				if (jp2->state != JOBSTOPPED)
-					break;
-			}
-			jp->prev_job = jp1->prev_job;
-			jp1->prev_job = ji;
-			break;
-		}
-		/* FALLTHROUGH */
-	case 2:	/* newly stopped job - becomes curjob */
-		jp->prev_job = curjob;
-		curjob = ji;
-		break;
-	}
-}
-
-int
-bgcmd(int argc, char **argv)
-{
-	struct job *jp;
-	int i;
-
-	nextopt("");
-	do {
-		jp = getjob(*argptr, 0);
-		if (jp->jobctl == 0)
-			error("job not created under job control");
-		set_curjob(jp, 1);
-		out1fmt("[%ld] %s", (long)(jp - jobtab + 1), jp->ps[0].cmd);
-		for (i = 1; i < jp->nprocs; i++)
-			out1fmt(" | %s", jp->ps[i].cmd );
-		out1c('\n');
-		output_flushall();
-		restartjob(jp);
-	} while (*argptr && *++argptr);
-	return 0;
-}
-
-
-STATIC void
-restartjob(struct job *jp)
-{
-	struct procstat *ps;
-	int i;
-
-	if (jp->state == JOBDONE)
-		return;
-	INTOFF;
-	for (i = 0; i < jp->nprocs; i++)
-		if (killpg(jp->ps[i].pid, SIGCONT) != -1)
-			break;
-	if (i >= jp->nprocs)
-		error("Cannot continue job (%s)", strerror(errno));
-	for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) {
-		if (WIFSTOPPED(ps->status)) {
-			ps->status = -1;
-			jp->state = JOBRUNNING;
-		}
-	}
-	INTON;
-}
-#endif
-
-static void
-showjob(struct output *out, struct job *jp, int mode)
-{
-	int procno;
-	int st;
-	struct procstat *ps;
-	int col;
-	char s[64];
-
-#if JOBS
-	if (mode & SHOW_PGID) {
-		/* just output process (group) id of pipeline */
-		outfmt(out, "%ld\n", (long)jp->ps->pid);
-		return;
-	}
-#endif
-
-	procno = jp->nprocs;
-	if (!procno)
-		return;
-
-	if (mode & SHOW_PID)
-		mode |= SHOW_MULTILINE;
-
-	if ((procno > 1 && !(mode & SHOW_MULTILINE))
-	    || (mode & SHOW_SIGNALLED)) {
-		/* See if we have more than one status to report */
-		ps = jp->ps;
-		st = ps->status;
-		do {
-			int st1 = ps->status;
-			if (st1 != st)
-				/* yes - need multi-line output */
-				mode |= SHOW_MULTILINE;
-			if (st1 == -1 || !(mode & SHOW_SIGNALLED) || WIFEXITED(st1))
-				continue;
-			if (WIFSTOPPED(st1) || ((st1 = WTERMSIG(st1) & 0x7f)
-			    && st1 != SIGINT && st1 != SIGPIPE))
-				mode |= SHOW_ISSIG;
-
-		} while (ps++, --procno);
-		procno = jp->nprocs;
-	}
-
-	if (mode & SHOW_SIGNALLED && !(mode & SHOW_ISSIG)) {
-		if (jp->state == JOBDONE && !(mode & SHOW_NO_FREE)) {
-			TRACE(("showjob: freeing job %d\n", jp - jobtab + 1));
-			freejob(jp);
-		}
-		return;
-	}
-
-	for (ps = jp->ps; --procno >= 0; ps++) {	/* for each process */
-		if (ps == jp->ps)
-			fmtstr(s, 16, "[%ld] %c ",
-				(long)(jp - jobtab + 1),
-#if JOBS
-				jp == jobtab + curjob ? '+' :
-				curjob != -1 && jp == jobtab +
-					    jobtab[curjob].prev_job ? '-' :
-#endif
-				' ');
-		else
-			fmtstr(s, 16, "      " );
-		col = strlen(s);
-		if (mode & SHOW_PID) {
-			fmtstr(s + col, 16, "%ld ", (long)ps->pid);
-			     col += strlen(s + col);
-		}
-		if (ps->status == -1) {
-			scopy("Running", s + col);
-		} else if (WIFEXITED(ps->status)) {
-			st = WEXITSTATUS(ps->status);
-			if (st)
-				fmtstr(s + col, 16, "Done(%d)", st);
-			else
-				fmtstr(s + col, 16, "Done");
-		} else {
-#if JOBS
-			if (WIFSTOPPED(ps->status))
-				st = WSTOPSIG(ps->status);
-			else /* WIFSIGNALED(ps->status) */
-#endif
-				st = WTERMSIG(ps->status);
-			st &= 0x7f;
-			if (st < NSIG && sys_siglist[st])
-				scopyn(sys_siglist[st], s + col, 32);
-			else
-				fmtstr(s + col, 16, "Signal %d", st);
-			if (WCOREDUMP(ps->status)) {
-				col += strlen(s + col);
-				scopyn(" (core dumped)", s + col,  64 - col);
-			}
-		}
-		col += strlen(s + col);
-		outstr(s, out);
-		do {
-			outc(' ', out);
-			col++;
-		} while (col < 30);
-		outstr(ps->cmd, out);
-		if (mode & SHOW_MULTILINE) {
-			if (procno > 0) {
-				outc(' ', out);
-				outc('|', out);
-			}
-		} else {
-			while (--procno >= 0)
-				outfmt(out, " | %s", (++ps)->cmd );
-		}
-		outc('\n', out);
-	}
-	flushout(out);
-	jp->changed = 0;
-	if (jp->state == JOBDONE && !(mode & SHOW_NO_FREE))
-		freejob(jp);
-}
-
-
-int
-jobscmd(int argc, char **argv)
-{
-	int mode, m;
-	int sv = jobs_invalid;
-
-	jobs_invalid = 0;
-	mode = 0;
-	while ((m = nextopt("lp")))
-		if (m == 'l')
-			mode = SHOW_PID;
-		else
-			mode = SHOW_PGID;
-	if (*argptr)
-		do
-			showjob(out1, getjob(*argptr,0), mode);
-		while (*++argptr);
-	else
-		showjobs(out1, mode);
-	jobs_invalid = sv;
-	return 0;
-}
-
-
-/*
- * Print a list of jobs.  If "change" is nonzero, only print jobs whose
- * statuses have changed since the last call to showjobs.
- *
- * If the shell is interrupted in the process of creating a job, the
- * result may be a job structure containing zero processes.  Such structures
- * will be freed here.
- */
-
-void
-showjobs(struct output *out, int mode)
-{
-	int jobno;
-	struct job *jp;
-	int silent = 0, gotpid;
-
-	TRACE(("showjobs(%x) called\n", mode));
-
-	/* If not even one one job changed, there is nothing to do */
-	gotpid = dowait(0, NULL);
-	while (dowait(0, NULL) > 0)
-		continue;
-#ifdef JOBS
-	/*
-	 * Check if we are not in our foreground group, and if not
-	 * put us in it.
-	 */
-	if (mflag && gotpid != -1 && tcgetpgrp(ttyfd) != getpid()) {
-		if (tcsetpgrp(ttyfd, getpid()) == -1)
-			error("Cannot set tty process group (%s) at %d",
-			    strerror(errno), __LINE__);
-		TRACE(("repaired tty process group\n"));
-		silent = 1;
-	}
-#endif
-	if (jobs_invalid)
-		return;
-
-	for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) {
-		if (!jp->used)
-			continue;
-		if (jp->nprocs == 0) {
-			freejob(jp);
-			continue;
-		}
-		if ((mode & SHOW_CHANGED) && !jp->changed)
-			continue;
-		if (silent && jp->changed) {
-			jp->changed = 0;
-			continue;
-		}
-		showjob(out, jp, mode);
-	}
-}
-
-/*
- * Mark a job structure as unused.
- */
-
-STATIC void
-freejob(struct job *jp)
-{
-	INTOFF;
-	if (jp->ps != &jp->ps0) {
-		ckfree(jp->ps);
-		jp->ps = &jp->ps0;
-	}
-	jp->nprocs = 0;
-	jp->used = 0;
-#if JOBS
-	set_curjob(jp, 0);
-#endif
-	INTON;
-}
-
-
-
-int
-waitcmd(int argc, char **argv)
-{
-	struct job *job;
-	int status, retval;
-	struct job *jp;
-
-	nextopt("");
-
-	if (!*argptr) {
-		/* wait for all jobs */
-		jp = jobtab;
-		if (jobs_invalid)
-			return 0;
-		for (;;) {
-			if (jp >= jobtab + njobs) {
-				/* no running procs */
-				return 0;
-			}
-			if (!jp->used || jp->state != JOBRUNNING) {
-				jp++;
-				continue;
-			}
-			if (dowait(1, (struct job *)NULL) == -1)
-			       return 128 + SIGINT;
-			jp = jobtab;
-		}
-	}
-
-	retval = 127;		/* XXXGCC: -Wuninitialized */
-	for (; *argptr; argptr++) {
-		job = getjob(*argptr, 1);
-		if (!job) {
-			retval = 127;
-			continue;
-		}
-		/* loop until process terminated or stopped */
-		while (job->state == JOBRUNNING) {
-			if (dowait(1, (struct job *)NULL) == -1)
-			       return 128 + SIGINT;
-		}
-		status = job->ps[job->nprocs].status;
-		if (WIFEXITED(status))
-			retval = WEXITSTATUS(status);
-#if JOBS
-		else if (WIFSTOPPED(status))
-			retval = WSTOPSIG(status) + 128;
-#endif
-		else {
-			/* XXX: limits number of signals */
-			retval = WTERMSIG(status) + 128;
-		}
-		if (!iflag)
-			freejob(job);
-	}
-	return retval;
-}
-
-
-
-int
-jobidcmd(int argc, char **argv)
-{
-	struct job *jp;
-	int i;
-
-	nextopt("");
-	jp = getjob(*argptr, 0);
-	for (i = 0 ; i < jp->nprocs ; ) {
-		out1fmt("%ld", (long)jp->ps[i].pid);
-		out1c(++i < jp->nprocs ? ' ' : '\n');
-	}
-	return 0;
-}
-
-int
-getjobpgrp(const char *name)
-{
-	struct job *jp;
-
-	jp = getjob(name, 1);
-	if (jp == 0)
-		return 0;
-	return -jp->ps[0].pid;
-}
-
-/*
- * Convert a job name to a job structure.
- */
-
-STATIC struct job *
-getjob(const char *name, int noerror)
-{
-	int jobno = -1;
-	struct job *jp;
-	int pid;
-	int i;
-	const char *err_msg = "No such job: %s";
-
-	if (name == NULL) {
-#if JOBS
-		jobno = curjob;
-#endif
-		err_msg = "No current job";
-	} else if (name[0] == '%') {
-		if (is_number(name + 1)) {
-			jobno = number(name + 1) - 1;
-		} else if (!name[2]) {
-			switch (name[1]) {
-#if JOBS
-			case 0:
-			case '+':
-			case '%':
-				jobno = curjob;
-				err_msg = "No current job";
-				break;
-			case '-':
-				jobno = curjob;
-				if (jobno != -1)
-					jobno = jobtab[jobno].prev_job;
-				err_msg = "No previous job";
-				break;
-#endif
-			default:
-				goto check_pattern;
-			}
-		} else {
-			struct job *found;
-    check_pattern:
-			found = NULL;
-			for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
-				if (!jp->used || jp->nprocs <= 0)
-					continue;
-				if ((name[1] == '?'
-					&& strstr(jp->ps[0].cmd, name + 2))
-				    || prefix(name + 1, jp->ps[0].cmd)) {
-					if (found) {
-						err_msg = "%s: ambiguous";
-						found = 0;
-						break;
-					}
-					found = jp;
-				}
-			}
-			if (found)
-				return found;
-		}
-
-	} else if (is_number(name)) {
-		pid = number(name);
-		for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
-			if (jp->used && jp->nprocs > 0
-			 && jp->ps[jp->nprocs - 1].pid == pid)
-				return jp;
-		}
-	}
-
-	if (!jobs_invalid && jobno >= 0 && jobno < njobs) {
-		jp = jobtab + jobno;
-		if (jp->used)
-			return jp;
-	}
-	if (!noerror)
-		error(err_msg, name);
-	return 0;
-}
-
-
-
-/*
- * Return a new job structure,
- */
-
-struct job *
-makejob(union node *node, int nprocs)
-{
-	int i;
-	struct job *jp;
-
-	if (jobs_invalid) {
-		for (i = njobs, jp = jobtab ; --i >= 0 ; jp++) {
-			if (jp->used)
-				freejob(jp);
-		}
-		jobs_invalid = 0;
-	}
-
-	for (i = njobs, jp = jobtab ; ; jp++) {
-		if (--i < 0) {
-			INTOFF;
-			if (njobs == 0) {
-				jobtab = ckmalloc(4 * sizeof jobtab[0]);
-			} else {
-				jp = ckmalloc((njobs + 4) * sizeof jobtab[0]);
-				memcpy(jp, jobtab, njobs * sizeof jp[0]);
-				/* Relocate `ps' pointers */
-				for (i = 0; i < njobs; i++)
-					if (jp[i].ps == &jobtab[i].ps0)
-						jp[i].ps = &jp[i].ps0;
-				ckfree(jobtab);
-				jobtab = jp;
-			}
-			jp = jobtab + njobs;
-			for (i = 4 ; --i >= 0 ; jobtab[njobs++].used = 0);
-			INTON;
-			break;
-		}
-		if (jp->used == 0)
-			break;
-	}
-	INTOFF;
-	jp->state = JOBRUNNING;
-	jp->used = 1;
-	jp->changed = 0;
-	jp->nprocs = 0;
-#if JOBS
-	jp->jobctl = jobctl;
-	set_curjob(jp, 1);
-#endif
-	if (nprocs > 1) {
-		jp->ps = ckmalloc(nprocs * sizeof (struct procstat));
-	} else {
-		jp->ps = &jp->ps0;
-	}
-	INTON;
-	TRACE(("makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs,
-	    jp - jobtab + 1));
-	return jp;
-}
-
-
-/*
- * Fork off a subshell.  If we are doing job control, give the subshell its
- * own process group.  Jp is a job structure that the job is to be added to.
- * N is the command that will be evaluated by the child.  Both jp and n may
- * be NULL.  The mode parameter can be one of the following:
- *	FORK_FG - Fork off a foreground process.
- *	FORK_BG - Fork off a background process.
- *	FORK_NOJOB - Like FORK_FG, but don't give the process its own
- *		     process group even if job control is on.
- *
- * When job control is turned off, background processes have their standard
- * input redirected to /dev/null (except for the second and later processes
- * in a pipeline).
- */
-
-int
-forkshell(struct job *jp, union node *n, int mode)
-{
-	int pid;
-
-	TRACE(("forkshell(%%%d, %p, %d) called\n", jp - jobtab, n, mode));
-	switch ((pid = fork())) {
-	case -1:
-		TRACE(("Fork failed, errno=%d\n", errno));
-		INTON;
-		error("Cannot fork");
-		break;
-	case 0:
-		forkchild(jp, n, mode, 0);
-		return 0;
-	default:
-		return forkparent(jp, n, mode, pid);
-	}
-}
-
-int
-forkparent(struct job *jp, union node *n, int mode, pid_t pid)
-{
-	int pgrp;
-
-	if (rootshell && mode != FORK_NOJOB && mflag) {
-		if (jp == NULL || jp->nprocs == 0)
-			pgrp = pid;
-		else
-			pgrp = jp->ps[0].pid;
-		/* This can fail because we are doing it in the child also */
-		(void)setpgid(pid, pgrp);
-	}
-	if (mode == FORK_BG)
-		backgndpid = pid;		/* set $! */
-	if (jp) {
-		struct procstat *ps = &jp->ps[jp->nprocs++];
-		ps->pid = pid;
-		ps->status = -1;
-		ps->cmd[0] = 0;
-		if (/* iflag && rootshell && */ n)
-			commandtext(ps, n);
-	}
-	TRACE(("In parent shell:  child = %d\n", pid));
-	return pid;
-}
-
-void
-forkchild(struct job *jp, union node *n, int mode, int vforked)
-{
-	int wasroot;
-	int pgrp;
-	const char *devnull = _PATH_DEVNULL;
-	const char *nullerr = "Can't open %s";
-
-	wasroot = rootshell;
-	TRACE(("Child shell %d\n", getpid()));
-	if (!vforked)
-		rootshell = 0;
-
-	closescript(vforked);
-	clear_traps(vforked);
-#if JOBS
-	if (!vforked)
-		jobctl = 0;		/* do job control only in root shell */
-	if (wasroot && mode != FORK_NOJOB && mflag) {
-		if (jp == NULL || jp->nprocs == 0)
-			pgrp = getpid();
-		else
-			pgrp = jp->ps[0].pid;
-		/* This can fail because we are doing it in the parent also */
-		(void)setpgid(0, pgrp);
-		if (mode == FORK_FG) {
-			if (tcsetpgrp(ttyfd, pgrp) == -1)
-				error("Cannot set tty process group (%s) at %d",
-				    strerror(errno), __LINE__);
-		}
-		setsignal(SIGTSTP, vforked);
-		setsignal(SIGTTOU, vforked);
-	} else if (mode == FORK_BG) {
-		ignoresig(SIGINT, vforked);
-		ignoresig(SIGQUIT, vforked);
-		if ((jp == NULL || jp->nprocs == 0) &&
-		    ! fd0_redirected_p ()) {
-			close(0);
-			if (open(devnull, O_RDONLY) != 0)
-				error(nullerr, devnull);
-		}
-	}
-#else
-	if (mode == FORK_BG) {
-		ignoresig(SIGINT, vforked);
-		ignoresig(SIGQUIT, vforked);
-		if ((jp == NULL || jp->nprocs == 0) &&
-		    ! fd0_redirected_p ()) {
-			close(0);
-			if (open(devnull, O_RDONLY) != 0)
-				error(nullerr, devnull);
-		}
-	}
-#endif
-	if (wasroot && iflag) {
-		setsignal(SIGINT, vforked);
-		setsignal(SIGQUIT, vforked);
-		setsignal(SIGTERM, vforked);
-	}
-
-	if (!vforked)
-		jobs_invalid = 1;
-}
-
-/*
- * Wait for job to finish.
- *
- * Under job control we have the problem that while a child process is
- * running interrupts generated by the user are sent to the child but not
- * to the shell.  This means that an infinite loop started by an inter-
- * active user may be hard to kill.  With job control turned off, an
- * interactive user may place an interactive program inside a loop.  If
- * the interactive program catches interrupts, the user doesn't want
- * these interrupts to also abort the loop.  The approach we take here
- * is to have the shell ignore interrupt signals while waiting for a
- * forground process to terminate, and then send itself an interrupt
- * signal if the child process was terminated by an interrupt signal.
- * Unfortunately, some programs want to do a bit of cleanup and then
- * exit on interrupt; unless these processes terminate themselves by
- * sending a signal to themselves (instead of calling exit) they will
- * confuse this approach.
- */
-
-int
-waitforjob(struct job *jp)
-{
-#if JOBS
-	int mypgrp = getpgrp();
-#endif
-	int status;
-	int st;
-
-	INTOFF;
-	TRACE(("waitforjob(%%%d) called\n", jp - jobtab + 1));
-	while (jp->state == JOBRUNNING) {
-		dowait(1, jp);
-	}
-#if JOBS
-	if (jp->jobctl) {
-		if (tcsetpgrp(ttyfd, mypgrp) == -1)
-			error("Cannot set tty process group (%s) at %d",
-			    strerror(errno), __LINE__);
-	}
-	if (jp->state == JOBSTOPPED && curjob != jp - jobtab)
-		set_curjob(jp, 2);
-#endif
-	status = jp->ps[jp->nprocs - 1].status;
-	/* convert to 8 bits */
-	if (WIFEXITED(status))
-		st = WEXITSTATUS(status);
-#if JOBS
-	else if (WIFSTOPPED(status))
-		st = WSTOPSIG(status) + 128;
-#endif
-	else
-		st = WTERMSIG(status) + 128;
-	TRACE(("waitforjob: job %d, nproc %d, status %x, st %x\n",
-		jp - jobtab + 1, jp->nprocs, status, st ));
-#if JOBS
-	if (jp->jobctl) {
-		/*
-		 * This is truly gross.
-		 * If we're doing job control, then we did a TIOCSPGRP which
-		 * caused us (the shell) to no longer be in the controlling
-		 * session -- so we wouldn't have seen any ^C/SIGINT.  So, we
-		 * intuit from the subprocess exit status whether a SIGINT
-		 * occurred, and if so interrupt ourselves.  Yuck.  - mycroft
-		 */
-		if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT)
-			raise(SIGINT);
-	}
-#endif
-	if (! JOBS || jp->state == JOBDONE)
-		freejob(jp);
-	INTON;
-	return st;
-}
-
-
-
-/*
- * Wait for a process to terminate.
- */
-
-STATIC int
-dowait(int block, struct job *job)
-{
-	int pid;
-	int status;
-	struct procstat *sp;
-	struct job *jp;
-	struct job *thisjob;
-	int done;
-	int stopped;
-	extern volatile char gotsig[];
-
-	TRACE(("dowait(%d) called\n", block));
-	do {
-		pid = waitproc(block, job, &status);
-		TRACE(("wait returns pid %d, status %d\n", pid, status));
-	} while (pid == -1 && errno == EINTR && gotsig[SIGINT - 1] == 0);
-	if (pid <= 0)
-		return pid;
-	INTOFF;
-	thisjob = NULL;
-	for (jp = jobtab ; jp < jobtab + njobs ; jp++) {
-		if (jp->used) {
-			done = 1;
-			stopped = 1;
-			for (sp = jp->ps ; sp < jp->ps + jp->nprocs ; sp++) {
-				if (sp->pid == -1)
-					continue;
-				if (sp->pid == pid) {
-					TRACE(("Job %d: changing status of proc %d from 0x%x to 0x%x\n", jp - jobtab + 1, pid, sp->status, status));
-					sp->status = status;
-					thisjob = jp;
-				}
-				if (sp->status == -1)
-					stopped = 0;
-				else if (WIFSTOPPED(sp->status))
-					done = 0;
-			}
-			if (stopped) {		/* stopped or done */
-				int state = done ? JOBDONE : JOBSTOPPED;
-				if (jp->state != state) {
-					TRACE(("Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state));
-					jp->state = state;
-#if JOBS
-					if (done)
-						set_curjob(jp, 0);
-#endif
-				}
-			}
-		}
-	}
-
-	if (thisjob && thisjob->state != JOBRUNNING) {
-		int mode = 0;
-		if (!rootshell || !iflag)
-			mode = SHOW_SIGNALLED;
-		if (job == thisjob)
-			mode = SHOW_SIGNALLED | SHOW_NO_FREE;
-		if (mode)
-			showjob(out2, thisjob, mode);
-		else {
-			TRACE(("Not printing status, rootshell=%d, job=%p\n",
-				rootshell, job));
-			thisjob->changed = 1;
-		}
-	}
-
-	INTON;
-	return pid;
-}
-
-
-
-/*
- * Do a wait system call.  If job control is compiled in, we accept
- * stopped processes.  If block is zero, we return a value of zero
- * rather than blocking.
- *
- * System V doesn't have a non-blocking wait system call.  It does
- * have a SIGCLD signal that is sent to a process when one of it's
- * children dies.  The obvious way to use SIGCLD would be to install
- * a handler for SIGCLD which simply bumped a counter when a SIGCLD
- * was received, and have waitproc bump another counter when it got
- * the status of a process.  Waitproc would then know that a wait
- * system call would not block if the two counters were different.
- * This approach doesn't work because if a process has children that
- * have not been waited for, System V will send it a SIGCLD when it
- * installs a signal handler for SIGCLD.  What this means is that when
- * a child exits, the shell will be sent SIGCLD signals continuously
- * until is runs out of stack space, unless it does a wait call before
- * restoring the signal handler.  The code below takes advantage of
- * this (mis)feature by installing a signal handler for SIGCLD and
- * then checking to see whether it was called.  If there are any
- * children to be waited for, it will be.
- *
- * If neither SYSV nor BSD is defined, we don't implement nonblocking
- * waits at all.  In this case, the user will not be informed when
- * a background process until the next time she runs a real program
- * (as opposed to running a builtin command or just typing return),
- * and the jobs command may give out of date information.
- */
-
-#ifdef SYSV
-STATIC int gotsigchild;
-
-STATIC int onsigchild() {
-	gotsigchild = 1;
-}
-#endif
-
-
-STATIC int
-waitproc(int block, struct job *jp, int *status)
-{
-#ifdef BSD
-	int flags = 0;
-
-#if JOBS
-	if (jp != NULL && jp->jobctl)
-		flags |= WUNTRACED;
-#endif
-	if (block == 0)
-		flags |= WNOHANG;
-	return wait3(status, flags, (struct rusage *)NULL);
-#else
-#ifdef SYSV
-	int (*save)();
-
-	if (block == 0) {
-		gotsigchild = 0;
-		save = signal(SIGCLD, onsigchild);
-		signal(SIGCLD, save);
-		if (gotsigchild == 0)
-			return 0;
-	}
-	return wait(status);
-#else
-	if (block == 0)
-		return 0;
-	return wait(status);
-#endif
-#endif
-}
-
-/*
- * return 1 if there are stopped jobs, otherwise 0
- */
-int job_warning = 0;
-int
-stoppedjobs(void)
-{
-	int jobno;
-	struct job *jp;
-
-	if (job_warning || jobs_invalid)
-		return (0);
-	for (jobno = 1, jp = jobtab; jobno <= njobs; jobno++, jp++) {
-		if (jp->used == 0)
-			continue;
-		if (jp->state == JOBSTOPPED) {
-			out2str("You have stopped jobs.\n");
-			job_warning = 2;
-			return (1);
-		}
-	}
-
-	return (0);
-}
-
-/*
- * Return a string identifying a command (to be printed by the
- * jobs command).
- */
-
-STATIC char *cmdnextc;
-STATIC int cmdnleft;
-
-void
-commandtext(struct procstat *ps, union node *n)
-{
-	int len;
-
-	cmdnextc = ps->cmd;
-	if (iflag || mflag || sizeof ps->cmd < 100)
-		len = sizeof(ps->cmd);
-	else
-		len = sizeof(ps->cmd) / 10;
-	cmdnleft = len;
-	cmdtxt(n);
-	if (cmdnleft <= 0) {
-		char *p = ps->cmd + len - 4;
-		p[0] = '.';
-		p[1] = '.';
-		p[2] = '.';
-		p[3] = 0;
-	} else
-		*cmdnextc = '\0';
-	TRACE(("commandtext: ps->cmd %x, end %x, left %d\n\t\"%s\"\n",
-		ps->cmd, cmdnextc, cmdnleft, ps->cmd));
-}
-
-
-STATIC void
-cmdtxt(union node *n)
-{
-	union node *np;
-	struct nodelist *lp;
-	const char *p;
-	int i;
-	char s[2];
-
-	if (n == NULL || cmdnleft <= 0)
-		return;
-	switch (n->type) {
-	case NSEMI:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs("; ");
-		cmdtxt(n->nbinary.ch2);
-		break;
-	case NAND:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs(" && ");
-		cmdtxt(n->nbinary.ch2);
-		break;
-	case NOR:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs(" || ");
-		cmdtxt(n->nbinary.ch2);
-		break;
-	case NPIPE:
-		for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
-			cmdtxt(lp->n);
-			if (lp->next)
-				cmdputs(" | ");
-		}
-		break;
-	case NSUBSHELL:
-		cmdputs("(");
-		cmdtxt(n->nredir.n);
-		cmdputs(")");
-		break;
-	case NREDIR:
-	case NBACKGND:
-		cmdtxt(n->nredir.n);
-		break;
-	case NIF:
-		cmdputs("if ");
-		cmdtxt(n->nif.test);
-		cmdputs("; then ");
-		cmdtxt(n->nif.ifpart);
-		if (n->nif.elsepart) {
-			cmdputs("; else ");
-			cmdtxt(n->nif.elsepart);
-		}
-		cmdputs("; fi");
-		break;
-	case NWHILE:
-		cmdputs("while ");
-		goto until;
-	case NUNTIL:
-		cmdputs("until ");
-until:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs("; do ");
-		cmdtxt(n->nbinary.ch2);
-		cmdputs("; done");
-		break;
-	case NFOR:
-		cmdputs("for ");
-		cmdputs(n->nfor.var);
-		cmdputs(" in ");
-		cmdlist(n->nfor.args, 1);
-		cmdputs("; do ");
-		cmdtxt(n->nfor.body);
-		cmdputs("; done");
-		break;
-	case NCASE:
-		cmdputs("case ");
-		cmdputs(n->ncase.expr->narg.text);
-		cmdputs(" in ");
-		for (np = n->ncase.cases; np; np = np->nclist.next) {
-			cmdtxt(np->nclist.pattern);
-			cmdputs(") ");
-			cmdtxt(np->nclist.body);
-			cmdputs(";; ");
-		}
-		cmdputs("esac");
-		break;
-	case NDEFUN:
-		cmdputs(n->narg.text);
-		cmdputs("() { ... }");
-		break;
-	case NCMD:
-		cmdlist(n->ncmd.args, 1);
-		cmdlist(n->ncmd.redirect, 0);
-		break;
-	case NARG:
-		cmdputs(n->narg.text);
-		break;
-	case NTO:
-		p = ">";  i = 1;  goto redir;
-	case NCLOBBER:
-		p = ">|";  i = 1;  goto redir;
-	case NAPPEND:
-		p = ">>";  i = 1;  goto redir;
-	case NTOFD:
-		p = ">&";  i = 1;  goto redir;
-	case NFROM:
-		p = "<";  i = 0;  goto redir;
-	case NFROMFD:
-		p = "<&";  i = 0;  goto redir;
-	case NFROMTO:
-		p = "<>";  i = 0;  goto redir;
-redir:
-		if (n->nfile.fd != i) {
-			s[0] = n->nfile.fd + '0';
-			s[1] = '\0';
-			cmdputs(s);
-		}
-		cmdputs(p);
-		if (n->type == NTOFD || n->type == NFROMFD) {
-			s[0] = n->ndup.dupfd + '0';
-			s[1] = '\0';
-			cmdputs(s);
-		} else {
-			cmdtxt(n->nfile.fname);
-		}
-		break;
-	case NHERE:
-	case NXHERE:
-		cmdputs("<<...");
-		break;
-	default:
-		cmdputs("???");
-		break;
-	}
-}
-
-STATIC void
-cmdlist(union node *np, int sep)
-{
-	for (; np; np = np->narg.next) {
-		if (!sep)
-			cmdputs(" ");
-		cmdtxt(np);
-		if (sep && np->narg.next)
-			cmdputs(" ");
-	}
-}
-
-
-STATIC void
-cmdputs(const char *s)
-{
-	const char *p, *str = 0;
-	char c, cc[2] = " ";
-	char *nextc;
-	int nleft;
-	int subtype = 0;
-	int quoted = 0;
-	static char vstype[16][4] = { "", "}", "-", "+", "?", "=",
-					"#", "##", "%", "%%" };
-
-	p = s;
-	nextc = cmdnextc;
-	nleft = cmdnleft;
-	while (nleft > 0 && (c = *p++) != 0) {
-		switch (c) {
-		case CTLESC:
-			c = *p++;
-			break;
-		case CTLVAR:
-			subtype = *p++;
-			if ((subtype & VSTYPE) == VSLENGTH)
-				str = "${#";
-			else
-				str = "${";
-			if (!(subtype & VSQUOTE) != !(quoted & 1)) {
-				quoted ^= 1;
-				c = '"';
-			} else
-				c = *str++;
-			break;
-		case CTLENDVAR:
-			if (quoted & 1) {
-				c = '"';
-				str = "}";
-			} else
-				c = '}';
-			quoted >>= 1;
-			subtype = 0;
-			break;
-		case CTLBACKQ:
-			c = '$';
-			str = "(...)";
-			break;
-		case CTLBACKQ+CTLQUOTE:
-			c = '"';
-			str = "$(...)\"";
-			break;
-		case CTLARI:
-			c = '$';
-			str = "((";
-			break;
-		case CTLENDARI:
-			c = ')';
-			str = ")";
-			break;
-		case CTLQUOTEMARK:
-			quoted ^= 1;
-			c = '"';
-			break;
-		case '=':
-			if (subtype == 0)
-				break;
-			str = vstype[subtype & VSTYPE];
-			if (subtype & VSNUL)
-				c = ':';
-			else
-				c = *str++;
-			if (c != '}')
-				quoted <<= 1;
-			break;
-		case '\'':
-		case '\\':
-		case '"':
-		case '$':
-			/* These can only happen inside quotes */
-			cc[0] = c;
-			str = cc;
-			c = '\\';
-			break;
-		default:
-			break;
-		}
-		do {
-			*nextc++ = c;
-		} while (--nleft > 0 && str && (c = *str++));
-		str = 0;
-	}
-	if ((quoted & 1) && nleft) {
-		*nextc++ = '"';
-		nleft--;
-	}
-	cmdnleft = nleft;
-	cmdnextc = nextc;
-}
diff --git a/src/ash/jobs.h b/src/ash/jobs.h
deleted file mode 100644
index 47e76c2..0000000
--- a/src/ash/jobs.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*	$NetBSD: jobs.h,v 1.19 2003/11/27 21:16:14 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)jobs.h	8.2 (Berkeley) 5/4/95
- */
-
-#include "output.h"
-
-/* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
-#define FORK_FG 0
-#define FORK_BG 1
-#define FORK_NOJOB 2
-
-/* mode flags for showjob(s) */
-#define	SHOW_PGID	0x01	/* only show pgid - for jobs -p */
-#define	SHOW_MULTILINE	0x02	/* one line per process */
-#define	SHOW_PID	0x04	/* include process pid */
-#define	SHOW_CHANGED	0x08	/* only jobs whose state has changed */
-#define	SHOW_SIGNALLED	0x10	/* only if stopped/exited on signal */
-#define	SHOW_ISSIG	0x20	/* job was signalled */
-#define	SHOW_NO_FREE	0x40	/* do not free job */
-
-
-/*
- * A job structure contains information about a job.  A job is either a
- * single process or a set of processes contained in a pipeline.  In the
- * latter case, pidlist will be non-NULL, and will point to a -1 terminated
- * array of pids.
- */
-#define	MAXCMDTEXT	200
-
-struct procstat {
-	pid_t	pid;		/* process id */
- 	int	status;		/* last process status from wait() */
- 	char	cmd[MAXCMDTEXT];/* text of command being run */
-};
-
-struct job {
-	struct procstat ps0;	/* status of process */
-	struct procstat *ps;	/* status or processes when more than one */
-	int	nprocs;		/* number of processes */
-	pid_t	pgrp;		/* process group of this job */
-	char	state;
-#define	JOBRUNNING	0	/* at least one proc running */
-#define	JOBSTOPPED	1	/* all procs are stopped */
-#define	JOBDONE		2	/* all procs are completed */
-	char	used;		/* true if this entry is in used */
-	char	changed;	/* true if status has changed */
-#if JOBS
-	char 	jobctl;		/* job running under job control */
-	int	prev_job;	/* previous job index */
-#endif
-};
-
-extern pid_t backgndpid;	/* pid of last background process */
-extern int job_warning;		/* user was warned about stopped jobs */
-
-void setjobctl(int);
-int fgcmd(int, char **);
-int bgcmd(int, char **);
-int jobscmd(int, char **);
-void showjobs(struct output *, int);
-int waitcmd(int, char **);
-int jobidcmd(int, char **);
-struct job *makejob(union node *, int);
-int forkshell(struct job *, union node *, int);
-void forkchild(struct job *, union node *, int, int);
-int forkparent(struct job *, union node *, int, pid_t);
-int waitforjob(struct job *);
-int stoppedjobs(void);
-void commandtext(struct procstat *, union node *);
-int getjobpgrp(const char *);
-
-#if ! JOBS
-#define setjobctl(on)	/* do nothing */
-#endif
diff --git a/src/ash/machdep.h b/src/ash/machdep.h
deleted file mode 100644
index 14e803b..0000000
--- a/src/ash/machdep.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$NetBSD: machdep.h,v 1.11 2003/08/07 09:05:33 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)machdep.h	8.2 (Berkeley) 5/4/95
- */
-
-/*
- * Most machines require the value returned from malloc to be aligned
- * in some way.  The following macro will get this right on many machines.
- */
-
-#define SHELL_SIZE (sizeof(union {int i; char *cp; double d; }) - 1)
-/*
- * It appears that grabstackstr() will barf with such alignments
- * because stalloc() will return a string allocated in a new stackblock.
- */
-#define SHELL_ALIGN(nbytes) (((nbytes) + SHELL_SIZE) & ~SHELL_SIZE)
diff --git a/src/ash/mail.c b/src/ash/mail.c
deleted file mode 100644
index 569f72c..0000000
--- a/src/ash/mail.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*	$NetBSD: mail.c,v 1.16 2003/08/07 09:05:33 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)mail.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: mail.c,v 1.16 2003/08/07 09:05:33 agc Exp $");
-#endif
-#endif /* not lint */
-
-/*
- * Routines to check for mail.  (Perhaps make part of main.c?)
- */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-
-#include "shell.h"
-#include "exec.h"	/* defines padvance() */
-#include "var.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mail.h"
-
-
-#define MAXMBOXES 10
-
-
-STATIC int nmboxes;			/* number of mailboxes */
-STATIC time_t mailtime[MAXMBOXES];	/* times of mailboxes */
-
-
-
-/*
- * Print appropriate message(s) if mail has arrived.  If the argument is
- * nozero, then the value of MAIL has changed, so we just update the
- * values.
- */
-
-void
-chkmail(int silent)
-{
-	int i;
-	const char *mpath;
-	char *p;
-	char *q;
-	struct stackmark smark;
-	struct stat statb;
-
-	if (silent)
-		nmboxes = 10;
-	if (nmboxes == 0)
-		return;
-	setstackmark(&smark);
-	mpath = mpathset() ? mpathval() : mailval();
-	for (i = 0 ; i < nmboxes ; i++) {
-		p = padvance(&mpath, nullstr);
-		if (p == NULL)
-			break;
-		if (*p == '\0')
-			continue;
-		for (q = p ; *q ; q++);
-		if (q[-1] != '/')
-			abort();
-		q[-1] = '\0';			/* delete trailing '/' */
-#ifdef notdef /* this is what the System V shell claims to do (it lies) */
-		if (stat(p, &statb) < 0)
-			statb.st_mtime = 0;
-		if (statb.st_mtime > mailtime[i] && ! silent) {
-			out2str(pathopt ? pathopt : "you have mail");
-			out2c('\n');
-		}
-		mailtime[i] = statb.st_mtime;
-#else /* this is what it should do */
-		if (stat(p, &statb) < 0)
-			statb.st_size = 0;
-		if (statb.st_size > mailtime[i] && ! silent) {
-			out2str(pathopt ? pathopt : "you have mail");
-			out2c('\n');
-		}
-		mailtime[i] = statb.st_size;
-#endif
-	}
-	nmboxes = i;
-	popstackmark(&smark);
-}
diff --git a/src/ash/mail.h b/src/ash/mail.h
deleted file mode 100644
index 9ea7c21..0000000
--- a/src/ash/mail.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*	$NetBSD: mail.h,v 1.10 2003/08/07 09:05:34 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)mail.h	8.2 (Berkeley) 5/4/95
- */
-
-void chkmail(int);
diff --git a/src/ash/main.c b/src/ash/main.c
deleted file mode 100644
index 3ba0571..0000000
--- a/src/ash/main.c
+++ /dev/null
@@ -1,441 +0,0 @@
-/*	$NetBSD: main.c,v 1.48 2003/09/14 12:09:29 jmmv Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
-	The Regents of the University of California.  All rights reserved.\n");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)main.c	8.7 (Berkeley) 7/19/95";
-#else
-__RCSID("$NetBSD: main.c,v 1.48 2003/09/14 12:09:29 jmmv Exp $");
-#endif
-#endif /* not lint */
-
-#include <errno.h>
-#include <stdio.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <locale.h>
-#include <fcntl.h>
-
-
-#include "shell.h"
-#include "main.h"
-#include "mail.h"
-#include "options.h"
-#include "output.h"
-#include "parser.h"
-#include "nodes.h"
-#include "expand.h"
-#include "eval.h"
-#include "jobs.h"
-#include "input.h"
-#include "trap.h"
-#include "var.h"
-#include "show.h"
-#include "memalloc.h"
-#include "error.h"
-#include "init.h"
-#include "mystring.h"
-#include "exec.h"
-#include "cd.h"
-
-#define PROFILE 0
-
-int rootpid;
-int rootshell;
-STATIC union node *curcmd;
-STATIC union node *prevcmd;
-#if PROFILE
-short profile_buf[16384];
-extern int etext();
-#endif
-
-#ifndef KMK
-#error "Huh? KMK isn't defined!"
-STATIC void read_profile(const char *);
-#endif
-STATIC char *find_dot_file(char *);
-int main(int, char **);
-
-/*
- * Main routine.  We initialize things, parse the arguments, execute
- * profiles if we're a login shell, and then call cmdloop to execute
- * commands.  The setjmp call sets up the location to jump to when an
- * exception occurs.  When an exception occurs the variable "state"
- * is used to figure out how far we had gotten.
- */
-
-int
-main(int argc, char **argv)
-{
-	struct jmploc jmploc;
-	struct stackmark smark;
-	volatile int state;
-	char *shinit;
-
-	setlocale(LC_ALL, "");
-
-	/* Just a --version for show. */
-	if (argc > 1
-	 && argv[1][0] == '-'
-	 && argv[1][1] == '-') {
-		if (!strcmp(&argv[1][2], "version")) {
-			printf("kmk_ash - kBuild version %d.%d.%d\n",
-				   KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH);
-			return 0;
-		}
-		if (!strcmp(&argv[1][2], "help")) {
-			printf("usage: kmk_ash [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n"
-				   "               [+o option_name] [command_file [argument ...]]\n"
-				   "   or: kmk_ash -c [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n"
-				   "               [+o option_name] command_string [command_name [argument ...]]\n"
-				   "   or: kmk_ash -s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n"
-				   "               [+o option_name] [argument ...]\n"
-				   "   or: kmk_ash --help\n"
-				   "   or: kmk_ash --version\n",
-				   argv[0], argv[0], argv[0], argv[0], argv[0]);
-			return 0;
-		}
-	}
-
-#if PROFILE
-	monitor(4, etext, profile_buf, sizeof profile_buf, 50);
-#endif
-	state = 0;
-	if (setjmp(jmploc.loc)) {
-		/*
-		 * When a shell procedure is executed, we raise the
-		 * exception EXSHELLPROC to clean up before executing
-		 * the shell procedure.
-		 */
-		switch (exception) {
-		case EXSHELLPROC:
-			rootpid = getpid();
-			rootshell = 1;
-			minusc = NULL;
-			state = 3;
-			break;
-
-		case EXEXEC:
-			exitstatus = exerrno;
-			break;
-
-		case EXERROR:
-			exitstatus = 2;
-			break;
-
-		default:
-			break;
-		}
-
-		if (exception != EXSHELLPROC) {
-			if (state == 0 || iflag == 0 || ! rootshell)
-				exitshell(exitstatus);
-		}
-		reset();
-		if (exception == EXINT
-#if ATTY
-		 && (! attyset() || equal(termval(), "emacs"))
-#endif
-		 ) {
-			out2c('\n');
-			flushout(&errout);
-		}
-		popstackmark(&smark);
-		FORCEINTON;				/* enable interrupts */
-		if (state == 1)
-			goto state1;
-		else if (state == 2)
-			goto state2;
-		else if (state == 3)
-			goto state3;
-		else
-			goto state4;
-	}
-	handler = &jmploc;
-#ifdef DEBUG
-#if DEBUG == 2
-	debug = 1;
-#endif
-	opentrace();
-	trputs("Shell args:  ");  trargs(argv);
-#endif
-	rootpid = getpid();
-	rootshell = 1;
-#ifdef _MSC_VER
-    {
-        extern void init_syntax(void);
-        init_syntax();
-    }
-#endif
-	init();
-	setstackmark(&smark);
-	procargs(argc, argv);
-	if (argv[0] && argv[0][0] == '-') {
-		state = 1;
-#ifndef KMK
-		read_profile("/etc/profile");
-#endif
-state1:
-		state = 2;
-#ifndef KMK
-		read_profile(".profile");
-#endif
-	}
-state2:
-	state = 3;
-#ifndef KMK
-	if (getuid() == geteuid() && getgid() == getegid()) {
-		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
-			state = 3;
-			read_profile(shinit);
-		}
-	}
-#endif
-state3:
-	state = 4;
-	if (sflag == 0 || minusc) {
-		static int sigs[] =  {
-		    SIGINT, SIGQUIT, SIGHUP,
-#ifdef SIGTSTP
-		    SIGTSTP,
-#endif
-		    SIGPIPE
-		};
-#define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0]))
-		int i;
-
-		for (i = 0; i < SIGSSIZE; i++)
-		    setsignal(sigs[i], 0);
-	}
-
-	if (minusc)
-		evalstring(minusc, 0);
-
-	if (sflag || minusc == NULL) {
-state4:	/* XXX ??? - why isn't this before the "if" statement */
-		cmdloop(1);
-	}
-#if PROFILE
-	monitor(0);
-#endif
-	exitshell(exitstatus);
-	/* NOTREACHED */
-}
-
-
-/*
- * Read and execute commands.  "Top" is nonzero for the top level command
- * loop; it turns on prompting if the shell is interactive.
- */
-
-void
-cmdloop(int top)
-{
-	union node *n;
-	struct stackmark smark;
-	int inter;
-	int numeof = 0;
-
-	TRACE(("cmdloop(%d) called\n", top));
-	setstackmark(&smark);
-	for (;;) {
-		if (pendingsigs)
-			dotrap();
-		inter = 0;
-		if (iflag && top) {
-			inter = 1;
-			showjobs(out2, SHOW_CHANGED);
-			chkmail(0);
-			flushout(&errout);
-		}
-		n = parsecmd(inter);
-		/* showtree(n); DEBUG */
-		if (n == NEOF) {
-			if (!top || numeof >= 50)
-				break;
-			if (!stoppedjobs()) {
-				if (!Iflag)
-					break;
-				out2str("\nUse \"exit\" to leave shell.\n");
-			}
-			numeof++;
-		} else if (n != NULL && nflag == 0) {
-			job_warning = (job_warning == 2) ? 1 : 0;
-			numeof = 0;
-			evaltree(n, 0);
-		}
-		popstackmark(&smark);
-		setstackmark(&smark);
-		if (evalskip == SKIPFILE) {
-			evalskip = 0;
-			break;
-		}
-	}
-	popstackmark(&smark);
-}
-
-
-
-#ifndef KMK
-/*
- * Read /etc/profile or .profile.  Return on error.
- */
-
-STATIC void
-read_profile(const char *name)
-{
-	int fd;
-	int xflag_set = 0;
-	int vflag_set = 0;
-
-	INTOFF;
-	if ((fd = open(name, O_RDONLY)) >= 0)
-		setinputfd(fd, 1);
-	INTON;
-	if (fd < 0)
-		return;
-	/* -q turns off -x and -v just when executing init files */
-	if (qflag)  {
-	    if (xflag)
-		    xflag = 0, xflag_set = 1;
-	    if (vflag)
-		    vflag = 0, vflag_set = 1;
-	}
-	cmdloop(0);
-	if (qflag)  {
-	    if (xflag_set)
-		    xflag = 1;
-	    if (vflag_set)
-		    vflag = 1;
-	}
-	popfile();
-}
-#endif /* !KMK */
-
-
-
-/*
- * Read a file containing shell functions.
- */
-
-void
-readcmdfile(char *name)
-{
-	int fd;
-
-	INTOFF;
-	if ((fd = open(name, O_RDONLY)) >= 0)
-		setinputfd(fd, 1);
-	else
-		error("Can't open %s", name);
-	INTON;
-	cmdloop(0);
-	popfile();
-}
-
-
-
-/*
- * Take commands from a file.  To be compatible we should do a path
- * search for the file, which is necessary to find sub-commands.
- */
-
-
-STATIC char *
-find_dot_file(char *basename)
-{
-	char *fullname;
-	const char *path = pathval();
-	struct stat statb;
-
-	/* don't try this for absolute or relative paths */
-	if (strchr(basename, '/'))
-		return basename;
-
-	while ((fullname = padvance(&path, basename)) != NULL) {
-		if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) {
-			/*
-			 * Don't bother freeing here, since it will
-			 * be freed by the caller.
-			 */
-			return fullname;
-		}
-		stunalloc(fullname);
-	}
-
-	/* not found in the PATH */
-	error("%s: not found", basename);
-	/* NOTREACHED */
-}
-
-int
-dotcmd(int argc, char **argv)
-{
-	exitstatus = 0;
-
-	if (argc >= 2) {		/* That's what SVR2 does */
-		char *fullname;
-		struct stackmark smark;
-
-		setstackmark(&smark);
-		fullname = find_dot_file(argv[1]);
-		setinputfile(fullname, 1);
-		commandname = fullname;
-		cmdloop(0);
-		popfile();
-		popstackmark(&smark);
-	}
-	return exitstatus;
-}
-
-
-int
-exitcmd(int argc, char **argv)
-{
-	if (stoppedjobs())
-		return 0;
-	if (argc > 1)
-		exitstatus = number(argv[1]);
-	exitshell(exitstatus);
-	/* NOTREACHED */
-}
diff --git a/src/ash/main.h b/src/ash/main.h
deleted file mode 100644
index d198e2d..0000000
--- a/src/ash/main.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*	$NetBSD: main.h,v 1.10 2003/08/07 09:05:34 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)main.h	8.2 (Berkeley) 5/4/95
- */
-
-extern int rootpid;	/* pid of main shell */
-extern int rootshell;	/* true if we aren't a child of the main shell */
-
-void readcmdfile(char *);
-void cmdloop(int);
-int dotcmd(int, char **);
-int exitcmd(int, char **);
diff --git a/src/ash/memalloc.c b/src/ash/memalloc.c
deleted file mode 100644
index eb26842..0000000
--- a/src/ash/memalloc.c
+++ /dev/null
@@ -1,309 +0,0 @@
-/*	$NetBSD: memalloc.c,v 1.28 2003/08/07 09:05:34 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)memalloc.c	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: memalloc.c,v 1.28 2003/08/07 09:05:34 agc Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "shell.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "machdep.h"
-#include "mystring.h"
-
-/*
- * Like malloc, but returns an error when out of space.
- */
-
-pointer
-ckmalloc(int nbytes)
-{
-	pointer p;
-
-	p = malloc(nbytes);
-	if (p == NULL)
-		error("Out of space");
-	return p;
-}
-
-
-/*
- * Same for realloc.
- */
-
-pointer
-ckrealloc(pointer p, int nbytes)
-{
-	p = realloc(p, nbytes);
-	if (p == NULL)
-		error("Out of space");
-	return p;
-}
-
-
-/*
- * Make a copy of a string in safe storage.
- */
-
-char *
-savestr(const char *s)
-{
-	char *p;
-
-	p = ckmalloc(strlen(s) + 1);
-	scopy(s, p);
-	return p;
-}
-
-
-/*
- * Parse trees for commands are allocated in lifo order, so we use a stack
- * to make this more efficient, and also to avoid all sorts of exception
- * handling code to handle interrupts in the middle of a parse.
- *
- * The size 504 was chosen because the Ultrix malloc handles that size
- * well.
- */
-
-#define MINSIZE 504		/* minimum size of a block */
-
-struct stack_block {
-	struct stack_block *prev;
-	char space[MINSIZE];
-};
-
-struct stack_block stackbase;
-struct stack_block *stackp = &stackbase;
-struct stackmark *markp;
-char *stacknxt = stackbase.space;
-int stacknleft = MINSIZE;
-int sstrnleft;
-int herefd = -1;
-
-pointer
-stalloc(int nbytes)
-{
-	char *p;
-
-	nbytes = SHELL_ALIGN(nbytes);
-	if (nbytes > stacknleft) {
-		int blocksize;
-		struct stack_block *sp;
-
-		blocksize = nbytes;
-		if (blocksize < MINSIZE)
-			blocksize = MINSIZE;
-		INTOFF;
-		sp = ckmalloc(sizeof(struct stack_block) - MINSIZE + blocksize);
-		sp->prev = stackp;
-		stacknxt = sp->space;
-		stacknleft = blocksize;
-		stackp = sp;
-		INTON;
-	}
-	p = stacknxt;
-	stacknxt += nbytes;
-	stacknleft -= nbytes;
-	return p;
-}
-
-
-void
-stunalloc(pointer p)
-{
-	if (p == NULL) {		/*DEBUG */
-		write(2, "stunalloc\n", 10);
-		abort();
-	}
-	stacknleft += stacknxt - (char *)p;
-	stacknxt = p;
-}
-
-
-
-void
-setstackmark(struct stackmark *mark)
-{
-	mark->stackp = stackp;
-	mark->stacknxt = stacknxt;
-	mark->stacknleft = stacknleft;
-	mark->marknext = markp;
-	markp = mark;
-}
-
-
-void
-popstackmark(struct stackmark *mark)
-{
-	struct stack_block *sp;
-
-	INTOFF;
-	markp = mark->marknext;
-	while (stackp != mark->stackp) {
-		sp = stackp;
-		stackp = sp->prev;
-		ckfree(sp);
-	}
-	stacknxt = mark->stacknxt;
-	stacknleft = mark->stacknleft;
-	INTON;
-}
-
-
-/*
- * When the parser reads in a string, it wants to stick the string on the
- * stack and only adjust the stack pointer when it knows how big the
- * string is.  Stackblock (defined in stack.h) returns a pointer to a block
- * of space on top of the stack and stackblocklen returns the length of
- * this block.  Growstackblock will grow this space by at least one byte,
- * possibly moving it (like realloc).  Grabstackblock actually allocates the
- * part of the block that has been used.
- */
-
-void
-growstackblock(void)
-{
-	int newlen = SHELL_ALIGN(stacknleft * 2 + 100);
-
-	if (stacknxt == stackp->space && stackp != &stackbase) {
-		struct stack_block *oldstackp;
-		struct stackmark *xmark;
-		struct stack_block *sp;
-
-		INTOFF;
-		oldstackp = stackp;
-		sp = stackp;
-		stackp = sp->prev;
-		sp = ckrealloc((pointer)sp,
-		    sizeof(struct stack_block) - MINSIZE + newlen);
-		sp->prev = stackp;
-		stackp = sp;
-		stacknxt = sp->space;
-		stacknleft = newlen;
-
-		/*
-		 * Stack marks pointing to the start of the old block
-		 * must be relocated to point to the new block
-		 */
-		xmark = markp;
-		while (xmark != NULL && xmark->stackp == oldstackp) {
-			xmark->stackp = stackp;
-			xmark->stacknxt = stacknxt;
-			xmark->stacknleft = stacknleft;
-			xmark = xmark->marknext;
-		}
-		INTON;
-	} else {
-		char *oldspace = stacknxt;
-		int oldlen = stacknleft;
-		char *p = stalloc(newlen);
-
-		(void)memcpy(p, oldspace, oldlen);
-		stacknxt = p;			/* free the space */
-		stacknleft += newlen;		/* we just allocated */
-	}
-}
-
-void
-grabstackblock(int len)
-{
-	len = SHELL_ALIGN(len);
-	stacknxt += len;
-	stacknleft -= len;
-}
-
-/*
- * The following routines are somewhat easier to use than the above.
- * The user declares a variable of type STACKSTR, which may be declared
- * to be a register.  The macro STARTSTACKSTR initializes things.  Then
- * the user uses the macro STPUTC to add characters to the string.  In
- * effect, STPUTC(c, p) is the same as *p++ = c except that the stack is
- * grown as necessary.  When the user is done, she can just leave the
- * string there and refer to it using stackblock().  Or she can allocate
- * the space for it using grabstackstr().  If it is necessary to allow
- * someone else to use the stack temporarily and then continue to grow
- * the string, the user should use grabstack to allocate the space, and
- * then call ungrabstr(p) to return to the previous mode of operation.
- *
- * USTPUTC is like STPUTC except that it doesn't check for overflow.
- * CHECKSTACKSPACE can be called before USTPUTC to ensure that there
- * is space for at least one character.
- */
-
-char *
-growstackstr(void)
-{
-	int len = stackblocksize();
-	if (herefd >= 0 && len >= 1024) {
-		xwrite(herefd, stackblock(), len);
-		sstrnleft = len - 1;
-		return stackblock();
-	}
-	growstackblock();
-	sstrnleft = stackblocksize() - len - 1;
-	return stackblock() + len;
-}
-
-/*
- * Called from CHECKSTRSPACE.
- */
-
-char *
-makestrspace(void)
-{
-	int len = stackblocksize() - sstrnleft;
-	growstackblock();
-	sstrnleft = stackblocksize() - len;
-	return stackblock() + len;
-}
-
-void
-ungrabstackstr(char *s, char *p)
-{
-	stacknleft += stacknxt - s;
-	stacknxt = s;
-	sstrnleft = stacknleft - (p - s);
-
-}
diff --git a/src/ash/memalloc.h b/src/ash/memalloc.h
deleted file mode 100644
index e793880..0000000
--- a/src/ash/memalloc.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*	$NetBSD: memalloc.h,v 1.14 2003/08/07 09:05:34 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)memalloc.h	8.2 (Berkeley) 5/4/95
- */
-
-struct stackmark {
-	struct stack_block *stackp;
-	char *stacknxt;
-	int stacknleft;
-	struct stackmark *marknext;
-};
-
-
-extern char *stacknxt;
-extern int stacknleft;
-extern int sstrnleft;
-extern int herefd;
-
-pointer ckmalloc(int);
-pointer ckrealloc(pointer, int);
-char *savestr(const char *);
-pointer stalloc(int);
-void stunalloc(pointer);
-void setstackmark(struct stackmark *);
-void popstackmark(struct stackmark *);
-void growstackblock(void);
-void grabstackblock(int);
-char *growstackstr(void);
-char *makestrspace(void);
-void ungrabstackstr(char *, char *);
-
-
-
-#define stackblock() stacknxt
-#define stackblocksize() stacknleft
-#define STARTSTACKSTR(p)	p = stackblock(), sstrnleft = stackblocksize()
-#define STPUTC(c, p)	(--sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(), *p++ = (c)))
-#define CHECKSTRSPACE(n, p)	{ if (sstrnleft < n) p = makestrspace(); }
-#define USTPUTC(c, p)	(--sstrnleft, *p++ = (c))
-#define STACKSTRNUL(p)	(sstrnleft == 0? (p = growstackstr(), *p = '\0') : (*p = '\0'))
-#define STUNPUTC(p)	(++sstrnleft, --p)
-#define STTOPC(p)	p[-1]
-#define STADJUST(amount, p)	(p += (amount), sstrnleft -= (amount))
-#define grabstackstr(p)	stalloc(stackblocksize() - sstrnleft)
-
-#define ckfree(p)	free((pointer)(p))
diff --git a/src/ash/miscbltin.c b/src/ash/miscbltin.c
deleted file mode 100644
index 9ec652d..0000000
--- a/src/ash/miscbltin.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/*	$NetBSD: miscbltin.c,v 1.35 2005/03/19 14:22:50 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)miscbltin.c	8.4 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: miscbltin.c,v 1.35 2005/03/19 14:22:50 dsl Exp $");
-#endif
-#endif /* not lint */
-
-/*
- * Miscelaneous builtins.
- */
-
-#include <sys/types.h>		/* quad_t */
-#include <sys/param.h>		/* BSD4_4 */
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <errno.h>
-
-#include "shell.h"
-#include "options.h"
-#include "var.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "miscbltin.h"
-#include "mystring.h"
-
-#undef rflag
-
-
-
-/*
- * The read builtin.
- * Backslahes escape the next char unless -r is specified.
- *
- * This uses unbuffered input, which may be avoidable in some cases.
- *
- * Note that if IFS=' :' then read x y should work so that:
- * 'a b'	x='a', y='b'
- * ' a b '	x='a', y='b'
- * ':b'		x='',  y='b'
- * ':'		x='',  y=''
- * '::'		x='',  y=''
- * ': :'	x='',  y=''
- * ':::'	x='',  y='::'
- * ':b c:'	x='',  y='b c:'
- */
-
-int
-readcmd(int argc, char **argv)
-{
-	char **ap;
-	char c;
-	int rflag;
-	char *prompt;
-	const char *ifs;
-	char *p;
-	int startword;
-	int status;
-	int i;
-	int is_ifs;
-	int saveall = 0;
-
-	rflag = 0;
-	prompt = NULL;
-	while ((i = nextopt("p:r")) != '\0') {
-		if (i == 'p')
-			prompt = optionarg;
-		else
-			rflag = 1;
-	}
-
-	if (prompt && isatty(0)) {
-		out2str(prompt);
-		output_flushall();
-	}
-
-	if (*(ap = argptr) == NULL)
-		error("arg count");
-
-	if ((ifs = bltinlookup("IFS", 1)) == NULL)
-		ifs = " \t\n";
-
-	status = 0;
-	startword = 2;
-	STARTSTACKSTR(p);
-	for (;;) {
-		if (read(0, &c, 1) != 1) {
-			status = 1;
-			break;
-		}
-		if (c == '\0')
-			continue;
-		if (c == '\\' && !rflag) {
-			if (read(0, &c, 1) != 1) {
-				status = 1;
-				break;
-			}
-			if (c != '\n')
-				STPUTC(c, p);
-			continue;
-		}
-		if (c == '\n')
-			break;
-		if (strchr(ifs, c))
-			is_ifs = strchr(" \t\n", c) ? 1 : 2;
-		else
-			is_ifs = 0;
-
-		if (startword != 0) {
-			if (is_ifs == 1) {
-				/* Ignore leading IFS whitespace */
-				if (saveall)
-					STPUTC(c, p);
-				continue;
-			}
-			if (is_ifs == 2 && startword == 1) {
-				/* Only one non-whitespace IFS per word */
-				startword = 2;
-				if (saveall)
-					STPUTC(c, p);
-				continue;
-			}
-		}
-
-		if (is_ifs == 0) {
-			/* append this character to the current variable */
-			startword = 0;
-			if (saveall)
-				/* Not just a spare terminator */
-				saveall++;
-			STPUTC(c, p);
-			continue;
-		}
-
-		/* end of variable... */
-		startword = is_ifs;
-
-		if (ap[1] == NULL) {
-			/* Last variable needs all IFS chars */
-			saveall++;
-			STPUTC(c, p);
-			continue;
-		}
-
-		STACKSTRNUL(p);
-		setvar(*ap, stackblock(), 0);
-		ap++;
-		STARTSTACKSTR(p);
-	}
-	STACKSTRNUL(p);
-
-	/* Remove trailing IFS chars */
-	for (; stackblock() <= --p; *p = 0) {
-		if (!strchr(ifs, *p))
-			break;
-		if (strchr(" \t\n", *p))
-			/* Always remove whitespace */
-			continue;
-		if (saveall > 1)
-			/* Don't remove non-whitespace unless it was naked */
-			break;
-	}
-	setvar(*ap, stackblock(), 0);
-
-	/* Set any remaining args to "" */
-	while (*++ap != NULL)
-		setvar(*ap, nullstr, 0);
-	return status;
-}
-
-
-
-int
-umaskcmd(int argc, char **argv)
-{
-	char *ap;
-	int mask;
-	int i;
-	int symbolic_mode = 0;
-
-	while ((i = nextopt("S")) != '\0') {
-		symbolic_mode = 1;
-	}
-
-	INTOFF;
-	mask = umask(0);
-	umask(mask);
-	INTON;
-
-	if ((ap = *argptr) == NULL) {
-		if (symbolic_mode) {
-			char u[4], g[4], o[4];
-
-			i = 0;
-			if ((mask & S_IRUSR) == 0)
-				u[i++] = 'r';
-			if ((mask & S_IWUSR) == 0)
-				u[i++] = 'w';
-			if ((mask & S_IXUSR) == 0)
-				u[i++] = 'x';
-			u[i] = '\0';
-
-			i = 0;
-			if ((mask & S_IRGRP) == 0)
-				g[i++] = 'r';
-			if ((mask & S_IWGRP) == 0)
-				g[i++] = 'w';
-			if ((mask & S_IXGRP) == 0)
-				g[i++] = 'x';
-			g[i] = '\0';
-
-			i = 0;
-			if ((mask & S_IROTH) == 0)
-				o[i++] = 'r';
-			if ((mask & S_IWOTH) == 0)
-				o[i++] = 'w';
-			if ((mask & S_IXOTH) == 0)
-				o[i++] = 'x';
-			o[i] = '\0';
-
-			out1fmt("u=%s,g=%s,o=%s\n", u, g, o);
-		} else {
-			out1fmt("%.4o\n", mask);
-		}
-	} else {
-		if (isdigit((unsigned char)*ap)) {
-			mask = 0;
-			do {
-				if (*ap >= '8' || *ap < '0')
-					error("Illegal number: %s", argv[1]);
-				mask = (mask << 3) + (*ap - '0');
-			} while (*++ap != '\0');
-			umask(mask);
-		} else {
-			void *set;
-
-			INTOFF;
-#ifdef __INNOTEK_LIBC__
-			if ((set = bsd_setmode(ap)) != 0) {
-#else
-			if ((set = setmode(ap)) != 0) {
-#endif
-				mask = getmode(set, ~mask & 0777);
-				ckfree(set);
-			}
-			INTON;
-			if (!set)
-				error("Illegal mode: %s", ap);
-
-			umask(~mask & 0777);
-		}
-	}
-	return 0;
-}
-
-/*
- * ulimit builtin
- *
- * This code, originally by Doug Gwyn, Doug Kingston, Eric Gisin, and
- * Michael Rendell was ripped from pdksh 5.0.8 and hacked for use with
- * ash by J.T. Conklin.
- *
- * Public domain.
- */
-
-struct limits {
-	const char *name;
-	int	cmd;
-	int	factor;	/* multiply by to get rlim_{cur,max} values */
-	char	option;
-};
-
-static const struct limits limits[] = {
-#ifdef RLIMIT_CPU
-	{ "time(seconds)",		RLIMIT_CPU,	   1, 't' },
-#endif
-#ifdef RLIMIT_FSIZE
-	{ "file(blocks)",		RLIMIT_FSIZE,	 512, 'f' },
-#endif
-#ifdef RLIMIT_DATA
-	{ "data(kbytes)",		RLIMIT_DATA,	1024, 'd' },
-#endif
-#ifdef RLIMIT_STACK
-	{ "stack(kbytes)",		RLIMIT_STACK,	1024, 's' },
-#endif
-#ifdef  RLIMIT_CORE
-	{ "coredump(blocks)",		RLIMIT_CORE,	 512, 'c' },
-#endif
-#ifdef RLIMIT_RSS
-	{ "memory(kbytes)",		RLIMIT_RSS,	1024, 'm' },
-#endif
-#ifdef RLIMIT_MEMLOCK
-	{ "locked memory(kbytes)",	RLIMIT_MEMLOCK, 1024, 'l' },
-#endif
-#ifdef RLIMIT_NPROC
-	{ "process(processes)",		RLIMIT_NPROC,      1, 'p' },
-#endif
-#ifdef RLIMIT_NOFILE
-	{ "nofiles(descriptors)",	RLIMIT_NOFILE,     1, 'n' },
-#endif
-#ifdef RLIMIT_VMEM
-	{ "vmemory(kbytes)",		RLIMIT_VMEM,	1024, 'v' },
-#endif
-#ifdef RLIMIT_SWAP
-	{ "swap(kbytes)",		RLIMIT_SWAP,	1024, 'w' },
-#endif
-#ifdef RLIMIT_SBSIZE
-	{ "sbsize(bytes)",		RLIMIT_SBSIZE,	   1, 'b' },
-#endif
-	{ (char *) 0,			0,		   0,  '\0' }
-};
-
-int
-ulimitcmd(int argc, char **argv)
-{
-	int	c;
-	rlim_t val = 0;
-	enum { SOFT = 0x1, HARD = 0x2 }
-			how = SOFT | HARD;
-	const struct limits	*l;
-	int		set, all = 0;
-	int		optc, what;
-	struct rlimit	limit;
-
-	what = 'f';
-	while ((optc = nextopt("HSabtfdsmcnpl")) != '\0')
-		switch (optc) {
-		case 'H':
-			how = HARD;
-			break;
-		case 'S':
-			how = SOFT;
-			break;
-		case 'a':
-			all = 1;
-			break;
-		default:
-			what = optc;
-		}
-
-	for (l = limits; l->name && l->option != what; l++)
-		;
-	if (!l->name)
-		error("internal error (%c)", what);
-
-	set = *argptr ? 1 : 0;
-	if (set) {
-		char *p = *argptr;
-
-		if (all || argptr[1])
-			error("too many arguments");
-		if (strcmp(p, "unlimited") == 0)
-			val = RLIM_INFINITY;
-		else {
-			val = (rlim_t) 0;
-
-			while ((c = *p++) >= '0' && c <= '9')
-			{
-				val = (val * 10) + (long)(c - '0');
-				if (val < (rlim_t) 0)
-					break;
-			}
-			if (c)
-				error("bad number");
-			val *= l->factor;
-		}
-	}
-	if (all) {
-		for (l = limits; l->name; l++) {
-			getrlimit(l->cmd, &limit);
-			if (how & SOFT)
-				val = limit.rlim_cur;
-			else if (how & HARD)
-				val = limit.rlim_max;
-
-			out1fmt("%-20s ", l->name);
-			if (val == RLIM_INFINITY)
-				out1fmt("unlimited\n");
-			else
-			{
-				val /= l->factor;
-#ifdef BSD4_4
-				out1fmt("%lld\n", (long long) val);
-#else
-				out1fmt("%ld\n", (long) val);
-#endif
-			}
-		}
-		return 0;
-	}
-
-	getrlimit(l->cmd, &limit);
-	if (set) {
-		if (how & HARD)
-			limit.rlim_max = val;
-		if (how & SOFT)
-			limit.rlim_cur = val;
-		if (setrlimit(l->cmd, &limit) < 0)
-			error("error setting limit (%s)", strerror(errno));
-	} else {
-		if (how & SOFT)
-			val = limit.rlim_cur;
-		else if (how & HARD)
-			val = limit.rlim_max;
-
-		if (val == RLIM_INFINITY)
-			out1fmt("unlimited\n");
-		else
-		{
-			val /= l->factor;
-#ifdef BSD4_4
-			out1fmt("%lld\n", (long long) val);
-#else
-			out1fmt("%ld\n", (long) val);
-#endif
-		}
-	}
-	return 0;
-}
diff --git a/src/ash/miscbltin.h b/src/ash/miscbltin.h
deleted file mode 100644
index 4c12c82..0000000
--- a/src/ash/miscbltin.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*	$NetBSD: miscbltin.h,v 1.3 2003/08/21 17:57:53 christos Exp $	*/
-
-/*
- * Copyright (c) 1997 Christos Zoulas.  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. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
- */
-
-int readcmd(int, char **);
-int umaskcmd(int, char **);
-int ulimitcmd(int, char **);
diff --git a/src/ash/mkbuiltins b/src/ash/mkbuiltins
deleted file mode 100755
index 607c5c9..0000000
--- a/src/ash/mkbuiltins
+++ /dev/null
@@ -1,138 +0,0 @@
-#!/bin/sh -
-#	$NetBSD: mkbuiltins,v 1.21 2004/06/06 07:03:11 christos Exp $
-#
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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 the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)mkbuiltins	8.2 (Berkeley) 5/4/95
-
-havehist=1
-if [ "X$1" = "X-h" ]; then
-	havehist=0
-	shift
-fi
-
-shell=$1
-builtins=$2
-objdir=$3
-
-havejobs=0
-if grep '^#define JOBS[	 ]*1' ${shell} > /dev/null
-then
-	havejobs=1
-fi
-
-exec <$builtins 3> ${objdir}/builtins.c 4> ${objdir}/builtins.h
-
-echo '/*
- * This file was generated by the mkbuiltins program.
- */
-
-#include "shell.h"
-#include "builtins.h"
-
-const struct builtincmd builtincmd[] = {
-' >&3
-
-echo '/*
- * This file was generated by the mkbuiltins program.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-
-struct builtincmd {
-      const char *name;
-      int (*builtin)(int, char **);
-};
-
-extern const struct builtincmd builtincmd[];
-extern const struct builtincmd splbltincmd[];
-
-' >&4
-
-specials=
-
-while read line
-do
-	set -- $line
-	[ -z "$1" ] && continue
-	case "$1" in
-	\#if*|\#def*|\#end*)
-		echo $line >&3
-		echo $line >&4
-		continue
-		;;
-	esac
-	l1="${line###}"
-	[ "$l1" != "$line" ] && continue
-
-
-	func=$1
-	shift
-	[ x"$1" = x'-j' ] && {
-		[ $havejobs = 0 ] && continue
-		shift
-	}
-	[ x"$1" = x'-h' ] && {
-		[ $havehist = 0 ] && continue
-		shift
-	}
-	echo 'int '"$func"'(int, char **);' >&4
-	while
-		[ $# != 0 -a "$1" != '#' ]
-	do
-		[ "$1" = '-s' ] && {
-			specials="$specials $2 $func"
-			shift 2
-			continue;
-		}
-		[ "$1" = '-u' ] && shift
-		echo '	{ "'$1'",	'"$func"' },' >&3
-		shift
-	done
-done
-
-echo '	{ 0, 0 },' >&3
-echo '};' >&3
-echo >&3
-echo 'const struct builtincmd splbltincmd[] = {' >&3
-
-set -- $specials
-while
-	[ $# != 0 ]
-do
-	echo '	{ "'$1'",	'"$2"' },' >&3
-	shift 2
-done
-
-echo '	{ 0, 0 },' >&3
-echo "};" >&3
diff --git a/src/ash/mkinit.sh b/src/ash/mkinit.sh
deleted file mode 100755
index cae27dd..0000000
--- a/src/ash/mkinit.sh
+++ /dev/null
@@ -1,197 +0,0 @@
-#! /bin/sh
-#	$NetBSD: mkinit.sh,v 1.2 2004/06/15 23:09:54 dsl Exp $
-
-# Copyright (c) 2003 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# This code is derived from software contributed to The NetBSD Foundation
-# by David Laight.
-#
-# 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 The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
-
-srcs="$*"
-
-nl='
-'
-openparen='('
-backslash='\'
-
-includes=' "shell.h" "mystring.h" "init.h" '
-defines=
-decles=
-event_init=
-event_reset=
-event_shellproc=
-
-for src in $srcs; do
-	exec <$src
-	decnl="$nl"
-	while IFS=; read -r line; do
-		[ "$line" = x ]
-		case "$line " in
-		INIT["{ 	"]* ) event=init;;
-		RESET["{ 	"]* ) event=reset;;
-		SHELLPROC["{ 	"]* ) event=shellproc;;
-		INCLUDE[\ \	]* )
-			IFS=' 	'
-			set -- $line
-			# ignore duplicates
-			[ "${includes}" != "${includes%* $2 }" ] && continue
-			includes="$includes$2 "
-			continue
-			;;
-		MKINIT\  )
-			# struct declaration
-			decles="$decles$nl"
-			while
-				read -r line
-				decles="${decles}${line}${nl}"
-				[ "$line" != "};" ]
-			do
-				:
-			done
-			decnl="$nl"
-			continue
-			;;
-		MKINIT["{ 	"]* )
-			# strip initialiser
-			def=${line#MKINIT}
-			comment="${def#*;}"
-			def="${def%;$comment}"
-			def="${def%%=*}"
-			def="${def% }"
-			decles="${decles}${decnl}extern${def};${comment}${nl}"
-			decnl=
-			continue
-			;;
-		\#define[\ \	]* )
-			IFS=' 	'
-			set -- $line
-			# Ignore those with arguments
-			[ "$2" = "${2##*$openparen}" ] || continue
-			# and multiline definitions
-			[ "$line" = "${line%$backslash}" ] || continue
-			defines="${defines}#undef  $2${nl}${line}${nl}"
-			continue
-			;;
-		* ) continue;;
-		esac
-		# code for events
-		ev="${nl}      /* from $src: */${nl}      {${nl}"
-		while
-			read -r line
-			[ "$line" != "}" ]
-		do
-			# The C program indented by an extra 6 chars using
-			# tabs then spaces. I need to compare the output :-(
-			indent=6
-			while
-				l=${line#	}
-				[ "$l" != "$line" ]
-			do
-				indent=$(($indent + 8))
-				line="$l"
-			done
-			while
-				l=${line# }
-				[ "$l" != "$line" ]
-			do
-				indent=$(($indent + 1))
-				line="$l"
-			done
-			[ -z "$line" -o "$line" != "${line###}" ] && indent=0
-			while
-				[ $indent -ge 8 ]
-			do
-				ev="$ev	"
-				indent="$(($indent - 8))"
-			done
-			while
-				[ $indent -gt 0 ]
-			do
-				ev="$ev "
-				indent="$(($indent - 1))"
-			done
-			ev="${ev}${line}${nl}"
-		done
-		ev="${ev}      }${nl}"
-		eval event_$event=\"\$event_$event\$ev\"
-	done
-done
-
-exec >init.c.tmp
-
-echo "/*"
-echo " * This file was generated by the mkinit program."
-echo " */"
-echo
-
-IFS=' '
-for f in $includes; do
-	echo "#include $f"
-done
-
-echo
-echo
-echo
-echo "$defines"
-echo
-echo "$decles"
-echo
-echo
-echo "/*"
-echo " * Initialization code."
-echo " */"
-echo
-echo "void"
-echo "init() {"
-echo "${event_init%$nl}"
-echo "}"
-echo
-echo
-echo
-echo "/*"
-echo " * This routine is called when an error or an interrupt occurs in an"
-echo " * interactive shell and control is returned to the main command loop."
-echo " */"
-echo
-echo "void"
-echo "reset() {"
-echo "${event_reset%$nl}"
-echo "}"
-echo
-echo
-echo
-echo "/*"
-echo " * This routine is called to initialize the shell to run a shell procedure."
-echo " */"
-echo
-echo "void"
-echo "initshellproc() {"
-echo "${event_shellproc%$nl}"
-echo "}"
-
-exec >&-
-mv init.c.tmp init.c
diff --git a/src/ash/mknodes.sh b/src/ash/mknodes.sh
deleted file mode 100755
index c95bdf6..0000000
--- a/src/ash/mknodes.sh
+++ /dev/null
@@ -1,217 +0,0 @@
-#! /bin/sh
-#	$NetBSD: mknodes.sh,v 1.1 2004/01/16 23:24:38 dsl Exp $
-
-# Copyright (c) 2003 The NetBSD Foundation, Inc.
-# All rights reserved.
-#
-# This code is derived from software contributed to The NetBSD Foundation
-# by David Laight.
-#
-# 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 The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
-
-nodetypes=$1
-nodes_pat=$2
-objdir="$3"
-
-exec <$nodetypes
-exec >$objdir/nodes.h.tmp
-
-echo "/*"
-echo " * This file was generated by mknodes.sh"
-echo " */"
-echo
-
-tagno=0
-while IFS=; read -r line; do
-	line="${line%%#*}"
-	IFS=' 	'
-	set -- $line
-	IFS=
-	[ -z "$2" ] && continue
-	case "$line" in
-	[" 	"]* )
-		IFS=' '
-		[ $field = 0 ] && struct_list="$struct_list $struct"
-		eval field_${struct}_$field=\"\$*\"
-		eval numfld_$struct=\$field
-		field=$(($field + 1))
-		;;
-	* )
-		define=$1
-		struct=$2
-		echo "#define $define $tagno"
-		tagno=$(($tagno + 1))
-		eval define_$struct=\"\$define_$struct \$define\"
-		struct_define="$struct_define $struct"
-		field=0
-		;;
-	esac
-done
-
-echo
-
-IFS=' '
-for struct in $struct_list; do
-	echo
-	echo
-	echo "struct $struct {"
-	field=0
-	while
-		eval line=\"\$field_${struct}_$field\"
-		field=$(($field + 1))
-		[ -n "$line" ]
-	do
-		IFS=' '
-		set -- $line
-		name=$1
-		case $2 in
-		nodeptr ) type="union node *";;
-		nodelist ) type="struct nodelist *";;
-		string ) type="char *";;
-		int ) type="int ";;
-		* ) name=; shift 2; type="$*";;
-		esac
-		echo "      $type$name;"
-	done
-	echo "};"
-done
-
-echo
-echo
-echo "union node {"
-echo "      int type;"
-for struct in $struct_list; do
-	echo "      struct $struct $struct;"
-done
-echo "};"
-echo
-echo
-echo "struct nodelist {"
-echo "	struct nodelist *next;"
-echo "	union node *n;"
-echo "};"
-echo
-echo
-echo "union node *copyfunc(union node *);"
-echo "void freefunc(union node *);"
-
-exec <$nodes_pat
-exec >$objdir/nodes.c.tmp
-mv -f $objdir/nodes.h.tmp $objdir/nodes.h || exit 1
-
-echo "/*"
-echo " * This file was generated by mknodes.sh"
-echo " */"
-echo
-
-while IFS=; read -r line; do
-	IFS=' 	'
-	set -- $line
-	IFS=
-	case "$1" in
-	'%SIZES' )
-		echo "static const short nodesize[$tagno] = {"
-		IFS=' '
-		for struct in $struct_define; do
-			echo "      SHELL_ALIGN(sizeof (struct $struct)),"
-		done
-		echo "};"
-		;;
-	'%CALCSIZE' )
-		echo "      if (n == NULL)"
-		echo "	    return;"
-		echo "      funcblocksize += nodesize[n->type];"
-		echo "      switch (n->type) {"
-		IFS=' '
-		for struct in $struct_list; do
-			eval defines=\"\$define_$struct\"
-			for define in $defines; do
-				echo "      case $define:"
-			done
-			eval field=\$numfld_$struct
-			while
-				[ $field != 0 ]
-			do
-				eval line=\"\$field_${struct}_$field\"
-				field=$(($field - 1))
-				IFS=' '
-				set -- $line
-				name=$1
-				cl=")"
-				case $2 in
-				nodeptr ) fn=calcsize;;
-				nodelist ) fn=sizenodelist;;
-				string ) fn="funcstringsize += strlen"
-					cl=") + 1";;
-				* ) continue;;
-				esac
-				echo "	    ${fn}(n->$struct.$name${cl};"
-			done
-			echo "	    break;"
-		done
-		echo "      };"
-		;;
-	'%COPY' )
-		echo "      if (n == NULL)"
-		echo "	    return NULL;"
-		echo "      new = funcblock;"
-		echo "      funcblock = (char *) funcblock + nodesize[n->type];"
-		echo "      switch (n->type) {"
-		IFS=' '
-		for struct in $struct_list; do
-			eval defines=\"\$define_$struct\"
-			for define in $defines; do
-				echo "      case $define:"
-			done
-			eval field=\$numfld_$struct
-			while
-				[ $field != 0 ]
-			do
-				eval line=\"\$field_${struct}_$field\"
-				field=$(($field - 1))
-				IFS=' '
-				set -- $line
-				name=$1
-				case $2 in
-				nodeptr ) fn="copynode(";;
-				nodelist ) fn="copynodelist(";;
-				string ) fn="nodesavestr(";;
-				int ) fn=;;
-				* ) continue;;
-				esac
-				f="$struct.$name"
-				echo "	    new->$f = ${fn}n->$f${fn:+)};"
-			done
-			echo "	    break;"
-		done
-		echo "      };"
-		echo "      new->type = n->type;"
-		;;
-	* ) echo "$line";;
-	esac
-done
-
-exec >/dev/null
-mv -f $objdir/nodes.c.tmp $objdir/nodes.c || exit 1
diff --git a/src/ash/mktokens b/src/ash/mktokens
deleted file mode 100755
index 74d2a95..0000000
--- a/src/ash/mktokens
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/sh -
-#	$NetBSD: mktokens,v 1.10 2003/08/22 11:22:23 agc Exp $
-#
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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 the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)mktokens	8.1 (Berkeley) 5/31/93
-
-# The following is a list of tokens.  The second column is nonzero if the
-# token marks the end of a list.  The third column is the name to print in
-# error messages.
-
-if [ -z "$TMPDIR" ]; then
-    TMPDIR="/tmp"
-    export TMPDIR
-fi
-F="$TMPDIR/ka$$"
-echo $F
-cat > $F <<\!
-TEOF	1	end of file
-TNL	0	newline
-TSEMI	0	";"
-TBACKGND 0	"&"
-TAND	0	"&&"
-TOR	0	"||"
-TPIPE	0	"|"
-TLP	0	"("
-TRP	1	")"
-TENDCASE 1	";;"
-TENDBQUOTE 1	"`"
-TREDIR	0	redirection
-TWORD	0	word
-TIF	0	"if"
-TTHEN	1	"then"
-TELSE	1	"else"
-TELIF	1	"elif"
-TFI	1	"fi"
-TWHILE	0	"while"
-TUNTIL	0	"until"
-TFOR	0	"for"
-TDO	1	"do"
-TDONE	1	"done"
-TBEGIN	0	"{"
-TEND	1	"}"
-TCASE	0	"case"
-TESAC	1	"esac"
-TNOT	0	"!"
-!
-nl=`wc -l $F`
-exec > token.h
-awk '{print "#define " $1 " " NR-1}' $F
-echo '
-/* Array indicating which tokens mark the end of a list */
-const char tokendlist[] = {'
-awk '{print "\t" $2 ","}' $F
-echo '};
-
-const char *const tokname[] = {'
-sed -e 's/"/\\"/g' \
-    -e 's/[^	 ]*[	 ][	 ]*[^	 ]*[	 ][	 ]*\(.*\)/	"\1",/' \
-    $F
-echo '};
-'
-sed 's/"//g' $F | awk '
-/TIF/{print "#define KWDOFFSET " NR-1; print "";
-      print "const char *const parsekwd[] = {"}
-/TIF/,/neverfound/{print "	\"" $3 "\","}'
-echo '	0
-};'
-
-rm $F
diff --git a/src/ash/myhistedit.h b/src/ash/myhistedit.h
deleted file mode 100644
index 417e5d0..0000000
--- a/src/ash/myhistedit.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*	$NetBSD: myhistedit.h,v 1.10 2003/08/07 09:05:35 agc Exp $	*/
-
-/*-
- * Copyright (c) 1993
- *	The Regents of the University of California.  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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)myhistedit.h	8.2 (Berkeley) 5/4/95
- */
-
-#ifndef SMALL
-#include <histedit.h>
-
-extern History *hist;
-extern EditLine *el;
-#endif
-extern int displayhist;
-
-void histedit(void);
-void sethistsize(const char *);
-void setterm(const char *);
-int histcmd(int, char **);
-int inputrc(int, char **);
-int not_fcnumber(char *);
-int str_to_event(const char *, int);
-
diff --git a/src/ash/mystring.c b/src/ash/mystring.c
deleted file mode 100644
index c1af6c0..0000000
--- a/src/ash/mystring.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*	$NetBSD: mystring.c,v 1.16 2003/08/07 09:05:35 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)mystring.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: mystring.c,v 1.16 2003/08/07 09:05:35 agc Exp $");
-#endif
-#endif /* not lint */
-
-/*
- * String functions.
- *
- *	equal(s1, s2)		Return true if strings are equal.
- *	scopy(from, to)		Copy a string.
- *	scopyn(from, to, n)	Like scopy, but checks for overflow.
- *	number(s)		Convert a string of digits to an integer.
- *	is_number(s)		Return true if s is a string of digits.
- */
-
-#include <stdlib.h>
-#include "shell.h"
-#include "syntax.h"
-#include "error.h"
-#include "mystring.h"
-
-
-char nullstr[1];		/* zero length string */
-
-/*
- * equal - #defined in mystring.h
- */
-
-/*
- * scopy - #defined in mystring.h
- */
-
-
-/*
- * scopyn - copy a string from "from" to "to", truncating the string
- *		if necessary.  "To" is always nul terminated, even if
- *		truncation is performed.  "Size" is the size of "to".
- */
-
-void
-scopyn(const char *from, char *to, int size)
-{
-
-	while (--size > 0) {
-		if ((*to++ = *from++) == '\0')
-			return;
-	}
-	*to = '\0';
-}
-
-
-/*
- * prefix -- see if pfx is a prefix of string.
- */
-
-int
-prefix(const char *pfx, const char *string)
-{
-	while (*pfx) {
-		if (*pfx++ != *string++)
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Convert a string of digits to an integer, printing an error message on
- * failure.
- */
-
-int
-number(const char *s)
-{
-
-	if (! is_number(s))
-		error("Illegal number: %s", s);
-	return atoi(s);
-}
-
-
-
-/*
- * Check for a valid number.  This should be elsewhere.
- */
-
-int
-is_number(const char *p)
-{
-	do {
-		if (! is_digit(*p))
-			return 0;
-	} while (*++p != '\0');
-	return 1;
-}
diff --git a/src/ash/mystring.h b/src/ash/mystring.h
deleted file mode 100644
index 08a73e9..0000000
--- a/src/ash/mystring.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$NetBSD: mystring.h,v 1.11 2003/08/07 09:05:35 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)mystring.h	8.2 (Berkeley) 5/4/95
- */
-
-#include <string.h>
-
-void scopyn(const char *, char *, int);
-int prefix(const char *, const char *);
-int number(const char *);
-int is_number(const char *);
-
-#define equal(s1, s2)	(strcmp(s1, s2) == 0)
-#define scopy(s1, s2)	((void)strcpy(s2, s1))
diff --git a/src/ash/nodes.c.pat b/src/ash/nodes.c.pat
deleted file mode 100644
index e619a01..0000000
--- a/src/ash/nodes.c.pat
+++ /dev/null
@@ -1,166 +0,0 @@
-/*	$NetBSD: nodes.c.pat,v 1.12 2004/06/15 22:57:27 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)nodes.c.pat	8.2 (Berkeley) 5/4/95
- */
-
-#include <stdlib.h>
-/*
- * Routine for dealing with parsed shell commands.
- */
-
-#include "shell.h"
-#include "nodes.h"
-#include "memalloc.h"
-#include "machdep.h"
-#include "mystring.h"
-
-
-int     funcblocksize;		/* size of structures in function */
-int     funcstringsize;		/* size of strings in node */
-pointer funcblock;		/* block to allocate function from */
-char   *funcstring;		/* block to allocate strings from */
-
-%SIZES
-
-
-STATIC void calcsize(union node *);
-STATIC void sizenodelist(struct nodelist *);
-STATIC union node *copynode(union node *);
-STATIC struct nodelist *copynodelist(struct nodelist *);
-STATIC char *nodesavestr(char *);
-
-
-
-/*
- * Make a copy of a parse tree.
- */
-
-union node *
-copyfunc(n)
-	union node *n;
-{
-	if (n == NULL)
-		return NULL;
-	funcblocksize = 0;
-	funcstringsize = 0;
-	calcsize(n);
-	funcblock = ckmalloc(funcblocksize + funcstringsize);
-	funcstring = (char *) funcblock + funcblocksize;
-	return copynode(n);
-}
-
-
-
-STATIC void
-calcsize(n)
-	union node *n;
-{
-	%CALCSIZE
-}
-
-
-
-STATIC void
-sizenodelist(lp)
-	struct nodelist *lp;
-{
-	while (lp) {
-		funcblocksize += SHELL_ALIGN(sizeof(struct nodelist));
-		calcsize(lp->n);
-		lp = lp->next;
-	}
-}
-
-
-
-STATIC union node *
-copynode(n)
-	union node *n;
-{
-	union node *new;
-
-	%COPY
-	return new;
-}
-
-
-STATIC struct nodelist *
-copynodelist(lp)
-	struct nodelist *lp;
-{
-	struct nodelist *start;
-	struct nodelist **lpp;
-
-	lpp = &start;
-	while (lp) {
-		*lpp = funcblock;
-		funcblock = (char *) funcblock +
-		    SHELL_ALIGN(sizeof(struct nodelist));
-		(*lpp)->n = copynode(lp->n);
-		lp = lp->next;
-		lpp = &(*lpp)->next;
-	}
-	*lpp = NULL;
-	return start;
-}
-
-
-
-STATIC char *
-nodesavestr(s)
-	char   *s;
-{
-	register char *p = s;
-	register char *q = funcstring;
-	char   *rtn = funcstring;
-
-	while ((*q++ = *p++) != 0)
-		continue;
-	funcstring = q;
-	return rtn;
-}
-
-
-
-/*
- * Free a parse tree.
- */
-
-void
-freefunc(n)
-	union node *n;
-{
-	if (n)
-		ckfree(n);
-}
diff --git a/src/ash/nodetypes b/src/ash/nodetypes
deleted file mode 100644
index 4adebc0..0000000
--- a/src/ash/nodetypes
+++ /dev/null
@@ -1,143 +0,0 @@
-#	$NetBSD: nodetypes,v 1.12 2003/08/22 11:22:23 agc Exp $
-# Copyright (c) 1991, 1993
-#	The Regents of the University of California.  All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# 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 the University 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 REGENTS 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 REGENTS 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.
-#
-#	@(#)nodetypes	8.2 (Berkeley) 5/4/95
-
-# This file describes the nodes used in parse trees.  Unindented lines
-# contain a node type followed by a structure tag.  Subsequent indented
-# lines specify the fields of the structure.  Several node types can share
-# the same structure, in which case the fields of the structure should be
-# specified only once.
-#
-# A field of a structure is described by the name of the field followed
-# by a type.  The currently implemented types are:
-#	nodeptr - a pointer to a node
-#	nodelist - a pointer to a list of nodes
-#	string - a pointer to a nul terminated string
-#	int - an integer
-#	other - any type that can be copied by assignment
-#	temp - a field that doesn't have to be copied when the node is copied
-# The last two types should be followed by the text of a C declaration for
-# the field.
-
-NSEMI nbinary			# two commands separated by a semicolon
-	type	  int
-	ch1	  nodeptr		# the first child
-	ch2	  nodeptr		# the second child
-
-NCMD ncmd			# a simple command
-	type	  int
-	backgnd	  int			# set to run command in background
-	args	  nodeptr		# the arguments
-	redirect  nodeptr		# list of file redirections
-
-NPIPE npipe			# a pipeline
-	type	  int
-	backgnd	  int			# set to run pipeline in background
-	cmdlist	  nodelist		# the commands in the pipeline
-
-NREDIR nredir			# redirection (of a complex command)
-	type	  int
-	n	  nodeptr		# the command
-	redirect  nodeptr		# list of file redirections
-
-NBACKGND nredir			# run command in background
-NSUBSHELL nredir		# run command in a subshell
-
-NAND nbinary			# the && operator
-NOR nbinary			# the || operator
-
-NIF nif				# the if statement.  Elif clauses are handled
-	type	  int		    # using multiple if nodes.
-	test	  nodeptr		# if test
-	ifpart	  nodeptr		# then ifpart
-	elsepart  nodeptr		# else elsepart
-
-NWHILE nbinary			# the while statement.  First child is the test
-NUNTIL nbinary			# the until statement
-
-NFOR nfor			# the for statement
-	type	  int
-	args	  nodeptr		# for var in args
-	body	  nodeptr		# do body; done
-	var	  string		# the for variable
-
-NCASE ncase			# a case statement
-	type	  int
-	expr	  nodeptr		# the word to switch on
-	cases	  nodeptr		# the list of cases (NCLIST nodes)
-
-NCLIST nclist			# a case
-	type	  int
-	next	  nodeptr		# the next case in list
-	pattern	  nodeptr		# list of patterns for this case
-	body	  nodeptr		# code to execute for this case
-
-
-NDEFUN narg			# define a function.  The "next" field contains
-				# the body of the function.
-
-NARG narg			# represents a word
-	type	  int
-	next	  nodeptr		# next word in list
-	text	  string		# the text of the word
-	backquote nodelist		# list of commands in back quotes
-
-NTO nfile			# fd> fname
-NCLOBBER nfile			# fd>| fname
-NFROM nfile			# fd< fname
-NFROMTO nfile			# fd<> fname
-NAPPEND nfile			# fd>> fname
-	type	  int
-	next	  nodeptr		# next redirection in list
-	fd	  int			# file descriptor being redirected
-	fname	  nodeptr		# file name, in a NARG node
-	expfname  temp	char *expfname	# actual file name
-
-NTOFD ndup			# fd<&dupfd
-NFROMFD ndup			# fd>&dupfd
-	type	  int
-	next	  nodeptr		# next redirection in list
-	fd	  int			# file descriptor being redirected
-	dupfd	  int			# file descriptor to duplicate
-	vname	  nodeptr		# file name if fd>&$var
-
-
-NHERE nhere			# fd<<\!
-NXHERE nhere			# fd<<!
-	type	  int
-	next	  nodeptr		# next redirection in list
-	fd	  int			# file descriptor being redirected
-	doc	  nodeptr		# input to command (NARG node)
-
-NNOT nnot			# ! command  (actually pipeline)
-	type	int
-	com	nodeptr
diff --git a/src/ash/options.c b/src/ash/options.c
deleted file mode 100644
index eba6e9d..0000000
--- a/src/ash/options.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/*	$NetBSD: options.c,v 1.38 2005/03/20 21:38:17 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)options.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: options.c,v 1.38 2005/03/20 21:38:17 dsl Exp $");
-#endif
-#endif /* not lint */
-
-#include <signal.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "shell.h"
-#define DEFINE_OPTIONS
-#include "options.h"
-#undef DEFINE_OPTIONS
-#include "nodes.h"	/* for other header files */
-#include "eval.h"
-#include "jobs.h"
-#include "input.h"
-#include "output.h"
-#include "trap.h"
-#include "var.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#ifndef SMALL
-#include "myhistedit.h"
-#endif
-#include "show.h"
-
-char *arg0;			/* value of $0 */
-struct shparam shellparam;	/* current positional parameters */
-char **argptr;			/* argument list for builtin commands */
-char *optionarg;		/* set by nextopt (like getopt) */
-char *optptr;			/* used by nextopt */
-
-char *minusc;			/* argument to -c option */
-
-
-STATIC void options(int);
-STATIC void minus_o(char *, int);
-STATIC void setoption(int, int);
-STATIC int getopts(char *, char *, char **, char ***, char **);
-
-
-/*
- * Process the shell command line arguments.
- */
-
-void
-procargs(int argc, char **argv)
-{
-	int i;
-
-	argptr = argv;
-	if (argc > 0)
-		argptr++;
-	for (i = 0; i < NOPTS; i++)
-		optlist[i].val = 2;
-	options(1);
-	if (*argptr == NULL && minusc == NULL)
-		sflag = 1;
-	if (iflag == 2 && sflag == 1 && isatty(0) && isatty(1))
-		iflag = 1;
-	if (mflag == 2)
-		mflag = iflag;
-	for (i = 0; i < NOPTS; i++)
-		if (optlist[i].val == 2)
-			optlist[i].val = 0;
-#if DEBUG == 2
-	debug = 1;
-#endif
-	arg0 = argv[0];
-	if (sflag == 0 && minusc == NULL) {
-		commandname = argv[0];
-		arg0 = *argptr++;
-		setinputfile(arg0, 0);
-		commandname = arg0;
-	}
-	/* POSIX 1003.2: first arg after -c cmd is $0, remainder $1... */
-	if (minusc != NULL) {
-		if (argptr == NULL || *argptr == NULL)
-			error("Bad -c option");
-		minusc = *argptr++;
-		if (*argptr != 0)
-			arg0 = *argptr++;
-	}
-
-	shellparam.p = argptr;
-	shellparam.reset = 1;
-	/* assert(shellparam.malloc == 0 && shellparam.nparam == 0); */
-	while (*argptr) {
-		shellparam.nparam++;
-		argptr++;
-	}
-	optschanged();
-}
-
-
-void
-optschanged(void)
-{
-	setinteractive(iflag);
-#ifndef SMALL
-	histedit();
-#endif
-	setjobctl(mflag);
-}
-
-/*
- * Process shell options.  The global variable argptr contains a pointer
- * to the argument list; we advance it past the options.
- */
-
-STATIC void
-options(int cmdline)
-{
-	static char empty[] = "";
-	char *p;
-	int val;
-	int c;
-
-	if (cmdline)
-		minusc = NULL;
-	while ((p = *argptr) != NULL) {
-		argptr++;
-		if ((c = *p++) == '-') {
-			val = 1;
-                        if (p[0] == '\0' || (p[0] == '-' && p[1] == '\0')) {
-                                if (!cmdline) {
-                                        /* "-" means turn off -x and -v */
-                                        if (p[0] == '\0')
-                                                xflag = vflag = 0;
-                                        /* "--" means reset params */
-                                        else if (*argptr == NULL)
-						setparam(argptr);
-                                }
-				break;	  /* "-" or  "--" terminates options */
-			}
-		} else if (c == '+') {
-			val = 0;
-		} else {
-			argptr--;
-			break;
-		}
-		while ((c = *p++) != '\0') {
-			if (c == 'c' && cmdline) {
-				/* command is after shell args*/
-				minusc = empty;
-			} else if (c == 'o') {
-				minus_o(*argptr, val);
-				if (*argptr)
-					argptr++;
-			} else {
-				setoption(c, val);
-			}
-		}
-	}
-}
-
-static void
-set_opt_val(int i, int val)
-{
-	int j;
-	int flag;
-
-	if (val && (flag = optlist[i].opt_set)) {
-		/* some options (eg vi/emacs) are mutually exclusive */
-		for (j = 0; j < NOPTS; j++)
-		    if (optlist[j].opt_set == flag)
-			optlist[j].val = 0;
-	}
-	optlist[i].val = val;
-#ifdef DEBUG
-	if (&optlist[i].val == &debug)
-		opentrace();
-#endif
-}
-
-STATIC void
-minus_o(char *name, int val)
-{
-	int i;
-
-	if (name == NULL) {
-		out1str("Current option settings\n");
-		for (i = 0; i < NOPTS; i++)
-			out1fmt("%-16s%s\n", optlist[i].name,
-				optlist[i].val ? "on" : "off");
-	} else {
-		for (i = 0; i < NOPTS; i++)
-			if (equal(name, optlist[i].name)) {
-				set_opt_val(i, val);
-				return;
-			}
-		error("Illegal option -o %s", name);
-	}
-}
-
-
-STATIC void
-setoption(int flag, int val)
-{
-	int i;
-
-	for (i = 0; i < NOPTS; i++)
-		if (optlist[i].letter == flag) {
-			set_opt_val( i, val );
-			return;
-		}
-	error("Illegal option -%c", flag);
-	/* NOTREACHED */
-}
-
-
-
-#ifdef mkinit
-INCLUDE "options.h"
-
-SHELLPROC {
-	int i;
-
-	for (i = 0; optlist[i].name; i++)
-		optlist[i].val = 0;
-	optschanged();
-
-}
-#endif
-
-
-/*
- * Set the shell parameters.
- */
-
-void
-setparam(char **argv)
-{
-	char **newparam;
-	char **ap;
-	int nparam;
-
-	for (nparam = 0 ; argv[nparam] ; nparam++)
-		continue;
-	ap = newparam = ckmalloc((nparam + 1) * sizeof *ap);
-	while (*argv) {
-		*ap++ = savestr(*argv++);
-	}
-	*ap = NULL;
-	freeparam(&shellparam);
-	shellparam.malloc = 1;
-	shellparam.nparam = nparam;
-	shellparam.p = newparam;
-	shellparam.optnext = NULL;
-}
-
-
-/*
- * Free the list of positional parameters.
- */
-
-void
-freeparam(volatile struct shparam *param)
-{
-	char **ap;
-
-	if (param->malloc) {
-		for (ap = param->p ; *ap ; ap++)
-			ckfree(*ap);
-		ckfree(param->p);
-	}
-}
-
-
-
-/*
- * The shift builtin command.
- */
-
-int
-shiftcmd(int argc, char **argv)
-{
-	int n;
-	char **ap1, **ap2;
-
-	n = 1;
-	if (argc > 1)
-		n = number(argv[1]);
-	if (n > shellparam.nparam)
-		error("can't shift that many");
-	INTOFF;
-	shellparam.nparam -= n;
-	for (ap1 = shellparam.p ; --n >= 0 ; ap1++) {
-		if (shellparam.malloc)
-			ckfree(*ap1);
-	}
-	ap2 = shellparam.p;
-	while ((*ap2++ = *ap1++) != NULL);
-	shellparam.optnext = NULL;
-	INTON;
-	return 0;
-}
-
-
-
-/*
- * The set command builtin.
- */
-
-int
-setcmd(int argc, char **argv)
-{
-	if (argc == 1)
-		return showvars(0, 0, 1);
-	INTOFF;
-	options(0);
-	optschanged();
-	if (*argptr != NULL) {
-		setparam(argptr);
-	}
-	INTON;
-	return 0;
-}
-
-
-void
-getoptsreset(value)
-	const char *value;
-{
-	if (number(value) == 1) {
-		shellparam.optnext = NULL;
-		shellparam.reset = 1;
-	}
-}
-
-/*
- * The getopts builtin.  Shellparam.optnext points to the next argument
- * to be processed.  Shellparam.optptr points to the next character to
- * be processed in the current argument.  If shellparam.optnext is NULL,
- * then it's the first time getopts has been called.
- */
-
-int
-getoptscmd(int argc, char **argv)
-{
-	char **optbase;
-
-	if (argc < 3)
-		error("usage: getopts optstring var [arg]");
-	else if (argc == 3)
-		optbase = shellparam.p;
-	else
-		optbase = &argv[3];
-
-	if (shellparam.reset == 1) {
-		shellparam.optnext = optbase;
-		shellparam.optptr = NULL;
-		shellparam.reset = 0;
-	}
-
-	return getopts(argv[1], argv[2], optbase, &shellparam.optnext,
-		       &shellparam.optptr);
-}
-
-STATIC int
-getopts(char *optstr, char *optvar, char **optfirst, char ***optnext, char **optpptr)
-{
-	char *p, *q;
-	char c = '?';
-	int done = 0;
-	int ind = 0;
-	int err = 0;
-	char s[12];
-
-	if ((p = *optpptr) == NULL || *p == '\0') {
-		/* Current word is done, advance */
-		if (*optnext == NULL)
-			return 1;
-		p = **optnext;
-		if (p == NULL || *p != '-' || *++p == '\0') {
-atend:
-			ind = *optnext - optfirst + 1;
-			*optnext = NULL;
-			p = NULL;
-			done = 1;
-			goto out;
-		}
-		(*optnext)++;
-		if (p[0] == '-' && p[1] == '\0')	/* check for "--" */
-			goto atend;
-	}
-
-	c = *p++;
-	for (q = optstr; *q != c; ) {
-		if (*q == '\0') {
-			if (optstr[0] == ':') {
-				s[0] = c;
-				s[1] = '\0';
-				err |= setvarsafe("OPTARG", s, 0);
-			} else {
-				outfmt(&errout, "Illegal option -%c\n", c);
-				(void) unsetvar("OPTARG", 0);
-			}
-			c = '?';
-			goto bad;
-		}
-		if (*++q == ':')
-			q++;
-	}
-
-	if (*++q == ':') {
-		if (*p == '\0' && (p = **optnext) == NULL) {
-			if (optstr[0] == ':') {
-				s[0] = c;
-				s[1] = '\0';
-				err |= setvarsafe("OPTARG", s, 0);
-				c = ':';
-			} else {
-				outfmt(&errout, "No arg for -%c option\n", c);
-				(void) unsetvar("OPTARG", 0);
-				c = '?';
-			}
-			goto bad;
-		}
-
-		if (p == **optnext)
-			(*optnext)++;
-		err |= setvarsafe("OPTARG", p, 0);
-		p = NULL;
-	} else
-		err |= setvarsafe("OPTARG", "", 0);
-	ind = *optnext - optfirst + 1;
-	goto out;
-
-bad:
-	ind = 1;
-	*optnext = NULL;
-	p = NULL;
-out:
-	*optpptr = p;
-	fmtstr(s, sizeof(s), "%d", ind);
-	err |= setvarsafe("OPTIND", s, VNOFUNC);
-	s[0] = c;
-	s[1] = '\0';
-	err |= setvarsafe(optvar, s, 0);
-	if (err) {
-		*optnext = NULL;
-		*optpptr = NULL;
-		output_flushall();
-		exraise(EXERROR);
-	}
-	return done;
-}
-
-/*
- * XXX - should get rid of.  have all builtins use getopt(3).  the
- * library getopt must have the BSD extension static variable "optreset"
- * otherwise it can't be used within the shell safely.
- *
- * Standard option processing (a la getopt) for builtin routines.  The
- * only argument that is passed to nextopt is the option string; the
- * other arguments are unnecessary.  It return the character, or '\0' on
- * end of input.
- */
-
-int
-nextopt(const char *optstring)
-{
-	char *p;
-	const char *q;
-	char c;
-
-	if ((p = optptr) == NULL || *p == '\0') {
-		p = *argptr;
-		if (p == NULL || *p != '-' || *++p == '\0')
-			return '\0';
-		argptr++;
-		if (p[0] == '-' && p[1] == '\0')	/* check for "--" */
-			return '\0';
-	}
-	c = *p++;
-	for (q = optstring ; *q != c ; ) {
-		if (*q == '\0')
-			error("Illegal option -%c", c);
-		if (*++q == ':')
-			q++;
-	}
-	if (*++q == ':') {
-		if (*p == '\0' && (p = *argptr++) == NULL)
-			error("No arg for -%c option", c);
-		optionarg = p;
-		p = NULL;
-	}
-	optptr = p;
-	return c;
-}
diff --git a/src/ash/options.h b/src/ash/options.h
deleted file mode 100644
index 4a08d98..0000000
--- a/src/ash/options.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*	$NetBSD: options.h,v 1.18 2005/05/07 19:52:17 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)options.h	8.2 (Berkeley) 5/4/95
- */
-
-struct shparam {
-	int nparam;		/* # of positional parameters (without $0) */
-	unsigned char malloc;	/* if parameter list dynamically allocated */
-	unsigned char reset;	/* if getopts has been reset */
-	char **p;		/* parameter list */
-	char **optnext;		/* next parameter to be processed by getopts */
-	char *optptr;		/* used by getopts */
-};
-
-
-struct optent {
-	const char *name;		/* for set -o <name> */
-	const char letter;		/* set [+/-]<letter> and $- */
-	const char opt_set;		/* mutually exclusive option set */
-	char val;			/* value of <letter>flag */
-};
-
-/* Those marked [U] are required by posix, but have no effect! */
-
-#ifdef DEFINE_OPTIONS
-#define DEF_OPTS(name, letter, opt_set) {name, letter, opt_set, 0},
-struct optent optlist[] = {
-#else
-#define DEF_OPTS(name, letter, opt_set)
-#endif
-#define DEF_OPT(name,letter) DEF_OPTS(name, letter, 0)
-
-DEF_OPT( "errexit",	'e' )	/* exit on error */
-#define eflag optlist[0].val
-DEF_OPT( "noglob",	'f' )	/* no pathname expansion */
-#define fflag optlist[1].val
-DEF_OPT( "ignoreeof",	'I' )	/* do not exit on EOF */
-#define Iflag optlist[2].val
-DEF_OPT( "interactive",'i' )	/* interactive shell */
-#define iflag optlist[3].val
-DEF_OPT( "monitor",	'm' )	/* job control */
-#define mflag optlist[4].val
-DEF_OPT( "noexec",	'n' )	/* [U] do not exec commands */
-#define nflag optlist[5].val
-DEF_OPT( "stdin",	's' )	/* read from stdin */
-#define sflag optlist[6].val
-DEF_OPT( "xtrace",	'x' )	/* trace after expansion */
-#define xflag optlist[7].val
-DEF_OPT( "verbose",	'v' )	/* trace read input */
-#define vflag optlist[8].val
-DEF_OPTS( "vi",		'V', 'V' )	/* vi style editing */
-#define Vflag optlist[9].val
-DEF_OPTS( "emacs",	'E', 'V' )	/* emacs style editing */
-#define	Eflag optlist[10].val
-DEF_OPT( "noclobber",	'C' )	/* do not overwrite files with > */
-#define	Cflag optlist[11].val
-DEF_OPT( "allexport",	'a' )	/* export all variables */
-#define	aflag optlist[12].val
-DEF_OPT( "notify",	'b' )	/* [U] report completion of background jobs */
-#define	bflag optlist[13].val
-DEF_OPT( "nounset",	'u' )	/* error expansion of unset variables */
-#define	uflag optlist[14].val
-DEF_OPT( "quietprofile", 'q' )
-#define	qflag optlist[15].val
-DEF_OPT( "nolog",	0 )	/* [U] no functon defs in command history */
-#define	nolog optlist[16].val
-DEF_OPT( "cdprint",	0 )	/* always print result of cd */
-#define	cdprint optlist[17].val
-DEF_OPT( "tabcomplete",	0 )	/* <tab> causes filename expansion */
-#define	tabcomplete optlist[18].val
-#ifdef DEBUG
-DEF_OPT( "debug",	0 )	/* enable debug prints */
-#define	debug optlist[19].val
-#endif
-
-#ifdef DEFINE_OPTIONS
-	{ 0, 0, 0, 0 },
-};
-#define NOPTS (sizeof optlist / sizeof optlist[0] - 1)
-int sizeof_optlist = sizeof optlist;
-#else
-extern struct optent optlist[];
-extern int sizeof_optlist;
-#endif
-
-
-extern char *minusc;		/* argument to -c option */
-extern char *arg0;		/* $0 */
-extern struct shparam shellparam;  /* $@ */
-extern char **argptr;		/* argument list for builtin commands */
-extern char *optionarg;		/* set by nextopt */
-extern char *optptr;		/* used by nextopt */
-
-void procargs(int, char **);
-void optschanged(void);
-void setparam(char **);
-void freeparam(volatile struct shparam *);
-int shiftcmd(int, char **);
-int setcmd(int, char **);
-int getoptscmd(int, char **);
-int nextopt(const char *);
-void getoptsreset(const char *);
diff --git a/src/ash/output.c b/src/ash/output.c
deleted file mode 100644
index e667812..0000000
--- a/src/ash/output.c
+++ /dev/null
@@ -1,518 +0,0 @@
-/*	$NetBSD: output.c,v 1.28 2003/08/07 09:05:36 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)output.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: output.c,v 1.28 2003/08/07 09:05:36 agc Exp $");
-#endif
-#endif /* not lint */
-
-/*
- * Shell output routines.  We use our own output routines because:
- *	When a builtin command is interrupted we have to discard
- *		any pending output.
- *	When a builtin command appears in back quotes, we want to
- *		save the output of the command in a region obtained
- *		via malloc, rather than doing a fork and reading the
- *		output of the command via a pipe.
- *	Our output routines may be smaller than the stdio routines.
- */
-
-#include <sys/types.h>		/* quad_t */
-#include <sys/param.h>		/* BSD4_4 */
-#include <sys/ioctl.h>
-
-#include <stdio.h>	/* defines BUFSIZ */
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "shell.h"
-#include "syntax.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-
-
-#define OUTBUFSIZ BUFSIZ
-#define BLOCK_OUT -2		/* output to a fixed block of memory */
-#define MEM_OUT -3		/* output to dynamically allocated memory */
-#define OUTPUT_ERR 01		/* error occurred on output */
-
-
-struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};
-struct output errout = {NULL, 0, NULL, 100, 2, 0};
-struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};
-struct output *out1 = &output;
-struct output *out2 = &errout;
-
-
-
-#ifdef mkinit
-
-INCLUDE "output.h"
-INCLUDE "memalloc.h"
-
-RESET {
-	out1 = &output;
-	out2 = &errout;
-	if (memout.buf != NULL) {
-		ckfree(memout.buf);
-		memout.buf = NULL;
-	}
-}
-
-#endif
-
-
-#ifdef notdef	/* no longer used */
-/*
- * Set up an output file to write to memory rather than a file.
- */
-
-void
-open_mem(char *block, int length, struct output *file)
-{
-	file->nextc = block;
-	file->nleft = --length;
-	file->fd = BLOCK_OUT;
-	file->flags = 0;
-}
-#endif
-
-
-void
-out1str(const char *p)
-{
-	outstr(p, out1);
-}
-
-
-void
-out2str(const char *p)
-{
-	outstr(p, out2);
-}
-
-
-void
-outstr(const char *p, struct output *file)
-{
-	while (*p)
-		outc(*p++, file);
-	if (file == out2)
-		flushout(file);
-}
-
-
-char out_junk[16];
-
-
-void
-emptyoutbuf(struct output *dest)
-{
-	int offset;
-
-	if (dest->fd == BLOCK_OUT) {
-		dest->nextc = out_junk;
-		dest->nleft = sizeof out_junk;
-		dest->flags |= OUTPUT_ERR;
-	} else if (dest->buf == NULL) {
-		INTOFF;
-		dest->buf = ckmalloc(dest->bufsize);
-		dest->nextc = dest->buf;
-		dest->nleft = dest->bufsize;
-		INTON;
-	} else if (dest->fd == MEM_OUT) {
-		offset = dest->bufsize;
-		INTOFF;
-		dest->bufsize <<= 1;
-		dest->buf = ckrealloc(dest->buf, dest->bufsize);
-		dest->nleft = dest->bufsize - offset;
-		dest->nextc = dest->buf + offset;
-		INTON;
-	} else {
-		flushout(dest);
-	}
-	dest->nleft--;
-}
-
-
-void
-output_flushall(void)
-{
-	flushout(&output);
-	flushout(&errout);
-}
-
-
-void
-flushout(struct output *dest)
-{
-
-	if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0)
-		return;
-	if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0)
-		dest->flags |= OUTPUT_ERR;
-	dest->nextc = dest->buf;
-	dest->nleft = dest->bufsize;
-}
-
-
-void
-freestdout(void)
-{
-	INTOFF;
-	if (output.buf) {
-		ckfree(output.buf);
-		output.buf = NULL;
-		output.nleft = 0;
-	}
-	INTON;
-}
-
-
-void
-outfmt(struct output *file, const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	doformat(file, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-out1fmt(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	doformat(out1, fmt, ap);
-	va_end(ap);
-}
-
-void
-dprintf(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	doformat(out2, fmt, ap);
-	va_end(ap);
-	flushout(out2);
-}
-
-void
-fmtstr(char *outbuf, size_t length, const char *fmt, ...)
-{
-	va_list ap;
-	struct output strout;
-
-	va_start(ap, fmt);
-	strout.nextc = outbuf;
-	strout.nleft = length;
-	strout.fd = BLOCK_OUT;
-	strout.flags = 0;
-	doformat(&strout, fmt, ap);
-	outc('\0', &strout);
-	if (strout.flags & OUTPUT_ERR)
-		outbuf[length - 1] = '\0';
-	va_end(ap);
-}
-
-/*
- * Formatted output.  This routine handles a subset of the printf formats:
- * - Formats supported: d, u, o, p, X, s, and c.
- * - The x format is also accepted but is treated like X.
- * - The l, ll and q modifiers are accepted.
- * - The - and # flags are accepted; # only works with the o format.
- * - Width and precision may be specified with any format except c.
- * - An * may be given for the width or precision.
- * - The obsolete practice of preceding the width with a zero to get
- *   zero padding is not supported; use the precision field.
- * - A % may be printed by writing %% in the format string.
- */
-
-#define TEMPSIZE 24
-
-#ifdef BSD4_4
-#define HAVE_VASPRINTF 1
-#endif
-
-void
-doformat(struct output *dest, const char *f, va_list ap)
-{
-#if	HAVE_VASPRINTF
-	char *s;
-
-	vasprintf(&s, f, ap);
-	outstr(s, dest);
-	free(s);
-#else	/* !HAVE_VASPRINTF */
-	static const char digit[] = "0123456789ABCDEF";
-	char c;
-	char temp[TEMPSIZE];
-	int flushleft;
-	int sharp;
-	int width;
-	int prec;
-	int islong;
-	int isquad;
-	char *p;
-	int sign;
-#ifdef BSD4_4
-	quad_t l;
-	u_quad_t num;
-#else
-	long l;
-	u_long num;
-#endif
-	unsigned base;
-	int len;
-	int size;
-	int pad;
-
-	while ((c = *f++) != '\0') {
-		if (c != '%') {
-			outc(c, dest);
-			continue;
-		}
-		flushleft = 0;
-		sharp = 0;
-		width = 0;
-		prec = -1;
-		islong = 0;
-		isquad = 0;
-		for (;;) {
-			if (*f == '-')
-				flushleft++;
-			else if (*f == '#')
-				sharp++;
-			else
-				break;
-			f++;
-		}
-		if (*f == '*') {
-			width = va_arg(ap, int);
-			f++;
-		} else {
-			while (is_digit(*f)) {
-				width = 10 * width + digit_val(*f++);
-			}
-		}
-		if (*f == '.') {
-			if (*++f == '*') {
-				prec = va_arg(ap, int);
-				f++;
-			} else {
-				prec = 0;
-				while (is_digit(*f)) {
-					prec = 10 * prec + digit_val(*f++);
-				}
-			}
-		}
-		if (*f == 'l') {
-			f++;
-			if (*f == 'l') {
-				isquad++;
-				f++;
-			} else
-				islong++;
-		} else if (*f == 'q') {
-			isquad++;
-			f++;
-		}
-		switch (*f) {
-		case 'd':
-#ifdef BSD4_4
-			if (isquad)
-				l = va_arg(ap, quad_t);
-			else
-#endif
-			if (islong)
-				l = va_arg(ap, long);
-			else
-				l = va_arg(ap, int);
-			sign = 0;
-			num = l;
-			if (l < 0) {
-				num = -l;
-				sign = 1;
-			}
-			base = 10;
-			goto number;
-		case 'u':
-			base = 10;
-			goto uns_number;
-		case 'o':
-			base = 8;
-			goto uns_number;
-		case 'p':
-			outc('0', dest);
-			outc('x', dest);
-			/*FALLTHROUGH*/
-		case 'x':
-			/* we don't implement 'x'; treat like 'X' */
-		case 'X':
-			base = 16;
-uns_number:	  /* an unsigned number */
-			sign = 0;
-#ifdef BSD4_4
-			if (isquad)
-				num = va_arg(ap, u_quad_t);
-			else
-#endif
-			if (islong)
-				num = va_arg(ap, unsigned long);
-			else
-				num = va_arg(ap, unsigned int);
-number:		  /* process a number */
-			p = temp + TEMPSIZE - 1;
-			*p = '\0';
-			while (num) {
-				*--p = digit[num % base];
-				num /= base;
-			}
-			len = (temp + TEMPSIZE - 1) - p;
-			if (prec < 0)
-				prec = 1;
-			if (sharp && *f == 'o' && prec <= len)
-				prec = len + 1;
-			pad = 0;
-			if (width) {
-				size = len;
-				if (size < prec)
-					size = prec;
-				size += sign;
-				pad = width - size;
-				if (flushleft == 0) {
-					while (--pad >= 0)
-						outc(' ', dest);
-				}
-			}
-			if (sign)
-				outc('-', dest);
-			prec -= len;
-			while (--prec >= 0)
-				outc('0', dest);
-			while (*p)
-				outc(*p++, dest);
-			while (--pad >= 0)
-				outc(' ', dest);
-			break;
-		case 's':
-			p = va_arg(ap, char *);
-			pad = 0;
-			if (width) {
-				len = strlen(p);
-				if (prec >= 0 && len > prec)
-					len = prec;
-				pad = width - len;
-				if (flushleft == 0) {
-					while (--pad >= 0)
-						outc(' ', dest);
-				}
-			}
-			prec++;
-			while (--prec != 0 && *p)
-				outc(*p++, dest);
-			while (--pad >= 0)
-				outc(' ', dest);
-			break;
-		case 'c':
-			c = va_arg(ap, int);
-			outc(c, dest);
-			break;
-		default:
-			outc(*f, dest);
-			break;
-		}
-		f++;
-	}
-#endif	/* !HAVE_VASPRINTF */
-}
-
-
-
-/*
- * Version of write which resumes after a signal is caught.
- */
-
-int
-xwrite(int fd, char *buf, int nbytes)
-{
-	int ntry;
-	int i;
-	int n;
-
-	n = nbytes;
-	ntry = 0;
-	for (;;) {
-		i = write(fd, buf, n);
-		if (i > 0) {
-			if ((n -= i) <= 0)
-				return nbytes;
-			buf += i;
-			ntry = 0;
-		} else if (i == 0) {
-			if (++ntry > 10)
-				return nbytes - n;
-		} else if (errno != EINTR) {
-			return -1;
-		}
-	}
-}
-
-
-/*
- * Version of ioctl that retries after a signal is caught.
- * XXX unused function
- */
-
-int
-xioctl(int fd, unsigned long request, char *arg)
-{
-	int i;
-
-	while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR);
-	return i;
-}
diff --git a/src/ash/output.h b/src/ash/output.h
deleted file mode 100644
index 8f03e8d..0000000
--- a/src/ash/output.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*	$NetBSD: output.h,v 1.17 2003/08/07 09:05:36 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)output.h	8.2 (Berkeley) 5/4/95
- */
-
-#ifndef OUTPUT_INCL
-
-#include <stdarg.h>
-
-struct output {
-	char *nextc;
-	int nleft;
-	char *buf;
-	int bufsize;
-	short fd;
-	short flags;
-};
-
-extern struct output output;
-extern struct output errout;
-extern struct output memout;
-extern struct output *out1;
-extern struct output *out2;
-
-void open_mem(char *, int, struct output *);
-void out1str(const char *);
-void out2str(const char *);
-void outstr(const char *, struct output *);
-void emptyoutbuf(struct output *);
-void output_flushall(void);
-void flushout(struct output *);
-void freestdout(void);
-void outfmt(struct output *, const char *, ...)
-    __attribute__((__format__(__printf__,2,3)));
-void out1fmt(const char *, ...)
-    __attribute__((__format__(__printf__,1,2)));
-void dprintf(const char *, ...)
-    __attribute__((__format__(__printf__,1,2)));
-void fmtstr(char *, size_t, const char *, ...)
-    __attribute__((__format__(__printf__,3,4)));
-void doformat(struct output *, const char *, va_list);
-int xwrite(int, char *, int);
-int xioctl(int, unsigned long, char *);
-
-#define outc(c, file)	(--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
-#define out1c(c)	outc(c, out1);
-#define out2c(c)	outc(c, out2);
-
-#define OUTPUT_INCL
-#endif
diff --git a/src/ash/parser.c b/src/ash/parser.c
deleted file mode 100644
index a05561f..0000000
--- a/src/ash/parser.c
+++ /dev/null
@@ -1,1656 +0,0 @@
-/*	$NetBSD: parser.c,v 1.59 2005/03/21 20:10:29 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
-#else
-__RCSID("$NetBSD: parser.c,v 1.59 2005/03/21 20:10:29 dsl Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdlib.h>
-#ifdef __sun__
-#include <iso/limits_iso.h>
-#endif
-
-#include "shell.h"
-#include "parser.h"
-#include "nodes.h"
-#include "expand.h"	/* defines rmescapes() */
-#include "eval.h"	/* defines commandname */
-#include "redir.h"	/* defines copyfd() */
-#include "syntax.h"
-#include "options.h"
-#include "input.h"
-#include "output.h"
-#include "var.h"
-#include "error.h"
-#include "memalloc.h"
-#include "mystring.h"
-#include "alias.h"
-#include "show.h"
-#ifndef SMALL
-#include "myhistedit.h"
-#endif
-
-/*
- * Shell command parser.
- */
-
-#define EOFMARKLEN 79
-
-/* values returned by readtoken */
-#include "token.h"
-
-#define OPENBRACE '{'
-#define CLOSEBRACE '}'
-
-
-struct heredoc {
-	struct heredoc *next;	/* next here document in list */
-	union node *here;		/* redirection node */
-	char *eofmark;		/* string indicating end of input */
-	int striptabs;		/* if set, strip leading tabs */
-};
-
-
-
-static int noalias = 0;		/* when set, don't handle aliases */
-struct heredoc *heredoclist;	/* list of here documents to read */
-int parsebackquote;		/* nonzero if we are inside backquotes */
-int doprompt;			/* if set, prompt the user */
-int needprompt;			/* true if interactive and at start of line */
-int lasttoken;			/* last token read */
-MKINIT int tokpushback;		/* last token pushed back */
-char *wordtext;			/* text of last word returned by readtoken */
-MKINIT int checkkwd;            /* 1 == check for kwds, 2 == also eat newlines */
-struct nodelist *backquotelist;
-union node *redirnode;
-struct heredoc *heredoc;
-int quoteflag;			/* set if (part of) last token was quoted */
-int startlinno;			/* line # where last token started */
-
-
-STATIC union node *list(int);
-STATIC union node *andor(void);
-STATIC union node *pipeline(void);
-STATIC union node *command(void);
-STATIC union node *simplecmd(union node **, union node *);
-STATIC union node *makename(void);
-STATIC void parsefname(void);
-STATIC void parseheredoc(void);
-STATIC int peektoken(void);
-STATIC int readtoken(void);
-STATIC int xxreadtoken(void);
-STATIC int readtoken1(int, char const *, char *, int);
-STATIC int noexpand(char *);
-STATIC void synexpect(int) __attribute__((__noreturn__));
-STATIC void synerror(const char *) __attribute__((__noreturn__));
-STATIC void setprompt(int);
-
-
-/*
- * Read and parse a command.  Returns NEOF on end of file.  (NULL is a
- * valid parse tree indicating a blank line.)
- */
-
-union node *
-parsecmd(int interact)
-{
-	int t;
-
-	tokpushback = 0;
-	doprompt = interact;
-	if (doprompt)
-		setprompt(1);
-	else
-		setprompt(0);
-	needprompt = 0;
-	t = readtoken();
-	if (t == TEOF)
-		return NEOF;
-	if (t == TNL)
-		return NULL;
-	tokpushback++;
-	return list(1);
-}
-
-
-STATIC union node *
-list(int nlflag)
-{
-	union node *n1, *n2, *n3;
-	int tok;
-
-	checkkwd = 2;
-	if (nlflag == 0 && tokendlist[peektoken()])
-		return NULL;
-	n1 = NULL;
-	for (;;) {
-		n2 = andor();
-		tok = readtoken();
-		if (tok == TBACKGND) {
-			if (n2->type == NCMD || n2->type == NPIPE) {
-				n2->ncmd.backgnd = 1;
-			} else if (n2->type == NREDIR) {
-				n2->type = NBACKGND;
-			} else {
-				n3 = (union node *)stalloc(sizeof (struct nredir));
-				n3->type = NBACKGND;
-				n3->nredir.n = n2;
-				n3->nredir.redirect = NULL;
-				n2 = n3;
-			}
-		}
-		if (n1 == NULL) {
-			n1 = n2;
-		}
-		else {
-			n3 = (union node *)stalloc(sizeof (struct nbinary));
-			n3->type = NSEMI;
-			n3->nbinary.ch1 = n1;
-			n3->nbinary.ch2 = n2;
-			n1 = n3;
-		}
-		switch (tok) {
-		case TBACKGND:
-		case TSEMI:
-			tok = readtoken();
-			/* fall through */
-		case TNL:
-			if (tok == TNL) {
-				parseheredoc();
-				if (nlflag)
-					return n1;
-			} else {
-				tokpushback++;
-			}
-			checkkwd = 2;
-			if (tokendlist[peektoken()])
-				return n1;
-			break;
-		case TEOF:
-			if (heredoclist)
-				parseheredoc();
-			else
-				pungetc();		/* push back EOF on input */
-			return n1;
-		default:
-			if (nlflag)
-				synexpect(-1);
-			tokpushback++;
-			return n1;
-		}
-	}
-}
-
-
-
-STATIC union node *
-andor(void)
-{
-	union node *n1, *n2, *n3;
-	int t;
-
-	n1 = pipeline();
-	for (;;) {
-		if ((t = readtoken()) == TAND) {
-			t = NAND;
-		} else if (t == TOR) {
-			t = NOR;
-		} else {
-			tokpushback++;
-			return n1;
-		}
-		n2 = pipeline();
-		n3 = (union node *)stalloc(sizeof (struct nbinary));
-		n3->type = t;
-		n3->nbinary.ch1 = n1;
-		n3->nbinary.ch2 = n2;
-		n1 = n3;
-	}
-}
-
-
-
-STATIC union node *
-pipeline(void)
-{
-	union node *n1, *n2, *pipenode;
-	struct nodelist *lp, *prev;
-	int negate;
-
-	negate = 0;
-	TRACE(("pipeline: entered\n"));
-	while (readtoken() == TNOT)
-		negate = !negate;
-	tokpushback++;
-	n1 = command();
-	if (readtoken() == TPIPE) {
-		pipenode = (union node *)stalloc(sizeof (struct npipe));
-		pipenode->type = NPIPE;
-		pipenode->npipe.backgnd = 0;
-		lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
-		pipenode->npipe.cmdlist = lp;
-		lp->n = n1;
-		do {
-			prev = lp;
-			lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
-			lp->n = command();
-			prev->next = lp;
-		} while (readtoken() == TPIPE);
-		lp->next = NULL;
-		n1 = pipenode;
-	}
-	tokpushback++;
-	if (negate) {
-		n2 = (union node *)stalloc(sizeof (struct nnot));
-		n2->type = NNOT;
-		n2->nnot.com = n1;
-		return n2;
-	} else
-		return n1;
-}
-
-
-
-STATIC union node *
-command(void)
-{
-	union node *n1, *n2;
-	union node *ap, **app;
-	union node *cp, **cpp;
-	union node *redir, **rpp;
-	int t, negate = 0;
-
-	checkkwd = 2;
-	redir = NULL;
-	n1 = NULL;
-	rpp = &redir;
-
-	/* Check for redirection which may precede command */
-	while (readtoken() == TREDIR) {
-		*rpp = n2 = redirnode;
-		rpp = &n2->nfile.next;
-		parsefname();
-	}
-	tokpushback++;
-
-	while (readtoken() == TNOT) {
-		TRACE(("command: TNOT recognized\n"));
-		negate = !negate;
-	}
-	tokpushback++;
-
-	switch (readtoken()) {
-	case TIF:
-		n1 = (union node *)stalloc(sizeof (struct nif));
-		n1->type = NIF;
-		n1->nif.test = list(0);
-		if (readtoken() != TTHEN)
-			synexpect(TTHEN);
-		n1->nif.ifpart = list(0);
-		n2 = n1;
-		while (readtoken() == TELIF) {
-			n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif));
-			n2 = n2->nif.elsepart;
-			n2->type = NIF;
-			n2->nif.test = list(0);
-			if (readtoken() != TTHEN)
-				synexpect(TTHEN);
-			n2->nif.ifpart = list(0);
-		}
-		if (lasttoken == TELSE)
-			n2->nif.elsepart = list(0);
-		else {
-			n2->nif.elsepart = NULL;
-			tokpushback++;
-		}
-		if (readtoken() != TFI)
-			synexpect(TFI);
-		checkkwd = 1;
-		break;
-	case TWHILE:
-	case TUNTIL: {
-		int got;
-		n1 = (union node *)stalloc(sizeof (struct nbinary));
-		n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
-		n1->nbinary.ch1 = list(0);
-		if ((got=readtoken()) != TDO) {
-TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
-			synexpect(TDO);
-		}
-		n1->nbinary.ch2 = list(0);
-		if (readtoken() != TDONE)
-			synexpect(TDONE);
-		checkkwd = 1;
-		break;
-	}
-	case TFOR:
-		if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
-			synerror("Bad for loop variable");
-		n1 = (union node *)stalloc(sizeof (struct nfor));
-		n1->type = NFOR;
-		n1->nfor.var = wordtext;
-		if (readtoken() == TWORD && ! quoteflag && equal(wordtext, "in")) {
-			app = ≈
-			while (readtoken() == TWORD) {
-				n2 = (union node *)stalloc(sizeof (struct narg));
-				n2->type = NARG;
-				n2->narg.text = wordtext;
-				n2->narg.backquote = backquotelist;
-				*app = n2;
-				app = &n2->narg.next;
-			}
-			*app = NULL;
-			n1->nfor.args = ap;
-			if (lasttoken != TNL && lasttoken != TSEMI)
-				synexpect(-1);
-		} else {
-			static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
-								   '@', '=', '\0'};
-			n2 = (union node *)stalloc(sizeof (struct narg));
-			n2->type = NARG;
-			n2->narg.text = argvars;
-			n2->narg.backquote = NULL;
-			n2->narg.next = NULL;
-			n1->nfor.args = n2;
-			/*
-			 * Newline or semicolon here is optional (but note
-			 * that the original Bourne shell only allowed NL).
-			 */
-			if (lasttoken != TNL && lasttoken != TSEMI)
-				tokpushback++;
-		}
-		checkkwd = 2;
-		if ((t = readtoken()) == TDO)
-			t = TDONE;
-		else if (t == TBEGIN)
-			t = TEND;
-		else
-			synexpect(-1);
-		n1->nfor.body = list(0);
-		if (readtoken() != t)
-			synexpect(t);
-		checkkwd = 1;
-		break;
-	case TCASE:
-		n1 = (union node *)stalloc(sizeof (struct ncase));
-		n1->type = NCASE;
-		if (readtoken() != TWORD)
-			synexpect(TWORD);
-		n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg));
-		n2->type = NARG;
-		n2->narg.text = wordtext;
-		n2->narg.backquote = backquotelist;
-		n2->narg.next = NULL;
-		while (readtoken() == TNL);
-		if (lasttoken != TWORD || ! equal(wordtext, "in"))
-			synerror("expecting \"in\"");
-		cpp = &n1->ncase.cases;
-		noalias = 1;
-		checkkwd = 2, readtoken();
-		do {
-			*cpp = cp = (union node *)stalloc(sizeof (struct nclist));
-			cp->type = NCLIST;
-			app = &cp->nclist.pattern;
-			for (;;) {
-				*app = ap = (union node *)stalloc(sizeof (struct narg));
-				ap->type = NARG;
-				ap->narg.text = wordtext;
-				ap->narg.backquote = backquotelist;
-				if (checkkwd = 2, readtoken() != TPIPE)
-					break;
-				app = &ap->narg.next;
-				readtoken();
-			}
-			ap->narg.next = NULL;
-			noalias = 0;
-			if (lasttoken != TRP) {
-				synexpect(TRP);
-			}
-			cp->nclist.body = list(0);
-
-			checkkwd = 2;
-			if ((t = readtoken()) != TESAC) {
-				if (t != TENDCASE) {
-					noalias = 0;
-					synexpect(TENDCASE);
-				} else {
-					noalias = 1;
-					checkkwd = 2;
-					readtoken();
-				}
-			}
-			cpp = &cp->nclist.next;
-		} while(lasttoken != TESAC);
-		noalias = 0;
-		*cpp = NULL;
-		checkkwd = 1;
-		break;
-	case TLP:
-		n1 = (union node *)stalloc(sizeof (struct nredir));
-		n1->type = NSUBSHELL;
-		n1->nredir.n = list(0);
-		n1->nredir.redirect = NULL;
-		if (readtoken() != TRP)
-			synexpect(TRP);
-		checkkwd = 1;
-		break;
-	case TBEGIN:
-		n1 = list(0);
-		if (readtoken() != TEND)
-			synexpect(TEND);
-		checkkwd = 1;
-		break;
-	/* Handle an empty command like other simple commands.  */
-	case TSEMI:
-		/*
-		 * An empty command before a ; doesn't make much sense, and
-		 * should certainly be disallowed in the case of `if ;'.
-		 */
-		if (!redir)
-			synexpect(-1);
-	case TAND:
-	case TOR:
-	case TNL:
-	case TEOF:
-	case TWORD:
-	case TRP:
-		tokpushback++;
-		n1 = simplecmd(rpp, redir);
-		goto checkneg;
-	default:
-		synexpect(-1);
-		/* NOTREACHED */
-	}
-
-	/* Now check for redirection which may follow command */
-	while (readtoken() == TREDIR) {
-		*rpp = n2 = redirnode;
-		rpp = &n2->nfile.next;
-		parsefname();
-	}
-	tokpushback++;
-	*rpp = NULL;
-	if (redir) {
-		if (n1->type != NSUBSHELL) {
-			n2 = (union node *)stalloc(sizeof (struct nredir));
-			n2->type = NREDIR;
-			n2->nredir.n = n1;
-			n1 = n2;
-		}
-		n1->nredir.redirect = redir;
-	}
-
-checkneg:
-	if (negate) {
-		n2 = (union node *)stalloc(sizeof (struct nnot));
-		n2->type = NNOT;
-		n2->nnot.com = n1;
-		return n2;
-	}
-	else
-		return n1;
-}
-
-
-STATIC union node *
-simplecmd(union node **rpp, union node *redir)
-{
-	union node *args, **app;
-	union node **orig_rpp = rpp;
-	union node *n = NULL, *n2;
-	int negate = 0;
-
-	/* If we don't have any redirections already, then we must reset */
-	/* rpp to be the address of the local redir variable.  */
-	if (redir == 0)
-		rpp = &redir;
-
-	args = NULL;
-	app = &args;
-	/*
-	 * We save the incoming value, because we need this for shell
-	 * functions.  There can not be a redirect or an argument between
-	 * the function name and the open parenthesis.
-	 */
-	orig_rpp = rpp;
-
-	while (readtoken() == TNOT) {
-		TRACE(("command: TNOT recognized\n"));
-		negate = !negate;
-	}
-	tokpushback++;
-
-	for (;;) {
-		if (readtoken() == TWORD) {
-			n = (union node *)stalloc(sizeof (struct narg));
-			n->type = NARG;
-			n->narg.text = wordtext;
-			n->narg.backquote = backquotelist;
-			*app = n;
-			app = &n->narg.next;
-		} else if (lasttoken == TREDIR) {
-			*rpp = n = redirnode;
-			rpp = &n->nfile.next;
-			parsefname();	/* read name of redirection file */
-		} else if (lasttoken == TLP && app == &args->narg.next
-					    && rpp == orig_rpp) {
-			/* We have a function */
-			if (readtoken() != TRP)
-				synexpect(TRP);
-#ifdef notdef
-			if (! goodname(n->narg.text))
-				synerror("Bad function name");
-#endif
-			n->type = NDEFUN;
-			n->narg.next = command();
-			goto checkneg;
-		} else {
-			tokpushback++;
-			break;
-		}
-	}
-	*app = NULL;
-	*rpp = NULL;
-	n = (union node *)stalloc(sizeof (struct ncmd));
-	n->type = NCMD;
-	n->ncmd.backgnd = 0;
-	n->ncmd.args = args;
-	n->ncmd.redirect = redir;
-
-checkneg:
-	if (negate) {
-		n2 = (union node *)stalloc(sizeof (struct nnot));
-		n2->type = NNOT;
-		n2->nnot.com = n;
-		return n2;
-	}
-	else
-		return n;
-}
-
-STATIC union node *
-makename(void)
-{
-	union node *n;
-
-	n = (union node *)stalloc(sizeof (struct narg));
-	n->type = NARG;
-	n->narg.next = NULL;
-	n->narg.text = wordtext;
-	n->narg.backquote = backquotelist;
-	return n;
-}
-
-void fixredir(union node *n, const char *text, int err)
-	{
-	TRACE(("Fix redir %s %d\n", text, err));
-	if (!err)
-		n->ndup.vname = NULL;
-
-	if (is_digit(text[0]) && text[1] == '\0')
-		n->ndup.dupfd = digit_val(text[0]);
-	else if (text[0] == '-' && text[1] == '\0')
-		n->ndup.dupfd = -1;
-	else {
-
-		if (err)
-			synerror("Bad fd number");
-		else
-			n->ndup.vname = makename();
-	}
-}
-
-
-STATIC void
-parsefname(void)
-{
-	union node *n = redirnode;
-
-	if (readtoken() != TWORD)
-		synexpect(-1);
-	if (n->type == NHERE) {
-		struct heredoc *here = heredoc;
-		struct heredoc *p;
-		int i;
-
-		if (quoteflag == 0)
-			n->type = NXHERE;
-		TRACE(("Here document %d\n", n->type));
-		if (here->striptabs) {
-			while (*wordtext == '\t')
-				wordtext++;
-		}
-		if (! noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN)
-			synerror("Illegal eof marker for << redirection");
-		rmescapes(wordtext);
-		here->eofmark = wordtext;
-		here->next = NULL;
-		if (heredoclist == NULL)
-			heredoclist = here;
-		else {
-			for (p = heredoclist ; p->next ; p = p->next);
-			p->next = here;
-		}
-	} else if (n->type == NTOFD || n->type == NFROMFD) {
-		fixredir(n, wordtext, 0);
-	} else {
-		n->nfile.fname = makename();
-	}
-}
-
-
-/*
- * Input any here documents.
- */
-
-STATIC void
-parseheredoc(void)
-{
-	struct heredoc *here;
-	union node *n;
-
-	while (heredoclist) {
-		here = heredoclist;
-		heredoclist = here->next;
-		if (needprompt) {
-			setprompt(2);
-			needprompt = 0;
-		}
-		readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
-				here->eofmark, here->striptabs);
-		n = (union node *)stalloc(sizeof (struct narg));
-		n->narg.type = NARG;
-		n->narg.next = NULL;
-		n->narg.text = wordtext;
-		n->narg.backquote = backquotelist;
-		here->here->nhere.doc = n;
-	}
-}
-
-STATIC int
-peektoken(void)
-{
-	int t;
-
-	t = readtoken();
-	tokpushback++;
-	return (t);
-}
-
-STATIC int
-readtoken(void)
-{
-	int t;
-	int savecheckkwd = checkkwd;
-#ifdef DEBUG
-	int alreadyseen = tokpushback;
-#endif
-	struct alias *ap;
-
-	top:
-	t = xxreadtoken();
-
-	if (checkkwd) {
-		/*
-		 * eat newlines
-		 */
-		if (checkkwd == 2) {
-			checkkwd = 0;
-			while (t == TNL) {
-				parseheredoc();
-				t = xxreadtoken();
-			}
-		} else
-			checkkwd = 0;
-		/*
-		 * check for keywords and aliases
-		 */
-		if (t == TWORD && !quoteflag)
-		{
-			const char *const *pp;
-
-			for (pp = parsekwd; *pp; pp++) {
-				if (**pp == *wordtext && equal(*pp, wordtext))
-				{
-					lasttoken = t = pp -
-					    parsekwd + KWDOFFSET;
-					TRACE(("keyword %s recognized\n", tokname[t]));
-					goto out;
-				}
-			}
-			if(!noalias &&
-			    (ap = lookupalias(wordtext, 1)) != NULL) {
-				pushstring(ap->val, strlen(ap->val), ap);
-				checkkwd = savecheckkwd;
-				goto top;
-			}
-		}
-out:
-		checkkwd = (t == TNOT) ? savecheckkwd : 0;
-	}
-#ifdef DEBUG
-	if (!alreadyseen)
-	    TRACE(("token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
-	else
-	    TRACE(("reread token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
-#endif
-	return (t);
-}
-
-
-/*
- * Read the next input token.
- * If the token is a word, we set backquotelist to the list of cmds in
- *	backquotes.  We set quoteflag to true if any part of the word was
- *	quoted.
- * If the token is TREDIR, then we set redirnode to a structure containing
- *	the redirection.
- * In all cases, the variable startlinno is set to the number of the line
- *	on which the token starts.
- *
- * [Change comment:  here documents and internal procedures]
- * [Readtoken shouldn't have any arguments.  Perhaps we should make the
- *  word parsing code into a separate routine.  In this case, readtoken
- *  doesn't need to have any internal procedures, but parseword does.
- *  We could also make parseoperator in essence the main routine, and
- *  have parseword (readtoken1?) handle both words and redirection.]
- */
-
-#define RETURN(token)	return lasttoken = token
-
-STATIC int
-xxreadtoken(void)
-{
-	int c;
-
-	if (tokpushback) {
-		tokpushback = 0;
-		return lasttoken;
-	}
-	if (needprompt) {
-		setprompt(2);
-		needprompt = 0;
-	}
-	startlinno = plinno;
-	for (;;) {	/* until token or start of word found */
-		c = pgetc_macro();
-		if (c == ' ' || c == '\t')
-			continue;		/* quick check for white space first */
-		switch (c) {
-		case ' ': case '\t':
-			continue;
-		case '#':
-			while ((c = pgetc()) != '\n' && c != PEOF);
-			pungetc();
-			continue;
-		case '\\':
-			if (pgetc() == '\n') {
-				startlinno = ++plinno;
-				if (doprompt)
-					setprompt(2);
-				else
-					setprompt(0);
-				continue;
-			}
-			pungetc();
-			goto breakloop;
-		case '\n':
-			plinno++;
-			needprompt = doprompt;
-			RETURN(TNL);
-		case PEOF:
-			RETURN(TEOF);
-		case '&':
-			if (pgetc() == '&')
-				RETURN(TAND);
-			pungetc();
-			RETURN(TBACKGND);
-		case '|':
-			if (pgetc() == '|')
-				RETURN(TOR);
-			pungetc();
-			RETURN(TPIPE);
-		case ';':
-			if (pgetc() == ';')
-				RETURN(TENDCASE);
-			pungetc();
-			RETURN(TSEMI);
-		case '(':
-			RETURN(TLP);
-		case ')':
-			RETURN(TRP);
-		default:
-			goto breakloop;
-		}
-	}
-breakloop:
-	return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
-#undef RETURN
-}
-
-
-
-/*
- * If eofmark is NULL, read a word or a redirection symbol.  If eofmark
- * is not NULL, read a here document.  In the latter case, eofmark is the
- * word which marks the end of the document and striptabs is true if
- * leading tabs should be stripped from the document.  The argument firstc
- * is the first character of the input token or document.
- *
- * Because C does not have internal subroutines, I have simulated them
- * using goto's to implement the subroutine linkage.  The following macros
- * will run code that appears at the end of readtoken1.
- */
-
-#define CHECKEND()	{goto checkend; checkend_return:;}
-#define PARSEREDIR()	{goto parseredir; parseredir_return:;}
-#define PARSESUB()	{goto parsesub; parsesub_return:;}
-#define PARSEBACKQOLD()	{oldstyle = 1; goto parsebackq; parsebackq_oldreturn:;}
-#define PARSEBACKQNEW()	{oldstyle = 0; goto parsebackq; parsebackq_newreturn:;}
-#define	PARSEARITH()	{goto parsearith; parsearith_return:;}
-
-/*
- * Keep track of nested doublequotes in dblquote and doublequotep.
- * We use dblquote for the first 32 levels, and we expand to a malloc'ed
- * region for levels above that. Usually we never need to malloc.
- * This code assumes that an int is 32 bits. We don't use uint32_t,
- * because the rest of the code does not.
- */
-#define ISDBLQUOTE() ((varnest < 32) ? (dblquote & (1 << varnest)) : \
-    (dblquotep[(varnest / 32) - 1] & (1 << (varnest % 32))))
-
-#define SETDBLQUOTE() \
-    if (varnest < 32) \
-	dblquote |= (1 << varnest); \
-    else \
-	dblquotep[(varnest / 32) - 1] |= (1 << (varnest % 32))
-
-#define CLRDBLQUOTE() \
-    if (varnest < 32) \
-	dblquote &= ~(1 << varnest); \
-    else \
-	dblquotep[(varnest / 32) - 1] &= ~(1 << (varnest % 32))
-
-STATIC int
-readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
-{
-	int c = firstc;
-	char *out;
-	int len;
-	char line[EOFMARKLEN + 1];
-	struct nodelist *bqlist;
-	int quotef;
-	int *dblquotep = NULL;
-	size_t maxnest = 32;
-	int dblquote;
-	int varnest;	/* levels of variables expansion */
-	int arinest;	/* levels of arithmetic expansion */
-	int parenlevel;	/* levels of parens in arithmetic */
-	int oldstyle;
-	char const *prevsyntax;	/* syntax before arithmetic */
-#if __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &maxnest;
-	(void) &dblquotep;
-	(void) &out;
-	(void) "ef;
-	(void) &dblquote;
-	(void) &varnest;
-	(void) &arinest;
-	(void) &parenlevel;
-	(void) &oldstyle;
-	(void) &prevsyntax;
-	(void) &syntax;
-#endif
-
-	startlinno = plinno;
-	dblquote = 0;
-	varnest = 0;
-	if (syntax == DQSYNTAX) {
-		SETDBLQUOTE();
-	}
-	quotef = 0;
-	bqlist = NULL;
-	arinest = 0;
-	parenlevel = 0;
-
-	STARTSTACKSTR(out);
-	loop: {	/* for each line, until end of word */
-#if ATTY
-		if (c == '\034' && doprompt
-		 && attyset() && ! equal(termval(), "emacs")) {
-			attyline();
-			if (syntax == BASESYNTAX)
-				return readtoken();
-			c = pgetc();
-			goto loop;
-		}
-#endif
-		CHECKEND();	/* set c to PEOF if at end of here document */
-		for (;;) {	/* until end of line or end of word */
-			CHECKSTRSPACE(4, out);	/* permit 4 calls to USTPUTC */
-			switch(syntax[c]) {
-			case CNL:	/* '\n' */
-				if (syntax == BASESYNTAX)
-					goto endword;	/* exit outer loop */
-				USTPUTC(c, out);
-				plinno++;
-				if (doprompt)
-					setprompt(2);
-				else
-					setprompt(0);
-				c = pgetc();
-				goto loop;		/* continue outer loop */
-			case CWORD:
-				USTPUTC(c, out);
-				break;
-			case CCTL:
-				if (eofmark == NULL || ISDBLQUOTE())
-					USTPUTC(CTLESC, out);
-				USTPUTC(c, out);
-				break;
-			case CBACK:	/* backslash */
-				c = pgetc();
-				if (c == PEOF) {
-					USTPUTC('\\', out);
-					pungetc();
-					break;
-				}
-				if (c == '\n') {
-					if (doprompt)
-						setprompt(2);
-					else
-						setprompt(0);
-					break;
-				}
-				quotef = 1;
-				if (ISDBLQUOTE() && c != '\\' &&
-				    c != '`' && c != '$' &&
-				    (c != '"' || eofmark != NULL))
-					USTPUTC('\\', out);
-				if (SQSYNTAX[c] == CCTL)
-					USTPUTC(CTLESC, out);
-				else if (eofmark == NULL) {
-					USTPUTC(CTLQUOTEMARK, out);
-					USTPUTC(c, out);
-					if (varnest != 0)
-						USTPUTC(CTLQUOTEEND, out);
-					break;
-				}
-				USTPUTC(c, out);
-				break;
-			case CSQUOTE:
-				if (syntax != SQSYNTAX) {
-					if (eofmark == NULL)
-						USTPUTC(CTLQUOTEMARK, out);
-					quotef = 1;
-					syntax = SQSYNTAX;
-					break;
-				}
-				if (eofmark != NULL && arinest == 0 &&
-				    varnest == 0) {
-					/* Ignore inside quoted here document */
-					USTPUTC(c, out);
-					break;
-				}
-				/* End of single quotes... */
-				if (arinest)
-					syntax = ARISYNTAX;
-				else {
-					syntax = BASESYNTAX;
-					if (varnest != 0)
-						USTPUTC(CTLQUOTEEND, out);
-				}
-				break;
-			case CDQUOTE:
-				if (eofmark != NULL && arinest == 0 &&
-				    varnest == 0) {
-					/* Ignore inside here document */
-					USTPUTC(c, out);
-					break;
-				}
-				quotef = 1;
-				if (arinest) {
-					if (ISDBLQUOTE()) {
-						syntax = ARISYNTAX;
-						CLRDBLQUOTE();
-					} else {
-						syntax = DQSYNTAX;
-						SETDBLQUOTE();
-						USTPUTC(CTLQUOTEMARK, out);
-					}
-					break;
-				}
-				if (eofmark != NULL)
-					break;
-				if (ISDBLQUOTE()) {
-					if (varnest != 0)
-						USTPUTC(CTLQUOTEEND, out);
-					syntax = BASESYNTAX;
-					CLRDBLQUOTE();
-				} else {
-					syntax = DQSYNTAX;
-					SETDBLQUOTE();
-					USTPUTC(CTLQUOTEMARK, out);
-				}
-				break;
-			case CVAR:	/* '$' */
-				PARSESUB();		/* parse substitution */
-				break;
-			case CENDVAR:	/* CLOSEBRACE */
-				if (varnest > 0 && !ISDBLQUOTE()) {
-					varnest--;
-					USTPUTC(CTLENDVAR, out);
-				} else {
-					USTPUTC(c, out);
-				}
-				break;
-			case CLP:	/* '(' in arithmetic */
-				parenlevel++;
-				USTPUTC(c, out);
-				break;
-			case CRP:	/* ')' in arithmetic */
-				if (parenlevel > 0) {
-					USTPUTC(c, out);
-					--parenlevel;
-				} else {
-					if (pgetc() == ')') {
-						if (--arinest == 0) {
-							USTPUTC(CTLENDARI, out);
-							syntax = prevsyntax;
-							if (syntax == DQSYNTAX)
-								SETDBLQUOTE();
-							else
-								CLRDBLQUOTE();
-						} else
-							USTPUTC(')', out);
-					} else {
-						/*
-						 * unbalanced parens
-						 *  (don't 2nd guess - no error)
-						 */
-						pungetc();
-						USTPUTC(')', out);
-					}
-				}
-				break;
-			case CBQUOTE:	/* '`' */
-				PARSEBACKQOLD();
-				break;
-			case CEOF:
-				goto endword;		/* exit outer loop */
-			default:
-				if (varnest == 0)
-					goto endword;	/* exit outer loop */
-				USTPUTC(c, out);
-			}
-			c = pgetc_macro();
-		}
-	}
-endword:
-	if (syntax == ARISYNTAX)
-		synerror("Missing '))'");
-	if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL)
-		synerror("Unterminated quoted string");
-	if (varnest != 0) {
-		startlinno = plinno;
-		/* { */
-		synerror("Missing '}'");
-	}
-	USTPUTC('\0', out);
-	len = out - stackblock();
-	out = stackblock();
-	if (eofmark == NULL) {
-		if ((c == '>' || c == '<')
-		 && quotef == 0
-		 && len <= 2
-		 && (*out == '\0' || is_digit(*out))) {
-			PARSEREDIR();
-			return lasttoken = TREDIR;
-		} else {
-			pungetc();
-		}
-	}
-	quoteflag = quotef;
-	backquotelist = bqlist;
-	grabstackblock(len);
-	wordtext = out;
-	if (dblquotep != NULL)
-	    ckfree(dblquotep);
-	return lasttoken = TWORD;
-/* end of readtoken routine */
-
-
-
-/*
- * Check to see whether we are at the end of the here document.  When this
- * is called, c is set to the first character of the next input line.  If
- * we are at the end of the here document, this routine sets the c to PEOF.
- */
-
-checkend: {
-	if (eofmark) {
-		if (striptabs) {
-			while (c == '\t')
-				c = pgetc();
-		}
-		if (c == *eofmark) {
-			if (pfgets(line, sizeof line) != NULL) {
-				char *p, *q;
-
-				p = line;
-				for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
-				if (*p == '\n' && *q == '\0') {
-					c = PEOF;
-					plinno++;
-					needprompt = doprompt;
-				} else {
-					pushstring(line, strlen(line), NULL);
-				}
-			}
-		}
-	}
-	goto checkend_return;
-}
-
-
-/*
- * Parse a redirection operator.  The variable "out" points to a string
- * specifying the fd to be redirected.  The variable "c" contains the
- * first character of the redirection operator.
- */
-
-parseredir: {
-	char fd = *out;
-	union node *np;
-
-	np = (union node *)stalloc(sizeof (struct nfile));
-	if (c == '>') {
-		np->nfile.fd = 1;
-		c = pgetc();
-		if (c == '>')
-			np->type = NAPPEND;
-		else if (c == '|')
-			np->type = NCLOBBER;
-		else if (c == '&')
-			np->type = NTOFD;
-		else {
-			np->type = NTO;
-			pungetc();
-		}
-	} else {	/* c == '<' */
-		np->nfile.fd = 0;
-		switch (c = pgetc()) {
-		case '<':
-			if (sizeof (struct nfile) != sizeof (struct nhere)) {
-				np = (union node *)stalloc(sizeof (struct nhere));
-				np->nfile.fd = 0;
-			}
-			np->type = NHERE;
-			heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc));
-			heredoc->here = np;
-			if ((c = pgetc()) == '-') {
-				heredoc->striptabs = 1;
-			} else {
-				heredoc->striptabs = 0;
-				pungetc();
-			}
-			break;
-
-		case '&':
-			np->type = NFROMFD;
-			break;
-
-		case '>':
-			np->type = NFROMTO;
-			break;
-
-		default:
-			np->type = NFROM;
-			pungetc();
-			break;
-		}
-	}
-	if (fd != '\0')
-		np->nfile.fd = digit_val(fd);
-	redirnode = np;
-	goto parseredir_return;
-}
-
-
-/*
- * Parse a substitution.  At this point, we have read the dollar sign
- * and nothing else.
- */
-
-parsesub: {
-	int subtype;
-	int typeloc;
-	int flags;
-	char *p;
-	static const char types[] = "}-+?=";
-
-	c = pgetc();
-	if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) {
-		USTPUTC('$', out);
-		pungetc();
-	} else if (c == '(') {	/* $(command) or $((arith)) */
-		if (pgetc() == '(') {
-			PARSEARITH();
-		} else {
-			pungetc();
-			PARSEBACKQNEW();
-		}
-	} else {
-		USTPUTC(CTLVAR, out);
-		typeloc = out - stackblock();
-		USTPUTC(VSNORMAL, out);
-		subtype = VSNORMAL;
-		if (c == OPENBRACE) {
-			c = pgetc();
-			if (c == '#') {
-				if ((c = pgetc()) == CLOSEBRACE)
-					c = '#';
-				else
-					subtype = VSLENGTH;
-			}
-			else
-				subtype = 0;
-		}
-		if (is_name(c)) {
-			do {
-				STPUTC(c, out);
-				c = pgetc();
-			} while (is_in_name(c));
-		} else if (is_digit(c)) {
-			do {
-				USTPUTC(c, out);
-				c = pgetc();
-			} while (is_digit(c));
-		}
-		else if (is_special(c)) {
-			USTPUTC(c, out);
-			c = pgetc();
-		}
-		else
-badsub:			synerror("Bad substitution");
-
-		STPUTC('=', out);
-		flags = 0;
-		if (subtype == 0) {
-			switch (c) {
-			case ':':
-				flags = VSNUL;
-				c = pgetc();
-				/*FALLTHROUGH*/
-			default:
-				p = strchr(types, c);
-				if (p == NULL)
-					goto badsub;
-				subtype = p - types + VSNORMAL;
-				break;
-			case '%':
-			case '#':
-				{
-					int cc = c;
-					subtype = c == '#' ? VSTRIMLEFT :
-							     VSTRIMRIGHT;
-					c = pgetc();
-					if (c == cc)
-						subtype++;
-					else
-						pungetc();
-					break;
-				}
-			}
-		} else {
-			pungetc();
-		}
-		if (ISDBLQUOTE() || arinest)
-			flags |= VSQUOTE;
-		*(stackblock() + typeloc) = subtype | flags;
-		if (subtype != VSNORMAL) {
-			varnest++;
-			if (varnest >= maxnest) {
-				dblquotep = ckrealloc(dblquotep, maxnest / 8);
-				dblquotep[(maxnest / 32) - 1] = 0;
-				maxnest += 32;
-			}
-		}
-	}
-	goto parsesub_return;
-}
-
-
-/*
- * Called to parse command substitutions.  Newstyle is set if the command
- * is enclosed inside $(...); nlpp is a pointer to the head of the linked
- * list of commands (passed by reference), and savelen is the number of
- * characters on the top of the stack which must be preserved.
- */
-
-parsebackq: {
-	struct nodelist **nlpp;
-	int savepbq;
-	union node *n;
-	char *volatile str;
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-	int savelen;
-	int saveprompt;
-#ifdef __GNUC__
-	(void) &saveprompt;
-#endif
-
-	savepbq = parsebackquote;
-	if (setjmp(jmploc.loc)) {
-		if (str)
-			ckfree(str);
-		parsebackquote = 0;
-		handler = savehandler;
-		longjmp(handler->loc, 1);
-	}
-	INTOFF;
-	str = NULL;
-	savelen = out - stackblock();
-	if (savelen > 0) {
-		str = ckmalloc(savelen);
-		memcpy(str, stackblock(), savelen);
-	}
-	savehandler = handler;
-	handler = &jmploc;
-	INTON;
-        if (oldstyle) {
-                /* We must read until the closing backquote, giving special
-                   treatment to some slashes, and then push the string and
-                   reread it as input, interpreting it normally.  */
-                char *pout;
-                int pc;
-                int psavelen;
-                char *pstr;
-
-
-                STARTSTACKSTR(pout);
-		for (;;) {
-			if (needprompt) {
-				setprompt(2);
-				needprompt = 0;
-			}
-			switch (pc = pgetc()) {
-			case '`':
-				goto done;
-
-			case '\\':
-                                if ((pc = pgetc()) == '\n') {
-					plinno++;
-					if (doprompt)
-						setprompt(2);
-					else
-						setprompt(0);
-					/*
-					 * If eating a newline, avoid putting
-					 * the newline into the new character
-					 * stream (via the STPUTC after the
-					 * switch).
-					 */
-					continue;
-				}
-                                if (pc != '\\' && pc != '`' && pc != '$'
-                                    && (!ISDBLQUOTE() || pc != '"'))
-                                        STPUTC('\\', pout);
-				break;
-
-			case '\n':
-				plinno++;
-				needprompt = doprompt;
-				break;
-
-			case PEOF:
-			        startlinno = plinno;
-				synerror("EOF in backquote substitution");
- 				break;
-
-			default:
-				break;
-			}
-			STPUTC(pc, pout);
-                }
-done:
-                STPUTC('\0', pout);
-                psavelen = pout - stackblock();
-                if (psavelen > 0) {
-			pstr = grabstackstr(pout);
-			setinputstring(pstr, 1);
-                }
-        }
-	nlpp = &bqlist;
-	while (*nlpp)
-		nlpp = &(*nlpp)->next;
-	*nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
-	(*nlpp)->next = NULL;
-	parsebackquote = oldstyle;
-
-	if (oldstyle) {
-		saveprompt = doprompt;
-		doprompt = 0;
-	}
-
-	n = list(0);
-
-	if (oldstyle)
-		doprompt = saveprompt;
-	else {
-		if (readtoken() != TRP)
-			synexpect(TRP);
-	}
-
-	(*nlpp)->n = n;
-        if (oldstyle) {
-		/*
-		 * Start reading from old file again, ignoring any pushed back
-		 * tokens left from the backquote parsing
-		 */
-                popfile();
-		tokpushback = 0;
-	}
-	while (stackblocksize() <= savelen)
-		growstackblock();
-	STARTSTACKSTR(out);
-	if (str) {
-		memcpy(out, str, savelen);
-		STADJUST(savelen, out);
-		INTOFF;
-		ckfree(str);
-		str = NULL;
-		INTON;
-	}
-	parsebackquote = savepbq;
-	handler = savehandler;
-	if (arinest || ISDBLQUOTE())
-		USTPUTC(CTLBACKQ | CTLQUOTE, out);
-	else
-		USTPUTC(CTLBACKQ, out);
-	if (oldstyle)
-		goto parsebackq_oldreturn;
-	else
-		goto parsebackq_newreturn;
-}
-
-/*
- * Parse an arithmetic expansion (indicate start of one and set state)
- */
-parsearith: {
-
-	if (++arinest == 1) {
-		prevsyntax = syntax;
-		syntax = ARISYNTAX;
-		USTPUTC(CTLARI, out);
-		if (ISDBLQUOTE())
-			USTPUTC('"',out);
-		else
-			USTPUTC(' ',out);
-	} else {
-		/*
-		 * we collapse embedded arithmetic expansion to
-		 * parenthesis, which should be equivalent
-		 */
-		USTPUTC('(', out);
-	}
-	goto parsearith_return;
-}
-
-} /* end of readtoken */
-
-
-
-#ifdef mkinit
-RESET {
-	tokpushback = 0;
-	checkkwd = 0;
-}
-#endif
-
-/*
- * Returns true if the text contains nothing to expand (no dollar signs
- * or backquotes).
- */
-
-STATIC int
-noexpand(char *text)
-{
-	char *p;
-	char c;
-
-	p = text;
-	while ((c = *p++) != '\0') {
-		if (c == CTLQUOTEMARK)
-			continue;
-		if (c == CTLESC)
-			p++;
-		else if (BASESYNTAX[(int)c] == CCTL)
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Return true if the argument is a legal variable name (a letter or
- * underscore followed by zero or more letters, underscores, and digits).
- */
-
-int
-goodname(char *name)
-	{
-	char *p;
-
-	p = name;
-	if (! is_name(*p))
-		return 0;
-	while (*++p) {
-		if (! is_in_name(*p))
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Called when an unexpected token is read during the parse.  The argument
- * is the token that is expected, or -1 if more than one type of token can
- * occur at this point.
- */
-
-STATIC void
-synexpect(int token)
-{
-	char msg[64];
-
-	if (token >= 0) {
-		fmtstr(msg, 64, "%s unexpected (expecting %s)",
-			tokname[lasttoken], tokname[token]);
-	} else {
-		fmtstr(msg, 64, "%s unexpected", tokname[lasttoken]);
-	}
-	synerror(msg);
-	/* NOTREACHED */
-}
-
-
-STATIC void
-synerror(const char *msg)
-{
-	if (commandname)
-		outfmt(&errout, "%s: %d: ", commandname, startlinno);
-	outfmt(&errout, "Syntax error: %s\n", msg);
-	error((char *)NULL);
-	/* NOTREACHED */
-}
-
-STATIC void
-setprompt(int which)
-{
-	whichprompt = which;
-
-#ifndef SMALL
-	if (!el)
-#endif
-		out2str(getprompt(NULL));
-}
-
-/*
- * called by editline -- any expansions to the prompt
- *    should be added here.
- */
-const char *
-getprompt(void *unused)
-	{
-	switch (whichprompt) {
-	case 0:
-		return "";
-	case 1:
-		return ps1val();
-	case 2:
-		return ps2val();
-	default:
-		return "<internal prompt error>";
-	}
-}
diff --git a/src/ash/parser.h b/src/ash/parser.h
deleted file mode 100644
index b343c71..0000000
--- a/src/ash/parser.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*	$NetBSD: parser.h,v 1.17 2004/06/26 22:09:49 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)parser.h	8.3 (Berkeley) 5/4/95
- */
-
-/* control characters in argument strings */
-#define CTL_FIRST '\201'	/* first 'special' character */
-#define CTLESC '\201'		/* escape next character */
-#define CTLVAR '\202'		/* variable defn */
-#define CTLENDVAR '\203'
-#define CTLBACKQ '\204'
-#define CTLQUOTE 01		/* ored with CTLBACKQ code if in quotes */
-/*	CTLBACKQ | CTLQUOTE == '\205' */
-#define	CTLARI	'\206'		/* arithmetic expression */
-#define	CTLENDARI '\207'
-#define	CTLQUOTEMARK '\210'
-#define	CTLQUOTEEND '\211'	/* only inside ${...} */
-#define	CTL_LAST '\211'		/* last 'special' character */
-
-/* variable substitution byte (follows CTLVAR) */
-#define VSTYPE	0x0f		/* type of variable substitution */
-#define VSNUL	0x10		/* colon--treat the empty string as unset */
-#define VSQUOTE 0x80		/* inside double quotes--suppress splitting */
-
-/* values of VSTYPE field */
-#define VSNORMAL	0x1		/* normal variable:  $var or ${var} */
-#define VSMINUS		0x2		/* ${var-text} */
-#define VSPLUS		0x3		/* ${var+text} */
-#define VSQUESTION	0x4		/* ${var?message} */
-#define VSASSIGN	0x5		/* ${var=text} */
-#define VSTRIMLEFT	0x6		/* ${var#pattern} */
-#define VSTRIMLEFTMAX	0x7		/* ${var##pattern} */
-#define VSTRIMRIGHT	0x8		/* ${var%pattern} */
-#define VSTRIMRIGHTMAX 	0x9		/* ${var%%pattern} */
-#define VSLENGTH	0xa		/* ${#var} */
-
-
-/*
- * NEOF is returned by parsecmd when it encounters an end of file.  It
- * must be distinct from NULL, so we use the address of a variable that
- * happens to be handy.
- */
-extern int tokpushback;
-#define NEOF ((union node *)&tokpushback)
-extern int whichprompt;		/* 1 == PS1, 2 == PS2 */
-
-
-union node *parsecmd(int);
-void fixredir(union node *, const char *, int);
-int goodname(char *);
-const char *getprompt(void *);
diff --git a/src/ash/redir.c b/src/ash/redir.c
deleted file mode 100644
index 825c9b9..0000000
--- a/src/ash/redir.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/*	$NetBSD: redir.c,v 1.29 2004/07/08 03:57:33 christos Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)redir.c	8.2 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: redir.c,v 1.29 2004/07/08 03:57:33 christos Exp $");
-#endif
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/param.h>	/* PIPE_BUF */
-#include <signal.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-/*
- * Code for dealing with input/output redirection.
- */
-
-#include "main.h"
-#include "shell.h"
-#include "nodes.h"
-#include "jobs.h"
-#include "options.h"
-#include "expand.h"
-#include "redir.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-
-
-#define EMPTY -2		/* marks an unused slot in redirtab */
-#ifndef PIPE_BUF
-# define PIPESIZE 4096		/* amount of buffering in a pipe */
-#else
-# define PIPESIZE PIPE_BUF
-#endif
-
-
-MKINIT
-struct redirtab {
-	struct redirtab *next;
-	short renamed[10];
-};
-
-
-MKINIT struct redirtab *redirlist;
-
-/*
- * We keep track of whether or not fd0 has been redirected.  This is for
- * background commands, where we want to redirect fd0 to /dev/null only
- * if it hasn't already been redirected.
-*/
-int fd0_redirected = 0;
-
-STATIC void openredirect(union node *, char[10], int);
-STATIC int openhere(union node *);
-
-
-/*
- * Process a list of redirection commands.  If the REDIR_PUSH flag is set,
- * old file descriptors are stashed away so that the redirection can be
- * undone by calling popredir.  If the REDIR_BACKQ flag is set, then the
- * standard output, and the standard error if it becomes a duplicate of
- * stdout, is saved in memory.
- */
-
-void
-redirect(union node *redir, int flags)
-{
-	union node *n;
-	struct redirtab *sv = NULL;
-	int i;
-	int fd;
-	int try;
-	char memory[10];	/* file descriptors to write to memory */
-
-	for (i = 10 ; --i >= 0 ; )
-		memory[i] = 0;
-	memory[1] = flags & REDIR_BACKQ;
-	if (flags & REDIR_PUSH) {
-		/* We don't have to worry about REDIR_VFORK here, as
-		 * flags & REDIR_PUSH is never true if REDIR_VFORK is set.
-		 */
-		sv = ckmalloc(sizeof (struct redirtab));
-		for (i = 0 ; i < 10 ; i++)
-			sv->renamed[i] = EMPTY;
-		sv->next = redirlist;
-		redirlist = sv;
-	}
-	for (n = redir ; n ; n = n->nfile.next) {
-		fd = n->nfile.fd;
-		try = 0;
-		if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) &&
-		    n->ndup.dupfd == fd)
-			continue; /* redirect from/to same file descriptor */
-
-		if ((flags & REDIR_PUSH) && sv->renamed[fd] == EMPTY) {
-			INTOFF;
-again:
-			if ((i = fcntl(fd, F_DUPFD, 10)) == -1) {
-				switch (errno) {
-				case EBADF:
-					if (!try) {
-						openredirect(n, memory, flags);
-						try++;
-						goto again;
-					}
-					/* FALLTHROUGH*/
-				default:
-					INTON;
-					error("%d: %s", fd, strerror(errno));
-					/* NOTREACHED */
-				}
-			}
-			if (!try) {
-				sv->renamed[fd] = i;
-				close(fd);
-			}
-			INTON;
-		} else {
-			close(fd);
-		}
-                if (fd == 0)
-                        fd0_redirected++;
-		if (!try)
-			openredirect(n, memory, flags);
-	}
-	if (memory[1])
-		out1 = &memout;
-	if (memory[2])
-		out2 = &memout;
-}
-
-
-STATIC void
-openredirect(union node *redir, char memory[10], int flags)
-{
-	int fd = redir->nfile.fd;
-	char *fname;
-	int f;
-	int oflags = O_WRONLY|O_CREAT|O_TRUNC, eflags;
-
-	/*
-	 * We suppress interrupts so that we won't leave open file
-	 * descriptors around.  This may not be such a good idea because
-	 * an open of a device or a fifo can block indefinitely.
-	 */
-	INTOFF;
-	memory[fd] = 0;
-	switch (redir->nfile.type) {
-	case NFROM:
-		fname = redir->nfile.expfname;
-		if (flags & REDIR_VFORK)
-			eflags = O_NONBLOCK;
-		else
-			eflags = 0;
-		if ((f = open(fname, O_RDONLY|eflags)) < 0)
-			goto eopen;
-		if (eflags)
-			(void)fcntl(f, F_SETFL, fcntl(f, F_GETFL, 0) & ~eflags);
-		break;
-	case NFROMTO:
-		fname = redir->nfile.expfname;
-		if ((f = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
-			goto ecreate;
-		break;
-	case NTO:
-		if (Cflag)
-			oflags |= O_EXCL;
-		/* FALLTHROUGH */
-	case NCLOBBER:
-		fname = redir->nfile.expfname;
-		if ((f = open(fname, oflags, 0666)) < 0)
-			goto ecreate;
-		break;
-	case NAPPEND:
-		fname = redir->nfile.expfname;
-		if ((f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
-			goto ecreate;
-		break;
-	case NTOFD:
-	case NFROMFD:
-		if (redir->ndup.dupfd >= 0) {	/* if not ">&-" */
-			if (memory[redir->ndup.dupfd])
-				memory[fd] = 1;
-			else
-				copyfd(redir->ndup.dupfd, fd);
-		}
-		INTON;
-		return;
-	case NHERE:
-	case NXHERE:
-		f = openhere(redir);
-		break;
-	default:
-		abort();
-	}
-
-	if (f != fd) {
-		copyfd(f, fd);
-		close(f);
-	}
-	INTON;
-	return;
-ecreate:
-	error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-eopen:
-	error("cannot open %s: %s", fname, errmsg(errno, E_OPEN));
-}
-
-
-/*
- * Handle here documents.  Normally we fork off a process to write the
- * data to a pipe.  If the document is short, we can stuff the data in
- * the pipe without forking.
- */
-
-STATIC int
-openhere(union node *redir)
-{
-	int pip[2];
-	int len = 0;
-
-	if (pipe(pip) < 0)
-		error("Pipe call failed");
-	if (redir->type == NHERE) {
-		len = strlen(redir->nhere.doc->narg.text);
-		if (len <= PIPESIZE) {
-			xwrite(pip[1], redir->nhere.doc->narg.text, len);
-			goto out;
-		}
-	}
-	if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) {
-		close(pip[0]);
-		signal(SIGINT, SIG_IGN);
-		signal(SIGQUIT, SIG_IGN);
-		signal(SIGHUP, SIG_IGN);
-#ifdef SIGTSTP
-		signal(SIGTSTP, SIG_IGN);
-#endif
-		signal(SIGPIPE, SIG_DFL);
-		if (redir->type == NHERE)
-			xwrite(pip[1], redir->nhere.doc->narg.text, len);
-		else
-			expandhere(redir->nhere.doc, pip[1]);
-		_exit(0);
-	}
-out:
-	close(pip[1]);
-	return pip[0];
-}
-
-
-
-/*
- * Undo the effects of the last redirection.
- */
-
-void
-popredir(void)
-{
-	struct redirtab *rp = redirlist;
-	int i;
-
-	for (i = 0 ; i < 10 ; i++) {
-		if (rp->renamed[i] != EMPTY) {
-                        if (i == 0)
-                                fd0_redirected--;
-			close(i);
-			if (rp->renamed[i] >= 0) {
-				copyfd(rp->renamed[i], i);
-				close(rp->renamed[i]);
-			}
-		}
-	}
-	INTOFF;
-	redirlist = rp->next;
-	ckfree(rp);
-	INTON;
-}
-
-/*
- * Undo all redirections.  Called on error or interrupt.
- */
-
-#ifdef mkinit
-
-INCLUDE "redir.h"
-
-RESET {
-	while (redirlist)
-		popredir();
-}
-
-SHELLPROC {
-	clearredir(0);
-}
-
-#endif
-
-/* Return true if fd 0 has already been redirected at least once.  */
-int
-fd0_redirected_p () {
-        return fd0_redirected != 0;
-}
-
-/*
- * Discard all saved file descriptors.
- */
-
-void
-clearredir(vforked)
-	int vforked;
-{
-	struct redirtab *rp;
-	int i;
-
-	for (rp = redirlist ; rp ; rp = rp->next) {
-		for (i = 0 ; i < 10 ; i++) {
-			if (rp->renamed[i] >= 0) {
-				close(rp->renamed[i]);
-			}
-			if (!vforked)
-				rp->renamed[i] = EMPTY;
-		}
-	}
-}
-
-
-
-/*
- * Copy a file descriptor to be >= to.  Returns -1
- * if the source file descriptor is closed, EMPTY if there are no unused
- * file descriptors left.
- */
-
-int
-copyfd(int from, int to)
-{
-	int newfd;
-
-	newfd = fcntl(from, F_DUPFD, to);
-	if (newfd < 0) {
-		if (errno == EMFILE)
-			return EMPTY;
-		else
-			error("%d: %s", from, strerror(errno));
-	}
-	return newfd;
-}
diff --git a/src/ash/redir.h b/src/ash/redir.h
deleted file mode 100644
index c9709e9..0000000
--- a/src/ash/redir.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$NetBSD: redir.h,v 1.15 2003/08/07 09:05:37 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)redir.h	8.2 (Berkeley) 5/4/95
- */
-
-/* flags passed to redirect */
-#define REDIR_PUSH 01		/* save previous values of file descriptors */
-#define REDIR_BACKQ 02		/* save the command output in memory */
-#define REDIR_VFORK 04		/* running under vfork(2), be careful */
-
-union node;
-void redirect(union node *, int);
-void popredir(void);
-int fd0_redirected_p(void);
-void clearredir(int);
-int copyfd(int, int);
-
diff --git a/src/ash/setmode.c b/src/ash/setmode.c
deleted file mode 100644
index c2b5f34..0000000
--- a/src/ash/setmode.c
+++ /dev/null
@@ -1,501 +0,0 @@
-/*	$NetBSD: setmode.c,v 1.30 2003/08/07 16:42:56 agc Exp $	*/
-
-/*
- * Copyright (c) 1989, 1993, 1994
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Dave Borman at Cray Research, Inc.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-/*#include <sys/cdefs.h>*/
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)setmode.c	8.2 (Berkeley) 3/25/94";
-#else
-__RCSID("$NetBSD: setmode.c,v 1.30 2003/08/07 16:42:56 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-/*#include "namespace.h"*/
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#ifndef _MSC_VER
-#include <unistd.h>
-#else
-#include "mscfakes.h"
-#endif 
-
-#ifdef SETMODE_DEBUG
-#include <stdio.h>
-#endif
-
-/*#ifdef __weak_alias
-__weak_alias(getmode,_getmode)
-__weak_alias(setmode,_setmode)
-#endif*/
-
-#define	SET_LEN	6		/* initial # of bitcmd struct to malloc */
-#define	SET_LEN_INCR 4		/* # of bitcmd structs to add as needed */
-
-typedef struct bitcmd {
-	char	cmd;
-	char	cmd2;
-	mode_t	bits;
-} BITCMD;
-
-#define	CMD2_CLR	0x01
-#define	CMD2_SET	0x02
-#define	CMD2_GBITS	0x04
-#define	CMD2_OBITS	0x08
-#define	CMD2_UBITS	0x10
-
-static BITCMD	*addcmd(BITCMD *, int, int, int, u_int);
-static void	 compress_mode(BITCMD *);
-#ifdef SETMODE_DEBUG
-static void	 dumpmode(BITCMD *);
-#endif
-
-#ifndef _DIAGASSERT
-# define _DIAGASSERT assert
-#endif 
-
-#ifndef S_ISTXT
-# ifdef S_ISVTX
-#  define S_ISTXT S_ISVTX
-# else
-#  define S_ISTXT 0
-# endif
-#endif /* !S_ISTXT */
-
-/*
- * Given the old mode and an array of bitcmd structures, apply the operations
- * described in the bitcmd structures to the old mode, and return the new mode.
- * Note that there is no '=' command; a strict assignment is just a '-' (clear
- * bits) followed by a '+' (set bits).
- */
-mode_t
-getmode(bbox, omode)
-	const void *bbox;
-	mode_t omode;
-{
-	const BITCMD *set;
-	mode_t clrval, newmode, value;
-
-	_DIAGASSERT(bbox != NULL);
-
-	set = (const BITCMD *)bbox;
-	newmode = omode;
-	for (value = 0;; set++)
-		switch(set->cmd) {
-		/*
-		 * When copying the user, group or other bits around, we "know"
-		 * where the bits are in the mode so that we can do shifts to
-		 * copy them around.  If we don't use shifts, it gets real
-		 * grundgy with lots of single bit checks and bit sets.
-		 */
-		case 'u':
-			value = (newmode & S_IRWXU) >> 6;
-			goto common;
-
-		case 'g':
-			value = (newmode & S_IRWXG) >> 3;
-			goto common;
-
-		case 'o':
-			value = newmode & S_IRWXO;
-common:			if (set->cmd2 & CMD2_CLR) {
-				clrval =
-				    (set->cmd2 & CMD2_SET) ?  S_IRWXO : value;
-				if (set->cmd2 & CMD2_UBITS)
-					newmode &= ~((clrval<<6) & set->bits);
-				if (set->cmd2 & CMD2_GBITS)
-					newmode &= ~((clrval<<3) & set->bits);
-				if (set->cmd2 & CMD2_OBITS)
-					newmode &= ~(clrval & set->bits);
-			}
-			if (set->cmd2 & CMD2_SET) {
-				if (set->cmd2 & CMD2_UBITS)
-					newmode |= (value<<6) & set->bits;
-				if (set->cmd2 & CMD2_GBITS)
-					newmode |= (value<<3) & set->bits;
-				if (set->cmd2 & CMD2_OBITS)
-					newmode |= value & set->bits;
-			}
-			break;
-
-		case '+':
-			newmode |= set->bits;
-			break;
-
-		case '-':
-			newmode &= ~set->bits;
-			break;
-
-		case 'X':
-			if (omode & (S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH))
-				newmode |= set->bits;
-			break;
-
-		case '\0':
-		default:
-#ifdef SETMODE_DEBUG
-			(void)printf("getmode:%04o -> %04o\n", omode, newmode);
-#endif
-			return (newmode);
-		}
-}
-
-#define	ADDCMD(a, b, c, d) do {						\
-	if (set >= endset) {						\
-		BITCMD *newset;						\
-		setlen += SET_LEN_INCR;					\
-		newset = realloc(saveset, sizeof(BITCMD) * setlen);	\
-		if (newset == NULL) {					\
-			free(saveset);					\
-			return (NULL);					\
-		}							\
-		set = newset + (set - saveset);				\
-		saveset = newset;					\
-		endset = newset + (setlen - 2);				\
-	}								\
-	set = addcmd(set, (a), (b), (c), (d));				\
-} while (/*CONSTCOND*/0)
-
-#define	STANDARD_BITS	(S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
-
-void *
-setmode(p)
-	const char *p;
-{
-	int perm, who;
-	char op, *ep;
-	BITCMD *set, *saveset, *endset;
-#ifndef _MSC_VER
-	sigset_t signset, sigoset;
-#endif
-	mode_t mask;
-	int equalopdone = 0;	/* pacify gcc */
-	int permXbits, setlen;
-
-	if (!*p)
-		return (NULL);
-
-	/*
-	 * Get a copy of the mask for the permissions that are mask relative.
-	 * Flip the bits, we want what's not set.  Since it's possible that
-	 * the caller is opening files inside a signal handler, protect them
-	 * as best we can.
-	 */
-#ifndef _MSC_VER
-	sigfillset(&signset);
-	(void)sigprocmask(SIG_BLOCK, &signset, &sigoset);
-#endif 
-	(void)umask(mask = umask(0));
-	mask = ~mask;
-#ifndef _MSC_VER
-	(void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
-#endif
-
-	setlen = SET_LEN + 2;
-	
-	if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL)
-		return (NULL);
-	saveset = set;
-	endset = set + (setlen - 2);
-
-	/*
-	 * If an absolute number, get it and return; disallow non-octal digits
-	 * or illegal bits.
-	 */
-	if (isdigit((unsigned char)*p)) {
-		perm = (mode_t)strtol(p, &ep, 8);
-		if (*ep || perm & ~(STANDARD_BITS|S_ISTXT)) {
-			free(saveset);
-			return (NULL);
-		}
-		ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
-		set->cmd = 0;
-		return (saveset);
-	}
-
-	/*
-	 * Build list of structures to set/clear/copy bits as described by
-	 * each clause of the symbolic mode.
-	 */
-	for (;;) {
-		/* First, find out which bits might be modified. */
-		for (who = 0;; ++p) {
-			switch (*p) {
-			case 'a':
-				who |= STANDARD_BITS;
-				break;
-			case 'u':
-				who |= S_ISUID|S_IRWXU;
-				break;
-			case 'g':
-				who |= S_ISGID|S_IRWXG;
-				break;
-			case 'o':
-				who |= S_IRWXO;
-				break;
-			default:
-				goto getop;
-			}
-		}
-
-getop:		if ((op = *p++) != '+' && op != '-' && op != '=') {
-			free(saveset);
-			return (NULL);
-		}
-		if (op == '=')
-			equalopdone = 0;
-
-		who &= ~S_ISTXT;
-		for (perm = 0, permXbits = 0;; ++p) {
-			switch (*p) {
-			case 'r':
-				perm |= S_IRUSR|S_IRGRP|S_IROTH;
-				break;
-			case 's':
-				/*
-				 * If specific bits where requested and 
-				 * only "other" bits ignore set-id. 
-				 */
-				if (who == 0 || (who & ~S_IRWXO))
-					perm |= S_ISUID|S_ISGID;
-				break;
-			case 't':
-				/*
-				 * If specific bits where requested and 
-				 * only "other" bits ignore set-id. 
-				 */
-				if (who == 0 || (who & ~S_IRWXO)) {
-					who |= S_ISTXT;
-					perm |= S_ISTXT;
-				}
-				break;
-			case 'w':
-				perm |= S_IWUSR|S_IWGRP|S_IWOTH;
-				break;
-			case 'X':
-				permXbits = S_IXUSR|S_IXGRP|S_IXOTH;
-				break;
-			case 'x':
-				perm |= S_IXUSR|S_IXGRP|S_IXOTH;
-				break;
-			case 'u':
-			case 'g':
-			case 'o':
-				/*
-				 * When ever we hit 'u', 'g', or 'o', we have
-				 * to flush out any partial mode that we have,
-				 * and then do the copying of the mode bits.
-				 */
-				if (perm) {
-					ADDCMD(op, who, perm, mask);
-					perm = 0;
-				}
-				if (op == '=')
-					equalopdone = 1;
-				if (op == '+' && permXbits) {
-					ADDCMD('X', who, permXbits, mask);
-					permXbits = 0;
-				}
-				ADDCMD(*p, who, op, mask);
-				break;
-
-			default:
-				/*
-				 * Add any permissions that we haven't already
-				 * done.
-				 */
-				if (perm || (op == '=' && !equalopdone)) {
-					if (op == '=')
-						equalopdone = 1;
-					ADDCMD(op, who, perm, mask);
-					perm = 0;
-				}
-				if (permXbits) {
-					ADDCMD('X', who, permXbits, mask);
-					permXbits = 0;
-				}
-				goto apply;
-			}
-		}
-
-apply:		if (!*p)
-			break;
-		if (*p != ',')
-			goto getop;
-		++p;
-	}
-	set->cmd = 0;
-#ifdef SETMODE_DEBUG
-	(void)printf("Before compress_mode()\n");
-	dumpmode(saveset);
-#endif
-	compress_mode(saveset);
-#ifdef SETMODE_DEBUG
-	(void)printf("After compress_mode()\n");
-	dumpmode(saveset);
-#endif
-	return (saveset);
-}
-
-static BITCMD *
-addcmd(set, op, who, oparg, mask)
-	BITCMD *set;
-	int oparg, who;
-	int op;
-	u_int mask;
-{
-
-	_DIAGASSERT(set != NULL);
-
-	switch (op) {
-	case '=':
-		set->cmd = '-';
-		set->bits = who ? who : STANDARD_BITS;
-		set++;
-
-		op = '+';
-		/* FALLTHROUGH */
-	case '+':
-	case '-':
-	case 'X':
-		set->cmd = op;
-		set->bits = (who ? who : mask) & oparg;
-		break;
-
-	case 'u':
-	case 'g':
-	case 'o':
-		set->cmd = op;
-		if (who) {
-			set->cmd2 = ((who & S_IRUSR) ? CMD2_UBITS : 0) |
-				    ((who & S_IRGRP) ? CMD2_GBITS : 0) |
-				    ((who & S_IROTH) ? CMD2_OBITS : 0);
-			set->bits = (mode_t)~0;
-		} else {
-			set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS;
-			set->bits = mask;
-		}
-	
-		if (oparg == '+')
-			set->cmd2 |= CMD2_SET;
-		else if (oparg == '-')
-			set->cmd2 |= CMD2_CLR;
-		else if (oparg == '=')
-			set->cmd2 |= CMD2_SET|CMD2_CLR;
-		break;
-	}
-	return (set + 1);
-}
-
-#ifdef SETMODE_DEBUG
-static void
-dumpmode(set)
-	BITCMD *set;
-{
-
-	_DIAGASSERT(set != NULL);
-
-	for (; set->cmd; ++set)
-		(void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n",
-		    set->cmd, set->bits, set->cmd2 ? " cmd2:" : "",
-		    set->cmd2 & CMD2_CLR ? " CLR" : "",
-		    set->cmd2 & CMD2_SET ? " SET" : "",
-		    set->cmd2 & CMD2_UBITS ? " UBITS" : "",
-		    set->cmd2 & CMD2_GBITS ? " GBITS" : "",
-		    set->cmd2 & CMD2_OBITS ? " OBITS" : "");
-}
-#endif
-
-/*
- * Given an array of bitcmd structures, compress by compacting consecutive
- * '+', '-' and 'X' commands into at most 3 commands, one of each.  The 'u',
- * 'g' and 'o' commands continue to be separate.  They could probably be 
- * compacted, but it's not worth the effort.
- */
-static void
-compress_mode(set)
-	BITCMD *set;
-{
-	BITCMD *nset;
-	int setbits, clrbits, Xbits, op;
-
-	_DIAGASSERT(set != NULL);
-
-	for (nset = set;;) {
-		/* Copy over any 'u', 'g' and 'o' commands. */
-		while ((op = nset->cmd) != '+' && op != '-' && op != 'X') {
-			*set++ = *nset++;
-			if (!op)
-				return;
-		}
-
-		for (setbits = clrbits = Xbits = 0;; nset++) {
-			if ((op = nset->cmd) == '-') {
-				clrbits |= nset->bits;
-				setbits &= ~nset->bits;
-				Xbits &= ~nset->bits;
-			} else if (op == '+') {
-				setbits |= nset->bits;
-				clrbits &= ~nset->bits;
-				Xbits &= ~nset->bits;
-			} else if (op == 'X')
-				Xbits |= nset->bits & ~setbits;
-			else
-				break;
-		}
-		if (clrbits) {
-			set->cmd = '-';
-			set->cmd2 = 0;
-			set->bits = clrbits;
-			set++;
-		}
-		if (setbits) {
-			set->cmd = '+';
-			set->cmd2 = 0;
-			set->bits = setbits;
-			set++;
-		}
-		if (Xbits) {
-			set->cmd = 'X';
-			set->cmd2 = 0;
-			set->bits = Xbits;
-			set++;
-		}
-	}
-}
diff --git a/src/ash/sh.1 b/src/ash/sh.1
deleted file mode 100644
index a116652..0000000
--- a/src/ash/sh.1
+++ /dev/null
@@ -1,1949 +0,0 @@
-.\"	$NetBSD: sh.1,v 1.80 2005/05/24 00:03:52 wiz Exp $
-.\" Copyright (c) 1991, 1993
-.\"	The Regents of the University of California.  All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Kenneth Almquist.
-.\"
-.\" 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 the University 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 REGENTS 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 REGENTS 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.
-.\"
-.\"	@(#)sh.1	8.6 (Berkeley) 5/4/95
-.\"
-.Dd May 7, 2005
-.Os
-.Dt SH 1
-.Sh NAME
-.Nm sh
-.Nd command interpreter (shell)
-.Sh SYNOPSIS
-.Nm
-.Bk -words
-.Op Fl aCefnuvxIimqVEb
-.Op Cm +aCefnuvxIimqVEb
-.Ek
-.Bk -words
-.Op Fl o Ar option_name
-.Op Cm +o Ar option_name
-.Ek
-.Bk -words
-.Op Ar command_file Oo Ar argument ... Oc
-.Ek
-.Nm
-.Fl c
-.Bk -words
-.Op Fl aCefnuvxIimqVEb
-.Op Cm +aCefnuvxIimqVEb
-.Ek
-.Bk -words
-.Op Fl o Ar option_name
-.Op Cm +o Ar option_name
-.Ek
-.Bk -words
-.Ar command_string
-.Op Ar command_name Oo Ar argument ... Oc
-.Ek
-.Nm
-.Fl s
-.Bk -words
-.Op Fl aCefnuvxIimqVEb
-.Op Cm +aCefnuvxIimqVEb
-.Ek
-.Bk -words
-.Op Fl o Ar option_name
-.Op Cm +o Ar option_name
-.Ek
-.Bk -words
-.Op Ar argument ...
-.Ek
-.Sh DESCRIPTION
-.Nm
-is the standard command interpreter for the system.
-The current version of
-.Nm
-is in the process of being changed to conform with the
-.Tn POSIX
-1003.2 and 1003.2a specifications for the shell.
-This version has many
-features which make it appear similar in some respects to the Korn shell,
-but it is not a Korn shell clone (see
-.Xr ksh 1 ) .
-Only features designated by
-.Tn POSIX ,
-plus a few Berkeley extensions, are being incorporated into this shell.
-.\" We expect
-.\" .Tn POSIX
-.\" conformance by the time 4.4 BSD is released.
-This man page is not intended
-to be a tutorial or a complete specification of the shell.
-.Ss Overview
-The shell is a command that reads lines from either a file or the
-terminal, interprets them, and generally executes other commands.
-It is the program that is running when a user logs into the system
-(although a user can select a different shell with the
-.Xr chsh 1
-command).
-The shell implements a language that has flow control
-constructs, a macro facility that provides a variety of features in
-addition to data storage, along with built in history and line editing
-capabilities.
-It incorporates many features to aid interactive use and
-has the advantage that the interpretative language is common to both
-interactive and non-interactive use (shell scripts).
-That is, commands
-can be typed directly to the running shell or can be put into a file and
-the file can be executed directly by the shell.
-.Ss Invocation
-If no args are present and if the standard input of the shell
-is connected to a terminal (or if the
-.Fl i
-flag is set),
-and the
-.Fl c
-option is not present, the shell is considered an interactive shell.
-An interactive shell generally prompts before each command and handles
-programming and command errors differently (as described below).
-When first starting,
-the shell inspects argument 0, and if it begins with a dash
-.Sq - ,
-the shell is also considered
-a login shell.
-This is normally done automatically by the system
-when the user first logs in.
-A login shell first reads commands
-from the files
-.Pa /etc/profile
-and
-.Pa .profile
-if they exist.
-If the environment variable
-.Ev ENV
-is set on entry to a shell, or is set in the
-.Pa .profile
-of a login shell, the shell next reads
-commands from the file named in
-.Ev ENV .
-Therefore, a user should place commands that are to be executed only at
-login time in the
-.Pa .profile
-file, and commands that are executed for every shell inside the
-.Ev ENV
-file.
-To set the
-.Ev ENV
-variable to some file, place the following line in your
-.Pa .profile
-of your home directory
-.Pp
-.Dl ENV=$HOME/.shinit; export ENV
-.Pp
-substituting for
-.Dq .shinit
-any filename you wish.
-Since the
-.Ev ENV
-file is read for every invocation of the shell, including shell scripts
-and non-interactive shells, the following paradigm is useful for
-restricting commands in the
-.Ev ENV
-file to interactive invocations.
-Place commands within the
-.Dq case
-and
-.Dq esac
-below (these commands are described later):
-.Pp
-.Bl -item -compact -offset indent
-.It
-.Li case $- in *i*)
-.Bl -item -compact -offset indent
-.It
-.Li # commands for interactive use only
-.It
-.Li ...
-.El
-.It
-.Li esac
-.El
-.Pp
-If command line arguments besides the options have been specified, then
-the shell treats the first argument as the name of a file from which to
-read commands (a shell script), and the remaining arguments are set as the
-positional parameters of the shell ($1, $2, etc).
-Otherwise, the shell
-reads commands from its standard input.
-.Ss Argument List Processing
-All of the single letter options have a corresponding name that can be
-used as an argument to the
-.Fl o
-option.
-The set
-.Fl o
-name is provided next to the single letter option in
-the description below.
-Specifying a dash
-.Dq -
-turns the option on, while using a plus
-.Dq +
-disables the option.
-The following options can be set from the command line or
-with the
-.Ic set
-builtin (described later).
-.Bl -tag -width aaaallexportfoo -offset indent
-.It Fl a Em allexport
-Export all variables assigned to.
-.It Fl c
-Read commands from the
-.Ar command_string
-operand instead of from the standard input.
-Special parameter 0 will be set from the
-.Ar command_name
-operand and the positional parameters ($1, $2, etc.)
-set from the remaining argument operands.
-.It Fl C Em noclobber
-Don't overwrite existing files with
-.Dq \*[Gt] .
-.It Fl e Em errexit
-If not interactive, exit immediately if any untested command fails.
-The exit status of a command is considered to be
-explicitly tested if the command is used to control an
-.Ic if ,
-.Ic elif ,
-.Ic while ,
-or
-.Ic until ;
-or if the command is the left hand operand of an
-.Dq \*[Am]\*[Am]
-or
-.Dq ||
-operator.
-.It Fl f Em noglob
-Disable pathname expansion.
-.It Fl n Em noexec
-If not interactive, read commands but do not execute them.
-This is useful for checking the syntax of shell scripts.
-.It Fl u Em nounset
-Write a message to standard error when attempting to expand a variable
-that is not set, and if the shell is not interactive, exit immediately.
-.It Fl v Em verbose
-The shell writes its input to standard error as it is read.
-Useful for debugging.
-.It Fl x Em xtrace
-Write each command to standard error (preceded by a
-.Sq +\  )
-before it is executed.
-Useful for debugging.
-.It Fl q Em quietprofile
-If the
-.Fl v
-or
-.Fl x
-options have been set, do not apply them when reading
-initialization files, these being
-.Pa /etc/profile ,
-.Pa .profile ,
-and the file specified by the
-.Ev ENV
-environment variable.
-.It Fl I Em ignoreeof
-Ignore EOF's from input when interactive.
-.It Fl i Em interactive
-Force the shell to behave interactively.
-.It Fl m Em monitor
-Turn on job control (set automatically when interactive).
-.It Fl s Em stdin
-Read commands from standard input (set automatically if no file arguments
-are present).
-This option has no effect when set after the shell has
-already started running (i.e. with
-.Ic set ) .
-.It Fl V Em vi
-Enable the built-in
-.Xr vi 1
-command line editor (disables
-.Fl E
-if it has been set).
-(See the
-.Sx Command Line Editing
-section below.)
-.It Fl E Em emacs
-Enable the built-in emacs style
-command line editor (disables
-.Fl V
-if it has been set).
-(See the
-.Sx Command Line Editing
-section below.)
-.It Fl b Em notify
-Enable asynchronous notification of background job completion.
-(UNIMPLEMENTED for 4.4alpha)
-.It "\ \ " Em cdprint
-Make an interactive shell always print the new directory name when
-changed by the
-.Ic cd
-command.
-.It "\ \ " Em tabcomplete
-Enables filename completion in the command line editor.
-Typing a tab character will extend the current input word to match a
-filename.
-If more than one filename matches it is only extended to be the common prefix.
-Typing a second tab character will list all the matching names.
-.El
-.Ss Lexical Structure
-The shell reads input in terms of lines from a file and breaks it up into
-words at whitespace (blanks and tabs), and at certain sequences of
-characters that are special to the shell called
-.Dq operators .
-There are two types of operators: control operators and redirection
-operators (their meaning is discussed later).
-Following is a list of operators:
-.Bl -ohang -offset indent
-.It "Control operators:"
-.Dl \*[Am]  \*[Am]\*[Am]  \&(  \&)  \&;  ;; | || \*[Lt]newline\*[Gt]
-.It "Redirection operators:"
-.Dl \*[Lt]  \*[Gt]  \*[Gt]|  \*[Lt]\*[Lt]  \*[Gt]\*[Gt]  \*[Lt]\*[Am]  \*[Gt]\*[Am]  \*[Lt]\*[Lt]-  \*[Lt]\*[Gt]
-.El
-.Ss Quoting
-Quoting is used to remove the special meaning of certain characters or
-words to the shell, such as operators, whitespace, or keywords.
-There are three types of quoting: matched single quotes,
-matched double quotes, and backslash.
-.Ss Backslash
-A backslash preserves the literal meaning of the following
-character, with the exception of
-.Aq newline .
-A backslash preceding a
-.Aq newline
-is treated as a line continuation.
-.Ss Single Quotes
-Enclosing characters in single quotes preserves the literal meaning of all
-the characters (except single quotes, making it impossible to put
-single-quotes in a single-quoted string).
-.Ss Double Quotes
-Enclosing characters within double quotes preserves the literal
-meaning of all characters except dollarsign
-.Pq $ ,
-backquote
-.Pq ` ,
-and backslash
-.Pq \e .
-The backslash inside double quotes is historically weird, and serves to
-quote only the following characters:
-.Dl $  `  \*q  \e  \*[Lt]newline\*[Gt] .
-Otherwise it remains literal.
-.Ss Reserved Words
-Reserved words are words that have special meaning to the
-shell and are recognized at the beginning of a line and
-after a control operator.
-The following are reserved words:
-.Bl -column while while while while while -offset indent
-.It ! Ta elif Ta fi Ta while Ta case
-.It else Ta for Ta then Ta { Ta }
-.It do Ta done Ta until Ta if Ta esac
-.El
-.Pp
-Their meaning is discussed later.
-.Ss Aliases
-An alias is a name and corresponding value set using the
-.Ic alias
-builtin command.
-Whenever a reserved word may occur (see above),
-and after checking for reserved words, the shell
-checks the word to see if it matches an alias.
-If it does, it replaces it in the input stream with its value.
-For example, if there is an alias called
-.Dq lf
-with the value
-.Dq "ls -F" ,
-then the input:
-.Pp
-.Dl lf foobar Aq return
-.Pp
-would become
-.Pp
-.Dl ls -F foobar Aq return
-.Pp
-Aliases provide a convenient way for naive users to create shorthands for
-commands without having to learn how to create functions with arguments.
-They can also be used to create lexically obscure code.
-This use is discouraged.
-.Ss Commands
-The shell interprets the words it reads according to a language, the
-specification of which is outside the scope of this man page (refer to the
-BNF in the
-.Tn POSIX
-1003.2 document).
-Essentially though, a line is read and if the first
-word of the line (or after a control operator) is not a reserved word,
-then the shell has recognized a simple command.
-Otherwise, a complex
-command or some other special construct may have been recognized.
-.Ss Simple Commands
-If a simple command has been recognized, the shell performs
-the following actions:
-.Bl -enum -offset indent
-.It
-Leading words of the form
-.Dq name=value
-are stripped off and assigned to the environment of the simple command.
-Redirection operators and their arguments (as described below) are
-stripped off and saved for processing.
-.It
-The remaining words are expanded as described in
-the section called
-.Dq Expansions ,
-and the first remaining word is considered the command name and the
-command is located.
-The remaining words are considered the arguments of the command.
-If no command name resulted, then the
-.Dq name=value
-variable assignments recognized in item 1 affect the current shell.
-.It
-Redirections are performed as described in the next section.
-.El
-.Ss Redirections
-Redirections are used to change where a command reads its input or sends
-its output.
-In general, redirections open, close, or duplicate an
-existing reference to a file.
-The overall format used for redirection is:
-.Pp
-.Dl [n] Va redir-op Ar file
-.Pp
-where
-.Va redir-op
-is one of the redirection operators mentioned previously.
-Following is a list of the possible redirections.
-The
-.Bq n
-is an optional number, as in
-.Sq 3
-(not
-.Sq Bq 3 ) ,
-that refers to a file descriptor.
-.Bl -tag -width aaabsfiles -offset indent
-.It [n] Ns \*[Gt] file
-Redirect standard output (or n) to file.
-.It [n] Ns \*[Gt]| file
-Same, but override the
-.Fl C
-option.
-.It [n] Ns \*[Gt]\*[Gt] file
-Append standard output (or n) to file.
-.It [n] Ns \*[Lt] file
-Redirect standard input (or n) from file.
-.It [n1] Ns \*[Lt]\*[Am] Ns n2
-Duplicate standard input (or n1) from file descriptor n2.
-.It [n] Ns \*[Lt]\*[Am]-
-Close standard input (or n).
-.It [n1] Ns \*[Gt]\*[Am] Ns n2
-Duplicate standard output (or n1) to n2.
-.It [n] Ns \*[Gt]\*[Am]-
-Close standard output (or n).
-.It [n] Ns \*[Lt]\*[Gt] file
-Open file for reading and writing on standard input (or n).
-.El
-.Pp
-The following redirection is often called a
-.Dq here-document .
-.Bl -item -offset indent
-.It
-.Li [n]\*[Lt]\*[Lt] delimiter
-.Dl here-doc-text ...
-.Li delimiter
-.El
-.Pp
-All the text on successive lines up to the delimiter is saved away and
-made available to the command on standard input, or file descriptor n if
-it is specified.
-If the delimiter as specified on the initial line is
-quoted, then the here-doc-text is treated literally, otherwise the text is
-subjected to parameter expansion, command substitution, and arithmetic
-expansion (as described in the section on
-.Dq Expansions ) .
-If the operator is
-.Dq \*[Lt]\*[Lt]-
-instead of
-.Dq \*[Lt]\*[Lt] ,
-then leading tabs in the here-doc-text are stripped.
-.Ss Search and Execution
-There are three types of commands: shell functions, builtin commands, and
-normal programs -- and the command is searched for (by name) in that order.
-They each are executed in a different way.
-.Pp
-When a shell function is executed, all of the shell positional parameters
-(except $0, which remains unchanged) are set to the arguments of the shell
-function.
-The variables which are explicitly placed in the environment of
-the command (by placing assignments to them before the function name) are
-made local to the function and are set to the values given.
-Then the command given in the function definition is executed.
-The positional parameters are restored to their original values
-when the command completes.
-This all occurs within the current shell.
-.Pp
-Shell builtins are executed internally to the shell, without spawning a
-new process.
-.Pp
-Otherwise, if the command name doesn't match a function or builtin, the
-command is searched for as a normal program in the file system (as
-described in the next section).
-When a normal program is executed, the shell runs the program,
-passing the arguments and the environment to the program.
-If the program is not a normal executable file (i.e., if it does
-not begin with the "magic number" whose
-.Tn ASCII
-representation is "#!", so
-.Xr execve 2
-returns
-.Er ENOEXEC
-then) the shell will interpret the program in a subshell.
-The child shell will reinitialize itself in this case,
-so that the effect will be as if a
-new shell had been invoked to handle the ad-hoc shell script, except that
-the location of hashed commands located in the parent shell will be
-remembered by the child.
-.Pp
-Note that previous versions of this document and the source code itself
-misleadingly and sporadically refer to a shell script without a magic
-number as a "shell procedure".
-.Ss Path Search
-When locating a command, the shell first looks to see if it has a shell
-function by that name.
-Then it looks for a builtin command by that name.
-If a builtin command is not found, one of two things happen:
-.Bl -enum
-.It
-Command names containing a slash are simply executed without performing
-any searches.
-.It
-The shell searches each entry in
-.Ev PATH
-in turn for the command.
-The value of the
-.Ev PATH
-variable should be a series of entries separated by colons.
-Each entry consists of a directory name.
-The current directory may be indicated
-implicitly by an empty directory name, or explicitly by a single period.
-.El
-.Ss Command Exit Status
-Each command has an exit status that can influence the behavior
-of other shell commands.
-The paradigm is that a command exits
-with zero for normal or success, and non-zero for failure,
-error, or a false indication.
-The man page for each command
-should indicate the various exit codes and what they mean.
-Additionally, the builtin commands return exit codes, as does
-an executed shell function.
-.Pp
-If a command consists entirely of variable assignments then the
-exit status of the command is that of the last command substitution
-if any, otherwise 0.
-.Ss Complex Commands
-Complex commands are combinations of simple commands with control
-operators or reserved words, together creating a larger complex command.
-More generally, a command is one of the following:
-.Bl -bullet
-.It
-simple command
-.It
-pipeline
-.It
-list or compound-list
-.It
-compound command
-.It
-function definition
-.El
-.Pp
-Unless otherwise stated, the exit status of a command is that of the last
-simple command executed by the command.
-.Ss Pipelines
-A pipeline is a sequence of one or more commands separated
-by the control operator |.
-The standard output of all but
-the last command is connected to the standard input
-of the next command.
-The standard output of the last
-command is inherited from the shell, as usual.
-.Pp
-The format for a pipeline is:
-.Pp
-.Dl [!] command1 [ | command2 ...]
-.Pp
-The standard output of command1 is connected to the standard input of
-command2.
-The standard input, standard output, or both of a command is
-considered to be assigned by the pipeline before any redirection specified
-by redirection operators that are part of the command.
-.Pp
-If the pipeline is not in the background (discussed later), the shell
-waits for all commands to complete.
-.Pp
-If the reserved word ! does not precede the pipeline, the exit status is
-the exit status of the last command specified in the pipeline.
-Otherwise, the exit status is the logical NOT of the exit status of the
-last command.
-That is, if the last command returns zero, the exit status
-is 1; if the last command returns greater than zero, the exit status is
-zero.
-.Pp
-Because pipeline assignment of standard input or standard output or both
-takes place before redirection, it can be modified by redirection.
-For example:
-.Pp
-.Dl $ command1 2\*[Gt]\*[Am]1 | command2
-.Pp
-sends both the standard output and standard error of command1
-to the standard input of command2.
-.Pp
-A ; or
-.Aq newline
-terminator causes the preceding AND-OR-list (described
-next) to be executed sequentially; a \*[Am] causes asynchronous execution of
-the preceding AND-OR-list.
-.Pp
-Note that unlike some other shells, each process in the pipeline is a
-child of the invoking shell (unless it is a shell builtin, in which case
-it executes in the current shell -- but any effect it has on the
-environment is wiped).
-.Ss Background Commands -- \*[Am]
-If a command is terminated by the control operator ampersand (\*[Am]), the
-shell executes the command asynchronously -- that is, the shell does not
-wait for the command to finish before executing the next command.
-.Pp
-The format for running a command in background is:
-.Pp
-.Dl command1 \*[Am] [command2 \*[Am] ...]
-.Pp
-If the shell is not interactive, the standard input of an asynchronous
-command is set to
-.Pa /dev/null .
-.Ss Lists -- Generally Speaking
-A list is a sequence of zero or more commands separated by newlines,
-semicolons, or ampersands, and optionally terminated by one of these three
-characters.
-The commands in a list are executed in the order they are written.
-If command is followed by an ampersand, the shell starts the
-command and immediately proceed onto the next command; otherwise it waits
-for the command to terminate before proceeding to the next one.
-.Ss Short-Circuit List Operators
-.Dq \*[Am]\*[Am]
-and
-.Dq ||
-are AND-OR list operators.
-.Dq \*[Am]\*[Am]
-executes the first command, and then executes the second command if and only
-if the exit status of the first command is zero.
-.Dq ||
-is similar, but executes the second command if and only if the exit status
-of the first command is nonzero.
-.Dq \*[Am]\*[Am]
-and
-.Dq ||
-both have the same priority.
-Note that these operators are left-associative, so
-.Dq true || echo bar && echo baz
-writes
-.Dq baz
-and nothing else.
-This is not the way it works in C.
-.Ss Flow-Control Constructs -- if, while, for, case
-The syntax of the if command is
-.Bd -literal -offset indent
-if list
-then list
-[ elif list
-then    list ] ...
-[ else list ]
-fi
-.Ed
-.Pp
-The syntax of the while command is
-.Bd -literal -offset indent
-while list
-do   list
-done
-.Ed
-.Pp
-The two lists are executed repeatedly while the exit status of the
-first list is zero.
-The until command is similar, but has the word
-until in place of while, which causes it to
-repeat until the exit status of the first list is zero.
-.Pp
-The syntax of the for command is
-.Bd -literal -offset indent
-for variable in word ...
-do   list
-done
-.Ed
-.Pp
-The words are expanded, and then the list is executed repeatedly with the
-variable set to each word in turn.
-do and done may be replaced with
-.Dq {
-and
-.Dq } .
-.Pp
-The syntax of the break and continue command is
-.Bd -literal -offset indent
-break [ num ]
-continue [ num ]
-.Ed
-.Pp
-Break terminates the num innermost for or while loops.
-Continue continues with the next iteration of the innermost loop.
-These are implemented as builtin commands.
-.Pp
-The syntax of the case command is
-.Bd -literal -offset indent
-case word in
-pattern) list ;;
-\&...
-esac
-.Ed
-.Pp
-The pattern can actually be one or more patterns (see
-.Sx Shell Patterns
-described later), separated by
-.Dq \*(Ba
-characters.
-.Ss Grouping Commands Together
-Commands may be grouped by writing either
-.Pp
-.Dl (list)
-.Pp
-or
-.Pp
-.Dl { list; }
-.Pp
-The first of these executes the commands in a subshell.
-Builtin commands grouped into a (list) will not affect the current shell.
-The second form does not fork another shell so is slightly more efficient.
-Grouping commands together this way allows you to redirect
-their output as though they were one program:
-.Pp
-.Bd -literal -offset indent
-{ echo -n \*q hello \*q ; echo \*q world" ; } \*[Gt] greeting
-.Ed
-.Pp
-Note that
-.Dq }
-must follow a control operator (here,
-.Dq \&; )
-so that it is recognized as a reserved word and not as another command argument.
-.Ss Functions
-The syntax of a function definition is
-.Pp
-.Dl name ( ) command
-.Pp
-A function definition is an executable statement; when executed it
-installs a function named name and returns an exit status of zero.
-The command is normally a list enclosed between
-.Dq {
-and
-.Dq } .
-.Pp
-Variables may be declared to be local to a function by using a local
-command.
-This should appear as the first statement of a function, and the syntax is
-.Pp
-.Dl local [ variable | - ] ...
-.Pp
-Local is implemented as a builtin command.
-.Pp
-When a variable is made local, it inherits the initial value and exported
-and readonly flags from the variable with the same name in the surrounding
-scope, if there is one.
-Otherwise, the variable is initially unset.
-The shell uses dynamic scoping, so that if you make the variable x local to
-function f, which then calls function g, references to the variable x made
-inside g will refer to the variable x declared inside f, not to the global
-variable named x.
-.Pp
-The only special parameter that can be made local is
-.Dq - .
-Making
-.Dq -
-local any shell options that are changed via the set command inside the
-function to be restored to their original values when the function
-returns.
-.Pp
-The syntax of the return command is
-.Pp
-.Dl return [ exitstatus ]
-.Pp
-It terminates the currently executing function.
-Return is implemented as a builtin command.
-.Ss Variables and Parameters
-The shell maintains a set of parameters.
-A parameter denoted by a name is called a variable.
-When starting up, the shell turns all the environment
-variables into shell variables.
-New variables can be set using the form
-.Pp
-.Dl name=value
-.Pp
-Variables set by the user must have a name consisting solely of
-alphabetics, numerics, and underscores - the first of which must not be
-numeric.
-A parameter can also be denoted by a number or a special
-character as explained below.
-.Ss Positional Parameters
-A positional parameter is a parameter denoted by a number (n \*[Gt] 0).
-The shell sets these initially to the values of its command line arguments
-that follow the name of the shell script.
-The
-.Ic set
-builtin can also be used to set or reset them.
-.Ss Special Parameters
-A special parameter is a parameter denoted by one of the following special
-characters.
-The value of the parameter is listed next to its character.
-.Bl -tag -width thinhyphena
-.It *
-Expands to the positional parameters, starting from one.
-When the
-expansion occurs within a double-quoted string it expands to a single
-field with the value of each parameter separated by the first character of
-the
-.Ev IFS
-variable, or by a
-.Aq space
-if
-.Ev IFS
-is unset.
-.It @
-Expands to the positional parameters, starting from one.
-When the expansion occurs within double-quotes, each positional
-parameter expands as a separate argument.
-If there are no positional parameters, the
-expansion of @ generates zero arguments, even when @ is
-double-quoted.
-What this basically means, for example, is
-if $1 is
-.Dq abc
-and $2 is
-.Dq def ghi ,
-then
-.Qq $@
-expands to
-the two arguments:
-.Pp
-.Sm off
-.Dl \*q abc \*q \  \*q def\ ghi \*q
-.Sm on
-.It #
-Expands to the number of positional parameters.
-.It \&?
-Expands to the exit status of the most recent pipeline.
-.It - (Hyphen.)
-Expands to the current option flags (the single-letter
-option names concatenated into a string) as specified on
-invocation, by the set builtin command, or implicitly
-by the shell.
-.It $
-Expands to the process ID of the invoked shell.
-A subshell retains the same value of $ as its parent.
-.It \&!
-Expands to the process ID of the most recent background
-command executed from the current shell.
-For a pipeline, the process ID is that of the last command in the pipeline.
-.It 0 (Zero.)
-Expands to the name of the shell or shell script.
-.El
-.Ss Word Expansions
-This clause describes the various expansions that are performed on words.
-Not all expansions are performed on every word, as explained later.
-.Pp
-Tilde expansions, parameter expansions, command substitutions, arithmetic
-expansions, and quote removals that occur within a single word expand to a
-single field.
-It is only field splitting or pathname expansion that can
-create multiple fields from a single word.
-The single exception to this
-rule is the expansion of the special parameter @ within double-quotes, as
-was described above.
-.Pp
-The order of word expansion is:
-.Bl -enum
-.It
-Tilde Expansion, Parameter Expansion, Command Substitution,
-Arithmetic Expansion (these all occur at the same time).
-.It
-Field Splitting is performed on fields
-generated by step (1) unless the
-.Ev IFS
-variable is null.
-.It
-Pathname Expansion (unless set
-.Fl f
-is in effect).
-.It
-Quote Removal.
-.El
-.Pp
-The $ character is used to introduce parameter expansion, command
-substitution, or arithmetic evaluation.
-.Ss Tilde Expansion (substituting a user's home directory)
-A word beginning with an unquoted tilde character (~) is
-subjected to tilde expansion.
-All the characters up to
-a slash (/) or the end of the word are treated as a username
-and are replaced with the user's home directory.
-If the username is missing (as in
-.Pa ~/foobar ) ,
-the tilde is replaced with the value of the
-.Va HOME
-variable (the current user's home directory).
-.Ss Parameter Expansion
-The format for parameter expansion is as follows:
-.Pp
-.Dl ${expression}
-.Pp
-where expression consists of all characters until the matching
-.Dq } .
-Any
-.Dq }
-escaped by a backslash or within a quoted string, and characters in
-embedded arithmetic expansions, command substitutions, and variable
-expansions, are not examined in determining the matching
-.Dq } .
-.Pp
-The simplest form for parameter expansion is:
-.Pp
-.Dl ${parameter}
-.Pp
-The value, if any, of parameter is substituted.
-.Pp
-The parameter name or symbol can be enclosed in braces, which are
-optional except for positional parameters with more than one digit or
-when parameter is followed by a character that could be interpreted as
-part of the name.
-If a parameter expansion occurs inside double-quotes:
-.Bl -enum
-.It
-Pathname expansion is not performed on the results of the expansion.
-.It
-Field splitting is not performed on the results of the
-expansion, with the exception of the special rules for @.
-.El
-.Pp
-In addition, a parameter expansion can be modified by using one of the
-following formats.
-.Bl -tag -width aaparameterwordaaaaa
-.It ${parameter:-word}
-Use Default Values.
-If parameter is unset or null, the expansion of word
-is substituted; otherwise, the value of parameter is substituted.
-.It ${parameter:=word}
-Assign Default Values.
-If parameter is unset or null, the expansion of
-word is assigned to parameter.
-In all cases, the final value of parameter is substituted.
-Only variables, not positional parameters or special
-parameters, can be assigned in this way.
-.It ${parameter:?[word]}
-Indicate Error if Null or Unset.
-If parameter is unset or null, the
-expansion of word (or a message indicating it is unset if word is omitted)
-is written to standard error and the shell exits with a nonzero exit status.
-Otherwise, the value of parameter is substituted.
-An interactive shell need not exit.
-.It ${parameter:+word}
-Use Alternative Value.
-If parameter is unset or null, null is
-substituted; otherwise, the expansion of word is substituted.
-.El
-.Pp
-In the parameter expansions shown previously, use of the colon in the
-format results in a test for a parameter that is unset or null; omission
-of the colon results in a test for a parameter that is only unset.
-.Bl -tag -width aaparameterwordaaaaa
-.It ${#parameter}
-String Length.
-The length in characters of the value of parameter.
-.El
-.Pp
-The following four varieties of parameter expansion provide for substring
-processing.
-In each case, pattern matching notation (see
-.Sx Shell Patterns ) ,
-rather than regular expression notation, is used to evaluate the patterns.
-If parameter is * or @, the result of the expansion is unspecified.
-Enclosing the full parameter expansion string in double-quotes does not
-cause the following four varieties of pattern characters to be quoted,
-whereas quoting characters within the braces has this effect.
-.Bl -tag -width aaparameterwordaaaaa
-.It ${parameter%word}
-Remove Smallest Suffix Pattern.
-The word is expanded to produce a pattern.
-The parameter expansion then results in parameter, with the
-smallest portion of the suffix matched by the pattern deleted.
-.It ${parameter%%word}
-Remove Largest Suffix Pattern.
-The word is expanded to produce a pattern.
-The parameter expansion then results in parameter, with the largest
-portion of the suffix matched by the pattern deleted.
-.It ${parameter#word}
-Remove Smallest Prefix Pattern.
-The word is expanded to produce a pattern.
-The parameter expansion then results in parameter, with the
-smallest portion of the prefix matched by the pattern deleted.
-.It ${parameter##word}
-Remove Largest Prefix Pattern.
-The word is expanded to produce a pattern.
-The parameter expansion then results in parameter, with the largest
-portion of the prefix matched by the pattern deleted.
-.El
-.Ss Command Substitution
-Command substitution allows the output of a command to be substituted in
-place of the command name itself.
-Command substitution occurs when the command is enclosed as follows:
-.Pp
-.Dl $(command)
-.Pp
-or
-.Po
-.Dq backquoted
-version
-.Pc :
-.Pp
-.Dl `command`
-.Pp
-The shell expands the command substitution by executing command in a
-subshell environment and replacing the command substitution with the
-standard output of the command, removing sequences of one or more
-.Ao newline Ac Ns s
-at the end of the substitution.
-(Embedded
-.Ao newline Ac Ns s
-before
-the end of the output are not removed; however, during field splitting,
-they may be translated into
-.Ao space Ac Ns s ,
-depending on the value of
-.Ev IFS
-and quoting that is in effect.)
-.Ss Arithmetic Expansion
-Arithmetic expansion provides a mechanism for evaluating an arithmetic
-expression and substituting its value.
-The format for arithmetic expansion is as follows:
-.Pp
-.Dl $((expression))
-.Pp
-The expression is treated as if it were in double-quotes, except
-that a double-quote inside the expression is not treated specially.
-The shell expands all tokens in the expression for parameter expansion,
-command substitution, and quote removal.
-.Pp
-Next, the shell treats this as an arithmetic expression and
-substitutes the value of the expression.
-.Ss White Space Splitting (Field Splitting)
-After parameter expansion, command substitution, and
-arithmetic expansion the shell scans the results of
-expansions and substitutions that did not occur in double-quotes for
-field splitting and multiple fields can result.
-.Pp
-The shell treats each character of the
-.Ev IFS
-as a delimiter and use the delimiters to split the results of parameter
-expansion and command substitution into fields.
-.Pp
-Non-whitespace characters in
-.Ev IFS
-are treated strictly as parameter terminators.
-So adjacent non-whitespace
-.Ev IFS
-characters will produce empty parameters.
-.Pp
-If
-.Ev IFS
-is unset it is assumed to contain space, tab, and newline.
-.Ss Pathname Expansion (File Name Generation)
-Unless the
-.Fl f
-flag is set, file name generation is performed after word splitting is
-complete.
-Each word is viewed as a series of patterns, separated by slashes.
-The process of expansion replaces the word with the names of all
-existing files whose names can be formed by replacing each pattern with a
-string that matches the specified pattern.
-There are two restrictions on
-this: first, a pattern cannot match a string containing a slash, and
-second, a pattern cannot match a string starting with a period unless the
-first character of the pattern is a period.
-The next section describes the
-patterns used for both Pathname Expansion and the
-.Ic case
-command.
-.Ss Shell Patterns
-A pattern consists of normal characters, which match themselves,
-and meta-characters.
-The meta-characters are
-.Dq \&! ,
-.Dq * ,
-.Dq \&? ,
-and
-.Dq \&[ .
-These characters lose their special meanings if they are quoted.
-When command or variable substitution is performed
-and the dollar sign or back quotes are not double quoted,
-the value of the variable or the output of
-the command is scanned for these characters and they are turned into
-meta-characters.
-.Pp
-An asterisk
-.Pq Dq *
-matches any string of characters.
-A question mark matches any single character.
-A left bracket
-.Pq Dq \&[
-introduces a character class.
-The end of the character class is indicated by a
-.Pq Dq \&] ;
-if the
-.Dq \&]
-is missing then the
-.Dq \&[
-matches a
-.Dq \&[
-rather than introducing a character class.
-A character class matches any of the characters between the square brackets.
-A range of characters may be specified using a minus sign.
-The character class may be complemented
-by making an exclamation point the first character of the character class.
-.Pp
-To include a
-.Dq \&]
-in a character class, make it the first character listed (after the
-.Dq \&! ,
-if any).
-To include a minus sign, make it the first or last character listed.
-.Ss Builtins
-This section lists the builtin commands which are builtin because they
-need to perform some operation that can't be performed by a separate
-process.
-In addition to these, there are several other commands that may
-be builtin for efficiency (e.g.
-.Xr printf 1 ,
-.Xr echo 1 ,
-.Xr test 1 ,
-etc).
-.Bl -tag -width 5n
-.It :
-A null command that returns a 0 (true) exit value.
-.It \&. file
-The commands in the specified file are read and executed by the shell.
-.It alias Op Ar name Ns Op Ar "=string ..."
-If
-.Ar name=string
-is specified, the shell defines the alias
-.Ar name
-with value
-.Ar string .
-If just
-.Ar name
-is specified, the value of the alias
-.Ar name
-is printed.
-With no arguments, the
-.Ic alias
-builtin prints the
-names and values of all defined aliases (see
-.Ic unalias ) .
-.It bg [ Ar job ] ...
-Continue the specified jobs (or the current job if no
-jobs are given) in the background.
-.It Xo command
-.Op Fl p
-.Op Fl v
-.Op Fl V
-.Ar command
-.Op Ar arg ...
-.Xc
-Execute the specified command but ignore shell functions when searching
-for it.
-(This is useful when you
-have a shell function with the same name as a builtin command.)
-.Bl -tag -width 5n
-.It Fl p
-search for command using a
-.Ev PATH
-that guarantees to find all the standard utilities.
-.It Fl V
-Do not execute the command but
-search for the command and print the resolution of the
-command search.
-This is the same as the type builtin.
-.It Fl v
-Do not execute the command but
-search for the command and print the absolute pathname
-of utilities, the name for builtins or the expansion of aliases.
-.El
-.It cd Op Ar directory Op Ar replace
-Switch to the specified directory (default
-.Ev $HOME ) .
-If
-.Ar replace
-is specified, then the new directory name is generated by replacing
-the first occurrence of
-.Ar directory
-in the current directory name with
-.Ar replace .
-Otherwise if an entry for
-.Ev CDPATH
-appears in the environment of the
-.Ic cd
-command or the shell variable
-.Ev CDPATH
-is set and the directory name does not begin with a slash, then the
-directories listed in
-.Ev CDPATH
-will be searched for the specified directory.
-The format of
-.Ev CDPATH
-is the same as that of
-.Ev PATH .
-In an interactive shell, the
-.Ic cd
-command will print out the name of the
-directory that it actually switched to if this is different from the name
-that the user gave.
-These may be different either because the
-.Ev CDPATH
-mechanism was used or because a symbolic link was crossed.
-.It eval Ar string ...
-Concatenate all the arguments with spaces.
-Then re-parse and execute the command.
-.It exec Op Ar command arg ...
-Unless command is omitted, the shell process is replaced with the
-specified program (which must be a real program, not a shell builtin or
-function).
-Any redirections on the
-.Ic exec
-command are marked as permanent, so that they are not undone when the
-.Ic exec
-command finishes.
-.It exit Op Ar exitstatus
-Terminate the shell process.
-If
-.Ar exitstatus
-is given it is used as the exit status of the shell; otherwise the
-exit status of the preceding command is used.
-.It export Ar name ...
-.It export Fl p
-The specified names are exported so that they will appear in the
-environment of subsequent commands.
-The only way to un-export a variable is to unset it.
-The shell allows the value of a variable to be set at the
-same time it is exported by writing
-.Pp
-.Dl export name=value
-.Pp
-With no arguments the export command lists the names of all exported variables.
-With the
-.Fl p
-option specified the output will be formatted suitably for non-interactive use.
-.It Xo fc Op Fl e Ar editor
-.Op Ar first Op Ar last
-.Xc
-.It Xo fc Fl l
-.Op Fl nr
-.Op Ar first Op Ar last
-.Xc
-.It Xo fc Fl s Op Ar old=new
-.Op Ar first
-.Xc
-The
-.Ic fc
-builtin lists, or edits and re-executes, commands previously entered
-to an interactive shell.
-.Bl -tag -width 5n
-.It Fl e No editor
-Use the editor named by editor to edit the commands.
-The editor string is a command name, subject to search via the
-.Ev PATH
-variable.
-The value in the
-.Ev FCEDIT
-variable is used as a default when
-.Fl e
-is not specified.
-If
-.Ev FCEDIT
-is null or unset, the value of the
-.Ev EDITOR
-variable is used.
-If
-.Ev EDITOR
-is null or unset,
-.Xr ed 1
-is used as the editor.
-.It Fl l No (ell)
-List the commands rather than invoking an editor on them.
-The commands are written in the sequence indicated by
-the first and last operands, as affected by
-.Fl r ,
-with each command preceded by the command number.
-.It Fl n
-Suppress command numbers when listing with -l.
-.It Fl r
-Reverse the order of the commands listed (with
-.Fl l )
-or edited (with neither
-.Fl l
-nor
-.Fl s ) .
-.It Fl s
-Re-execute the command without invoking an editor.
-.It first
-.It last
-Select the commands to list or edit.
-The number of previous commands that
-can be accessed are determined by the value of the
-.Ev HISTSIZE
-variable.
-The value of first or last or both are one of the following:
-.Bl -tag -width 5n
-.It [+]number
-A positive number representing a command number; command numbers can be
-displayed with the
-.Fl l
-option.
-.It Fl number
-A negative decimal number representing the command that was executed
-number of commands previously.
-For example, \-1 is the immediately previous command.
-.El
-.It string
-A string indicating the most recently entered command that begins with
-that string.
-If the old=new operand is not also specified with
-.Fl s ,
-the string form of the first operand cannot contain an embedded equal sign.
-.El
-.Pp
-The following environment variables affect the execution of fc:
-.Bl -tag -width HISTSIZE
-.It Ev FCEDIT
-Name of the editor to use.
-.It Ev HISTSIZE
-The number of previous commands that are accessible.
-.El
-.It fg Op Ar job
-Move the specified job or the current job to the foreground.
-.It getopts Ar optstring var
-The
-.Tn POSIX
-.Ic getopts
-command, not to be confused with the
-.Em Bell Labs
--derived
-.Xr getopt 1 .
-.Pp
-The first argument should be a series of letters, each of which may be
-optionally followed by a colon to indicate that the option requires an
-argument.
-The variable specified is set to the parsed option.
-.Pp
-The
-.Ic getopts
-command deprecates the older
-.Xr getopt 1
-utility due to its handling of arguments containing whitespace.
-.Pp
-The
-.Ic getopts
-builtin may be used to obtain options and their arguments
-from a list of parameters.
-When invoked,
-.Ic getopts
-places the value of the next option from the option string in the list in
-the shell variable specified by
-.Va var
-and its index in the shell variable
-.Ev OPTIND .
-When the shell is invoked,
-.Ev OPTIND
-is initialized to 1.
-For each option that requires an argument, the
-.Ic getopts
-builtin will place it in the shell variable
-.Ev OPTARG .
-If an option is not allowed for in the
-.Va optstring ,
-then
-.Ev OPTARG
-will be unset.
-.Pp
-.Va optstring
-is a string of recognized option letters (see
-.Xr getopt 3 ) .
-If a letter is followed by a colon, the option is expected to have an
-argument which may or may not be separated from it by whitespace.
-If an option character is not found where expected,
-.Ic getopts
-will set the variable
-.Va var
-to a
-.Dq \&? ;
-.Ic getopts
-will then unset
-.Ev OPTARG
-and write output to standard error.
-By specifying a colon as the first character of
-.Va optstring
-all errors will be ignored.
-.Pp
-A nonzero value is returned when the last option is reached.
-If there are no remaining arguments,
-.Ic getopts
-will set
-.Va var
-to the special option,
-.Dq -- ,
-otherwise, it will set
-.Va var
-to
-.Dq \&? .
-.Pp
-The following code fragment shows how one might process the arguments
-for a command that can take the options
-.Op a
-and
-.Op b ,
-and the option
-.Op c ,
-which requires an argument.
-.Pp
-.Bd -literal -offset indent
-while getopts abc: f
-do
-	case $f in
-	a | b)	flag=$f;;
-	c)	carg=$OPTARG;;
-	\\?)	echo $USAGE; exit 1;;
-	esac
-done
-shift `expr $OPTIND - 1`
-.Ed
-.Pp
-This code will accept any of the following as equivalent:
-.Pp
-.Bd -literal -offset indent
-cmd \-acarg file file
-cmd \-a \-c arg file file
-cmd \-carg -a file file
-cmd \-a \-carg \-\- file file
-.Ed
-.It hash Fl rv Ar command ...
-The shell maintains a hash table which remembers the
-locations of commands.
-With no arguments whatsoever,
-the
-.Ic hash
-command prints out the contents of this table.
-Entries which have not been looked at since the last
-.Ic cd
-command are marked with an asterisk; it is possible for these entries
-to be invalid.
-.Pp
-With arguments, the
-.Ic hash
-command removes the specified commands from the hash table (unless
-they are functions) and then locates them.
-With the
-.Fl v
-option, hash prints the locations of the commands as it finds them.
-The
-.Fl r
-option causes the hash command to delete all the entries in the hash table
-except for functions.
-.It inputrc Ar file
-Read the
-.Va file
-to set keybindings as defined by
-.Xr editrc 5 .
-.It jobid Op Ar job
-Print the process id's of the processes in the job.
-If the
-.Ar job
-argument is omitted, the current job is used.
-.It jobs
-This command lists out all the background processes
-which are children of the current shell process.
-.It pwd Op Fl LP
-Print the current directory.
-If 
-.Fl L
-is specified the cached value (initially set from
-.Ev PWD )
-is checked to see if it refers to the current directory, if it does
-the value is printed.
-Otherwise the current directory name is found using
-.Xr getcwd(3) .
-The environment variable
-.Ev PWD
-is set to printed value.
-.Pp
-The default is
-.Ic pwd
-.Fl L ,
-but note that the builtin
-.Ic cd
-command doesn't currently support
-.Fl L
-or
-.Fl P
-and will cache (almost) the absolute path.
-If
-.Ic cd
-is changed,
-.Ic pwd
-may be changed to default to
-.Ic pwd
-.Fl P .
-.Pp
-If the current directory is renamed and replaced by a symlink to the
-same directory, or the initial
-.Ev PWD
-value followed a symbolic link, then the cached value may not
-be the absolute path.
-.Pp
-The builtin command may differ from the program of the same name because
-the program will use
-.Ev PWD
-and the builtin uses a separately cached value.
-.It Xo read Op Fl p Ar prompt
-.Op Fl r
-.Ar variable
-.Op Ar ...
-.Xc
-The prompt is printed if the
-.Fl p
-option is specified and the standard input is a terminal.
-Then a line is read from the standard input.
-The trailing newline is deleted from the
-line and the line is split as described in the section on word splitting
-above, and the pieces are assigned to the variables in order.
-If there are more pieces than variables, the remaining pieces
-(along with the characters in
-.Ev IFS
-that separated them) are assigned to the last variable.
-If there are more variables than pieces,
-the remaining variables are assigned the null string.
-The
-.Ic read
-builtin will indicate success unless EOF is encountered on input, in
-which case failure is returned.
-.Pp
-By default, unless the
-.Fl r
-option is specified, the backslash
-.Dq \e
-acts as an escape character, causing the following character to be treated
-literally.
-If a backslash is followed by a newline, the backslash and the
-newline will be deleted.
-.It readonly Ar name ...
-.It readonly Fl p
-The specified names are marked as read only, so that they cannot be
-subsequently modified or unset.
-The shell allows the value of a variable
-to be set at the same time it is marked read only by writing
-.Pp
-.Dl readonly name=value
-.Pp
-With no arguments the readonly command lists the names of all read only
-variables.
-With the
-.Fl p
-option specified the output will be formatted suitably for non-interactive use.
-.Pp
-.It Xo set
-.Oo {
-.Fl options | Cm +options | Cm -- }
-.Oc Ar arg ...
-.Xc
-The
-.Ic set
-command performs three different functions.
-.Pp
-With no arguments, it lists the values of all shell variables.
-.Pp
-If options are given, it sets the specified option
-flags, or clears them as described in the section called
-.Sx Argument List Processing .
-.Pp
-The third use of the set command is to set the values of the shell's
-positional parameters to the specified args.
-To change the positional
-parameters without changing any options, use
-.Dq --
-as the first argument to set.
-If no args are present, the set command
-will clear all the positional parameters (equivalent to executing
-.Dq shift $# . )
-.It setvar Ar variable Ar value
-Assigns value to variable.
-(In general it is better to write
-variable=value rather than using
-.Ic setvar .
-.Ic setvar
-is intended to be used in
-functions that assign values to variables whose names are passed as
-parameters.)
-.It shift Op Ar n
-Shift the positional parameters n times.
-A
-.Ic shift
-sets the value of
-.Va $1
-to the value of
-.Va $2 ,
-the value of
-.Va $2
-to the value of
-.Va $3 ,
-and so on, decreasing
-the value of
-.Va $#
-by one.
-If there are zero positional parameters,
-.Ic shift
-does nothing.
-.It Xo trap
-.Op Fl l
-.Xc
-.It Xo trap
-.Op Ar action
-.Ar signal ...
-.Xc
-Cause the shell to parse and execute action when any of the specified
-signals are received.
-The signals are specified by signal number or as the name of the signal.
-If
-.Ar signal
-is
-.Li 0 ,
-the action is executed when the shell exits.
-.Ar action
-may be null, which cause the specified signals to be ignored.
-With
-.Ar action
-omitted or set to `-' the specified signals are set to their default action.
-When the shell forks off a subshell, it resets trapped (but not ignored)
-signals to the default action.
-The
-.Ic trap
-command has no effect on signals that were
-ignored on entry to the shell.
-Issuing
-.Ic trap
-with option
-.Ar -l
-will print a list of valid signal names.
-.Ic trap
-without any arguments cause it to write a list of signals and their
-associated action to the standard output in a format that is suitable
-as an input to the shell that achieves the same trapping results.
-.Pp
-Examples:
-.Pp
-.Dl trap
-.Pp
-List trapped signals and their corresponding action
-.Pp
-.Dl trap -l
-.Pp
-Print a list of valid signals
-.Pp
-.Dl trap '' INT QUIT tstp 30
-.Pp
-Ignore signals INT QUIT TSTP USR1
-.Pp
-.Dl trap date INT
-.Pp
-Print date upon receiving signal INT
-.It type Op Ar name ...
-Interpret each name as a command and print the resolution of the command
-search.
-Possible resolutions are:
-shell keyword, alias, shell builtin,
-command, tracked alias and not found.
-For aliases the alias expansion is
-printed; for commands and tracked aliases the complete pathname of the
-command is printed.
-.It ulimit Xo
-.Op Fl H \*(Ba Fl S
-.Op Fl a \*(Ba Fl tfdscmlpn Op Ar value
-.Xc
-Inquire about or set the hard or soft limits on processes or set new
-limits.
-The choice between hard limit (which no process is allowed to
-violate, and which may not be raised once it has been lowered) and soft
-limit (which causes processes to be signaled but not necessarily killed,
-and which may be raised) is made with these flags:
-.Bl -tag -width Fl
-.It Fl H
-set or inquire about hard limits
-.It Fl S
-set or inquire about soft limits.
-If neither
-.Fl H
-nor
-.Fl S
-is specified, the soft limit is displayed or both limits are set.
-If both are specified, the last one wins.
-.El
-.Pp
-.Bl -tag -width Fl
-The limit to be interrogated or set, then, is chosen by specifying
-any one of these flags:
-.It Fl a
-show all the current limits
-.It Fl b
-show or set the limit on the socket buffer size of a process (in bytes)
-.It Fl t
-show or set the limit on CPU time (in seconds)
-.It Fl f
-show or set the limit on the largest file that can be created
-(in 512-byte blocks)
-.It Fl d
-show or set the limit on the data segment size of a process (in kilobytes)
-.It Fl s
-show or set the limit on the stack size of a process (in kilobytes)
-.It Fl c
-show or set the limit on the largest core dump size that can be produced
-(in 512-byte blocks)
-.It Fl m
-show or set the limit on the total physical memory that can be
-in use by a process (in kilobytes)
-.It Fl l
-show or set the limit on how much memory a process can lock with
-.Xr mlock 2
-(in kilobytes)
-.It Fl p
-show or set the limit on the number of processes this user can
-have at one time
-.It Fl n
-show or set the limit on the number of files a process can have open at once
-.El
-.Pp
-If none of these is specified, it is the limit on file size that is shown
-or set.
-If value is specified, the limit is set to that number; otherwise
-the current limit is displayed.
-.Pp
-Limits of an arbitrary process can be displayed or set using the
-.Xr sysctl 8
-utility.
-.Pp
-.It umask Op Ar mask
-Set the value of umask (see
-.Xr umask 2 )
-to the specified octal value.
-If the argument is omitted, the umask value is printed.
-.It unalias Xo
-.Op Fl a
-.Op Ar name
-.Xc
-If
-.Ar name
-is specified, the shell removes that alias.
-If
-.Fl a
-is specified, all aliases are removed.
-.It unset Ar name ...
-The specified variables and functions are unset and unexported.
-If a given name corresponds to both a variable and a function, both
-the variable and the function are unset.
-.It wait Op Ar job
-Wait for the specified job to complete and return the exit status of the
-last process in the job.
-If the argument is omitted, wait for all jobs to
-complete and then return an exit status of zero.
-.El
-.Ss Command Line Editing
-When
-.Nm
-is being used interactively from a terminal, the current command
-and the command history (see
-.Ic fc
-in
-.Sx Builtins )
-can be edited using emacs-mode or vi-mode command-line editing.
-The command
-.Ql set -o emacs
-enables emacs-mode editing.
-The command
-.Ql set -o vi
-enables vi-mode editing and places sh into vi insert mode.
-(See the
-.Sx Argument List Processing
-section above.)
-.Pp
-The vi mode uses commands similar to a subset of those described in the
-.Xr vi 1
-man page.
-With vi-mode
-enabled, sh can be switched between insert mode and command mode.
-It's similar to vi: typing
-.Aq ESC
-will throw you into command VI command mode.
-Hitting
-.Aq return
-while in command mode will pass the line to the shell.
-.Pp
-The emacs mode uses commands similar to a subset available in
-the emacs editor.
-With emacs-mode enabled, special keys can be used to modify the text
-in the buffer using the control key.
-.Pp
-.Nm
-uses the
-.Xr editline 3
-library.
-.Sh EXIT STATUS
-Errors that are detected by the shell, such as a syntax error, will cause the
-shell to exit with a non-zero exit status.
-If the shell is not an
-interactive shell, the execution of the shell file will be aborted.
-Otherwise
-the shell will return the exit status of the last command executed, or
-if the exit builtin is used with a numeric argument, it will return the
-argument.
-.Sh ENVIRONMENT
-.Bl -tag -width MAILCHECK
-.It Ev HOME
-Set automatically by
-.Xr login 1
-from the user's login directory in the password file
-.Pq Xr passwd 5 .
-This environment variable also functions as the default argument for the
-cd builtin.
-.It Ev PATH
-The default search path for executables.
-See the above section
-.Sx Path Search .
-.It Ev CDPATH
-The search path used with the cd builtin.
-.It Ev LANG
-The string used to specify localization information that allows users
-to work with different culture-specific and language conventions.
-See
-.Xr nls 7 .
-.It Ev MAIL
-The name of a mail file, that will be checked for the arrival of new mail.
-Overridden by
-.Ev MAILPATH .
-.It Ev MAILCHECK
-The frequency in seconds that the shell checks for the arrival of mail
-in the files specified by the
-.Ev MAILPATH
-or the
-.Ev MAIL
-file.
-If set to 0, the check will occur at each prompt.
-.It Ev MAILPATH
-A colon
-.Dq \&:
-separated list of file names, for the shell to check for incoming mail.
-This environment setting overrides the
-.Ev MAIL
-setting.
-There is a maximum of 10 mailboxes that can be monitored at once.
-.It Ev PS1
-The primary prompt string, which defaults to
-.Dq $ \  ,
-unless you are the superuser, in which case it defaults to
-.Dq # \  .
-.It Ev PS2
-The secondary prompt string, which defaults to
-.Dq \*[Gt] \  .
-.It Ev PS4
-Output before each line when execution trace (set -x) is enabled,
-defaults to
-.Dq + \  .
-.It Ev IFS
-Input Field Separators.
-This is normally set to
-.Aq space ,
-.Aq tab ,
-and
-.Aq newline .
-See the
-.Sx White Space Splitting
-section for more details.
-.It Ev TERM
-The default terminal setting for the shell.
-This is inherited by
-children of the shell, and is used in the history editing modes.
-.It Ev HISTSIZE
-The number of lines in the history buffer for the shell.
-.El
-.Sh FILES
-.Bl -item -width HOMEprofilexxxx
-.It
-.Pa $HOME/.profile
-.It
-.Pa /etc/profile
-.El
-.Sh SEE ALSO
-.Xr csh 1 ,
-.Xr echo 1 ,
-.Xr getopt 1 ,
-.Xr ksh 1 ,
-.Xr login 1 ,
-.Xr printf 1 ,
-.Xr test 1 ,
-.Xr editline 3 ,
-.Xr getopt 3 ,
-.\" .Xr profile 4 ,
-.Xr editrc 5 ,
-.Xr passwd 5 ,
-.Xr environ 7 ,
-.Xr nls 7 ,
-.Xr sysctl 8
-.Sh HISTORY
-A
-.Nm
-command appeared in
-.At v1 .
-It was, however, unmaintainable so we wrote this one.
-.Sh BUGS
-Setuid shell scripts should be avoided at all costs, as they are a
-significant security risk.
-.Pp
-PS1, PS2, and PS4 should be subject to parameter expansion before
-being displayed.
-.Pp
-The characters generated by filename completion should probably be quoted
-to ensure that the filename is still valid after the input line has been
-processed.
diff --git a/src/ash/shell.h b/src/ash/shell.h
deleted file mode 100644
index fd8bcc9..0000000
--- a/src/ash/shell.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*	$NetBSD: shell.h,v 1.17 2003/08/07 09:05:38 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)shell.h	8.2 (Berkeley) 5/4/95
- */
-
-/*
- * The follow should be set to reflect the type of system you have:
- *	JOBS -> 1 if you have Berkeley job control, 0 otherwise.
- *	SHORTNAMES -> 1 if your linker cannot handle long names.
- *	define BSD if you are running 4.2 BSD or later.
- *	define SYSV if you are running under System V.
- *	define DEBUG=1 to compile in debugging ('set -o debug' to turn on)
- *	define DEBUG=2 to compile in and turn on debugging.
- *	define DO_SHAREDVFORK to indicate that vfork(2) shares its address
- *	       with its parent.
- *
- * When debugging is on, debugging info will be written to ./trace and
- * a quit signal will generate a core dump.
- */
-
-#include <sys/param.h>
-
-#define JOBS 1
-#ifndef BSD
-#define BSD 1
-#endif
-
-#ifndef DO_SHAREDVFORK
-#if __NetBSD_Version__ >= 104000000
-#define DO_SHAREDVFORK
-#endif
-#endif
-
-typedef void *pointer;
-#ifndef NULL
-#define NULL (void *)0
-#endif
-#define STATIC	/* empty */
-#define MKINIT	/* empty */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-
-extern char nullstr[1];		/* null string */
-
-
-#ifdef DEBUG
-#define TRACE(param)	trace param
-#define TRACEV(param)	tracev param
-#else
-#define TRACE(param)
-#define TRACEV(param)
-#endif
diff --git a/src/ash/show.c b/src/ash/show.c
deleted file mode 100644
index 2769c69..0000000
--- a/src/ash/show.c
+++ /dev/null
@@ -1,456 +0,0 @@
-/*	$NetBSD: show.c,v 1.26 2003/11/14 10:46:13 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)show.c	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: show.c,v 1.26 2003/11/14 10:46:13 dsl Exp $");
-#endif
-#endif /* not lint */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <sys/fcntl.h>
-#include <unistd.h>
-
-#include "shell.h"
-#include "parser.h"
-#include "nodes.h"
-#include "mystring.h"
-#include "show.h"
-#include "options.h"
-
-
-#ifdef DEBUG
-static void shtree(union node *, int, char *, FILE*);
-static void shcmd(union node *, FILE *);
-static void sharg(union node *, FILE *);
-static void indent(int, char *, FILE *);
-static void trstring(char *);
-
-
-void
-showtree(union node *n)
-{
-	trputs("showtree called\n");
-	shtree(n, 1, NULL, stdout);
-}
-
-
-static void
-shtree(union node *n, int ind, char *pfx, FILE *fp)
-{
-	struct nodelist *lp;
-	const char *s;
-
-	if (n == NULL)
-		return;
-
-	indent(ind, pfx, fp);
-	switch(n->type) {
-	case NSEMI:
-		s = "; ";
-		goto binop;
-	case NAND:
-		s = " && ";
-		goto binop;
-	case NOR:
-		s = " || ";
-binop:
-		shtree(n->nbinary.ch1, ind, NULL, fp);
-	   /*    if (ind < 0) */
-			fputs(s, fp);
-		shtree(n->nbinary.ch2, ind, NULL, fp);
-		break;
-	case NCMD:
-		shcmd(n, fp);
-		if (ind >= 0)
-			putc('\n', fp);
-		break;
-	case NPIPE:
-		for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
-			shcmd(lp->n, fp);
-			if (lp->next)
-				fputs(" | ", fp);
-		}
-		if (n->npipe.backgnd)
-			fputs(" &", fp);
-		if (ind >= 0)
-			putc('\n', fp);
-		break;
-	default:
-		fprintf(fp, "<node type %d>", n->type);
-		if (ind >= 0)
-			putc('\n', fp);
-		break;
-	}
-}
-
-
-
-static void
-shcmd(union node *cmd, FILE *fp)
-{
-	union node *np;
-	int first;
-	const char *s;
-	int dftfd;
-
-	first = 1;
-	for (np = cmd->ncmd.args ; np ; np = np->narg.next) {
-		if (! first)
-			putchar(' ');
-		sharg(np, fp);
-		first = 0;
-	}
-	for (np = cmd->ncmd.redirect ; np ; np = np->nfile.next) {
-		if (! first)
-			putchar(' ');
-		switch (np->nfile.type) {
-			case NTO:	s = ">";  dftfd = 1; break;
-			case NCLOBBER:	s = ">|"; dftfd = 1; break;
-			case NAPPEND:	s = ">>"; dftfd = 1; break;
-			case NTOFD:	s = ">&"; dftfd = 1; break;
-			case NFROM:	s = "<";  dftfd = 0; break;
-			case NFROMFD:	s = "<&"; dftfd = 0; break;
-			case NFROMTO:	s = "<>"; dftfd = 0; break;
-			default:  	s = "*error*"; dftfd = 0; break;
-		}
-		if (np->nfile.fd != dftfd)
-			fprintf(fp, "%d", np->nfile.fd);
-		fputs(s, fp);
-		if (np->nfile.type == NTOFD || np->nfile.type == NFROMFD) {
-			fprintf(fp, "%d", np->ndup.dupfd);
-		} else {
-			sharg(np->nfile.fname, fp);
-		}
-		first = 0;
-	}
-}
-
-
-
-static void
-sharg(union node *arg, FILE *fp)
-{
-	char *p;
-	struct nodelist *bqlist;
-	int subtype;
-
-	if (arg->type != NARG) {
-		printf("<node type %d>\n", arg->type);
-		abort();
-	}
-	bqlist = arg->narg.backquote;
-	for (p = arg->narg.text ; *p ; p++) {
-		switch (*p) {
-		case CTLESC:
-			putc(*++p, fp);
-			break;
-		case CTLVAR:
-			putc('$', fp);
-			putc('{', fp);
-			subtype = *++p;
-			if (subtype == VSLENGTH)
-				putc('#', fp);
-
-			while (*p != '=')
-				putc(*p++, fp);
-
-			if (subtype & VSNUL)
-				putc(':', fp);
-
-			switch (subtype & VSTYPE) {
-			case VSNORMAL:
-				putc('}', fp);
-				break;
-			case VSMINUS:
-				putc('-', fp);
-				break;
-			case VSPLUS:
-				putc('+', fp);
-				break;
-			case VSQUESTION:
-				putc('?', fp);
-				break;
-			case VSASSIGN:
-				putc('=', fp);
-				break;
-			case VSTRIMLEFT:
-				putc('#', fp);
-				break;
-			case VSTRIMLEFTMAX:
-				putc('#', fp);
-				putc('#', fp);
-				break;
-			case VSTRIMRIGHT:
-				putc('%', fp);
-				break;
-			case VSTRIMRIGHTMAX:
-				putc('%', fp);
-				putc('%', fp);
-				break;
-			case VSLENGTH:
-				break;
-			default:
-				printf("<subtype %d>", subtype);
-			}
-			break;
-		case CTLENDVAR:
-		     putc('}', fp);
-		     break;
-		case CTLBACKQ:
-		case CTLBACKQ|CTLQUOTE:
-			putc('$', fp);
-			putc('(', fp);
-			shtree(bqlist->n, -1, NULL, fp);
-			putc(')', fp);
-			break;
-		default:
-			putc(*p, fp);
-			break;
-		}
-	}
-}
-
-
-static void
-indent(int amount, char *pfx, FILE *fp)
-{
-	int i;
-
-	for (i = 0 ; i < amount ; i++) {
-		if (pfx && i == amount - 1)
-			fputs(pfx, fp);
-		putc('\t', fp);
-	}
-}
-#endif
-
-
-
-/*
- * Debugging stuff.
- */
-
-
-FILE *tracefile;
-
-
-#ifdef DEBUG
-void
-trputc(int c)
-{
-	if (debug != 1)
-		return;
-	putc(c, tracefile);
-}
-#endif
-
-void
-trace(const char *fmt, ...)
-{
-#ifdef DEBUG
-	va_list va;
-
-	if (debug != 1)
-		return;
-        fprintf(tracefile, "[%d] ", getpid());
-	va_start(va, fmt);
-	(void) vfprintf(tracefile, fmt, va);
-	va_end(va);
-#endif
-}
-
-void
-tracev(const char *fmt, va_list va)
-{
-#ifdef DEBUG
-	if (debug != 1)
-		return;
-        fprintf(tracefile, "[%d] ", getpid());
-	(void) vfprintf(tracefile, fmt, va);
-#endif
-}
-
-
-#ifdef DEBUG
-void
-trputs(const char *s)
-{
-	if (debug != 1)
-		return;
-	fputs(s, tracefile);
-}
-
-
-static void
-trstring(char *s)
-{
-	char *p;
-	char c;
-
-	if (debug != 1)
-		return;
-	putc('"', tracefile);
-	for (p = s ; *p ; p++) {
-		switch (*p) {
-		case '\n':  c = 'n';  goto backslash;
-		case '\t':  c = 't';  goto backslash;
-		case '\r':  c = 'r';  goto backslash;
-		case '"':  c = '"';  goto backslash;
-		case '\\':  c = '\\';  goto backslash;
-		case CTLESC:  c = 'e';  goto backslash;
-		case CTLVAR:  c = 'v';  goto backslash;
-		case CTLVAR+CTLQUOTE:  c = 'V';  goto backslash;
-		case CTLBACKQ:  c = 'q';  goto backslash;
-		case CTLBACKQ+CTLQUOTE:  c = 'Q';  goto backslash;
-backslash:	  putc('\\', tracefile);
-			putc(c, tracefile);
-			break;
-		default:
-			if (*p >= ' ' && *p <= '~')
-				putc(*p, tracefile);
-			else {
-				putc('\\', tracefile);
-				putc(*p >> 6 & 03, tracefile);
-				putc(*p >> 3 & 07, tracefile);
-				putc(*p & 07, tracefile);
-			}
-			break;
-		}
-	}
-	putc('"', tracefile);
-}
-#endif
-
-
-void
-trargs(char **ap)
-{
-#ifdef DEBUG
-	if (debug != 1)
-		return;
-	while (*ap) {
-		trstring(*ap++);
-		if (*ap)
-			putc(' ', tracefile);
-		else
-			putc('\n', tracefile);
-	}
-#endif
-}
-
-
-#ifdef DEBUG
-void
-opentrace(void)
-{
-	char s[100];
-#ifdef O_APPEND
-	int flags;
-#endif
-#if 1
-	int fd;
-#endif
-
-	if (debug != 1) {
-		if (tracefile)
-			fflush(tracefile);
-		/* leave open because libedit might be using it */
-		return;
-	}
-#ifdef not_this_way
-	{
-		char *p;
-		if ((p = getenv("HOME")) == NULL) {
-			if (geteuid() == 0)
-				p = "/";
-			else
-				p = "/tmp";
-		}
-		scopy(p, s);
-		strcat(s, "/trace");
-	}
-#else
-	scopy("./trace", s);
-#endif /* not_this_way */
-	if (tracefile) {
-		if (!freopen(s, "a", tracefile)) {
-			fprintf(stderr, "Can't re-open %s\n", s);
-			debug = 0;
-			return;
-		}
-		trace("opentrace: fno=%d - freopen\n", fileno(tracefile));
-	} else {
-#if 0
-		if ((tracefile = fopen(s, "a")) == NULL) {
-#else
-		fd = open(s, O_APPEND | O_RDWR | O_CREAT, 0600);
-		if (fd != -1) {
-			int fd2 = fcntl(fd, F_DUPFD, 199);
-			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 99);
-			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 49);
-			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 18);
-			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 10);
-			if (fd2 != -1) {
-				close(fd);
-				fd = fd2;
-			}
-		}
-		if (fd == -1 || (tracefile = fdopen(fd, "a")) == NULL) {
-#endif
-			fprintf(stderr, "Can't open %s\n", s);
-			debug = 0;
-			return;
-		}
-		trace("opentrace: fno=%d\n", fileno(tracefile));
-	}
-#ifdef O_APPEND
-	if ((flags = fcntl(fileno(tracefile), F_GETFL, 0)) >= 0)
-		fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND);
-#endif
-	setlinebuf(tracefile);
-	fputs("\nTracing started.\n", tracefile);
-}
-#endif /* DEBUG */
diff --git a/src/ash/show.h b/src/ash/show.h
deleted file mode 100644
index 3152ff2..0000000
--- a/src/ash/show.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*	$NetBSD: show.h,v 1.7 2003/08/07 09:05:38 agc Exp $	*/
-
-/*-
- * Copyright (c) 1995
- *      The Regents of the University of California.  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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)show.h	1.1 (Berkeley) 5/4/95
- */
-
-#include <stdarg.h>
-
-union node;
-void showtree(union node *);
-void trace(const char *, ...);
-void tracev(const char *, va_list);
-void trargs(char **);
-#ifdef DEBUG
-void trputc(int);
-void trputs(const char *);
-void opentrace(void);
-#endif
diff --git a/src/ash/strlcpy.c b/src/ash/strlcpy.c
deleted file mode 100644
index 98211d2..0000000
--- a/src/ash/strlcpy.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*	$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $	*/
-
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com>
- * 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. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $");
-#include <sys/cdefs.h>
-//__FBSDID("$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.7 2003/05/01 19:03:14 nectar Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <string.h>
-
-/*
- * Copy src to string dst of size siz.  At most siz-1 characters
- * will be copied.  Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
- */
-size_t strlcpy(dst, src, siz)
-	char *dst;
-	const char *src;
-	size_t siz;
-{
-	char *d = dst;
-	const char *s = src;
-	size_t n = siz;
-
-	/* Copy as many bytes as will fit */
-	if (n != 0 && --n != 0) {
-		do {
-			if ((*d++ = *s++) == 0)
-				break;
-		} while (--n != 0);
-	}
-
-	/* Not enough room in dst, add NUL and traverse rest of src */
-	if (n == 0) {
-		if (siz != 0)
-			*d = '\0';		/* NUL-terminate dst */
-		while (*s++)
-			;
-	}
-
-	return(s - src - 1);	/* count does not include NUL */
-}
diff --git a/src/ash/syntax.c b/src/ash/syntax.c
deleted file mode 100644
index fbf5753..0000000
--- a/src/ash/syntax.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*	$NetBSD: syntax.c,v 1.1 2004/01/17 17:38:12 dsl Exp $	*/
-
-#ifdef __sun__
-#include <stdio.h>
-#include <iso/limits_iso.h>
-#endif
-
-#include "shell.h"
-#include "syntax.h"
-#include "parser.h"
-
-#ifdef _MSC_VER /* doesn't implement the fancy initializers I think... */
-
-char basesyntax[257] = {CEOF};
-char dqsyntax[257] = {CEOF};
-char sqsyntax[257] = {CEOF};
-char arisyntax[257] = {CEOF};
-char is_type[257] = {0};
-
-void init_syntax(void)
-{
-    char *tab;
-    int i;
-
-#define ndx(ch) (ch + 1 - CHAR_MIN)
-#define set(ch, val) tab[ndx(ch)] = val
-#define set_range(s, e, val) for (i = ndx(s); i <= ndx(e); i++) tab[i] = val
-
-    /*basesyntax*/
-    tab = basesyntax;
-    set_range(CTL_FIRST, CTL_LAST, CCTL);
-    set('\n', CNL);
-    set('\\', CBACK);
-    set('\'', CSQUOTE);
-    set('"', CDQUOTE);
-    set('`', CBQUOTE);
-    set('$', CVAR);
-    set('}', CENDVAR);
-    set('<', CSPCL);
-    set('>', CSPCL);
-    set('(', CSPCL);
-    set(')', CSPCL);
-    set(';', CSPCL);
-    set('&', CSPCL);
-    set('|', CSPCL);
-    set(' ', CSPCL);
-    set('\t', CSPCL);
-
-    tab = dqsyntax;
-    set_range(CTL_FIRST, CTL_LAST, CCTL);
-    set('\n', CNL);
-    set('\\', CBACK);
-    set('"', CDQUOTE);
-    set('`', CBQUOTE);
-    set('$', CVAR);
-    set('}', CENDVAR);
-    /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
-    set('!', CCTL);
-    set('*', CCTL);
-    set('?', CCTL);
-    set('[', CCTL);
-    set('=', CCTL);
-    set('~', CCTL);
-    set(':', CCTL);
-    set('/', CCTL);
-    set('-', CCTL);
-
-    tab = sqsyntax;
-    set_range(CTL_FIRST, CTL_LAST, CCTL);
-    set('\n', CNL);
-    set('\'', CSQUOTE);
-    /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
-    set('!', CCTL);
-    set('*', CCTL) ;
-    set('?', CCTL);
-    set('[', CCTL);
-    set('=', CCTL);
-    set('~', CCTL);
-    set(':', CCTL);
-    set('/', CCTL);
-    set('-', CCTL);
-
-    tab = arisyntax;
-    set_range(CTL_FIRST, CTL_LAST, CCTL);
-    set('\n', CNL);
-    set('\\', CBACK);
-    set('`', CBQUOTE);
-    set('\'', CSQUOTE);
-    set('"', CDQUOTE);
-    set('$', CVAR);
-    set('}', CENDVAR);
-    set('(', CLP);
-    set(')', CRP);
-
-    tab = is_type;
-    set_range('0', '9', ISDIGIT);
-    set_range('a', 'z', ISLOWER);
-    set_range('A', 'Z', ISUPPER);
-    set('_', ISUNDER);
-    set('#', ISSPECL);
-    set('?', ISSPECL);
-    set('$', ISSPECL);
-    set('!', ISSPECL);
-    set('-', ISSPECL);
-    set('*', ISSPECL);
-    set('@', ISSPECL);
-}
-
-#else /* !_MSC_VER */
-
-#if CWORD != 0
-#error initialisation assumes 'CWORD' is zero
-#endif
-
-#define ndx(ch) (ch + 1 - CHAR_MIN)
-#define set(ch, val) [ndx(ch)] = val,
-#define set_range(s, e, val) [ndx(s) ... ndx(e)] = val,
-
-/* syntax table used when not in quotes */
-const char basesyntax[257] = { CEOF,
-    set_range(CTL_FIRST, CTL_LAST, CCTL)
-    set('\n', CNL)
-    set('\\', CBACK)
-    set('\'', CSQUOTE)
-    set('"', CDQUOTE)
-    set('`', CBQUOTE)
-    set('$', CVAR)
-    set('}', CENDVAR)
-    set('<', CSPCL)
-    set('>', CSPCL)
-    set('(', CSPCL)
-    set(')', CSPCL)
-    set(';', CSPCL)
-    set('&', CSPCL)
-    set('|', CSPCL)
-    set(' ', CSPCL)
-    set('\t', CSPCL)
-};
-
-/* syntax table used when in double quotes */
-const char dqsyntax[257] = { CEOF,
-    set_range(CTL_FIRST, CTL_LAST, CCTL)
-    set('\n', CNL)
-    set('\\', CBACK)
-    set('"', CDQUOTE)
-    set('`', CBQUOTE)
-    set('$', CVAR)
-    set('}', CENDVAR)
-    /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
-    set('!', CCTL)
-    set('*', CCTL)
-    set('?', CCTL)
-    set('[', CCTL)
-    set('=', CCTL)
-    set('~', CCTL)
-    set(':', CCTL)
-    set('/', CCTL)
-    set('-', CCTL)
-};
-
-/* syntax table used when in single quotes */
-const char sqsyntax[257] = { CEOF,
-    set_range(CTL_FIRST, CTL_LAST, CCTL)
-    set('\n', CNL)
-    set('\'', CSQUOTE)
-    /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
-    set('!', CCTL)
-    set('*', CCTL)
-    set('?', CCTL)
-    set('[', CCTL)
-    set('=', CCTL)
-    set('~', CCTL)
-    set(':', CCTL)
-    set('/', CCTL)
-    set('-', CCTL)
-};
-
-/* syntax table used when in arithmetic */
-const char arisyntax[257] = { CEOF,
-    set_range(CTL_FIRST, CTL_LAST, CCTL)
-    set('\n', CNL)
-    set('\\', CBACK)
-    set('`', CBQUOTE)
-    set('\'', CSQUOTE)
-    set('"', CDQUOTE)
-    set('$', CVAR)
-    set('}', CENDVAR)
-    set('(', CLP)
-    set(')', CRP)
-};
-
-/* character classification table */
-const char is_type[257] = { 0,
-    set_range('0', '9', ISDIGIT)
-    set_range('a', 'z', ISLOWER)
-    set_range('A', 'Z', ISUPPER)
-    set('_', ISUNDER)
-    set('#', ISSPECL)
-    set('?', ISSPECL)
-    set('$', ISSPECL)
-    set('!', ISSPECL)
-    set('-', ISSPECL)
-    set('*', ISSPECL)
-    set('@', ISSPECL)
-};
-#endif /* !_MSC_VER */
diff --git a/src/ash/syntax.h b/src/ash/syntax.h
deleted file mode 100644
index c40dac8..0000000
--- a/src/ash/syntax.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*	$NetBSD: syntax.h,v 1.2 2004/01/17 17:38:12 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#include <ctype.h>
-
-/* Syntax classes */
-#define CWORD 0			/* character is nothing special */
-#define CNL 1			/* newline character */
-#define CBACK 2			/* a backslash character */
-#define CSQUOTE 3		/* single quote */
-#define CDQUOTE 4		/* double quote */
-#define CBQUOTE 5		/* backwards single quote */
-#define CVAR 6			/* a dollar sign */
-#define CENDVAR 7		/* a '}' character */
-#define CLP 8			/* a left paren in arithmetic */
-#define CRP 9			/* a right paren in arithmetic */
-#define CEOF 10			/* end of file */
-#define CCTL 11			/* like CWORD, except it must be escaped */
-#define CSPCL 12		/* these terminate a word */
-
-/* Syntax classes for is_ functions */
-#define ISDIGIT 01		/* a digit */
-#define ISUPPER 02		/* an upper case letter */
-#define ISLOWER 04		/* a lower case letter */
-#define ISUNDER 010		/* an underscore */
-#define ISSPECL 020		/* the name of a special parameter */
-
-#define PEOF (CHAR_MIN - 1)
-#define SYNBASE (-PEOF)
-/* XXX UPEOF is CHAR_MAX, so is a valid 'char' value... */
-#define UPEOF ((char)PEOF)
-
-
-#define BASESYNTAX (basesyntax + SYNBASE)
-#define DQSYNTAX (dqsyntax + SYNBASE)
-#define SQSYNTAX (sqsyntax + SYNBASE)
-#define ARISYNTAX (arisyntax + SYNBASE)
-
-/* These defines assume that the digits are contiguous */
-#define is_digit(c)	((unsigned)((c) - '0') <= 9)
-#define is_alpha(c)	(((char)(c)) != UPEOF && ((c) < CTL_FIRST || (c) > CTL_LAST) && isalpha((unsigned char)(c)))
-#define is_name(c)	(((char)(c)) != UPEOF && ((c) < CTL_FIRST || (c) > CTL_LAST) && ((c) == '_' || isalpha((unsigned char)(c))))
-#define is_in_name(c)	(((char)(c)) != UPEOF && ((c) < CTL_FIRST || (c) > CTL_LAST) && ((c) == '_' || isalnum((unsigned char)(c))))
-#define is_special(c)	((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))
-#define digit_val(c)	((c) - '0')
-
-#ifdef _MSC_VER
-extern char basesyntax[];
-extern char dqsyntax[];
-extern char sqsyntax[];
-extern char arisyntax[];
-extern char is_type[];
-#else
-extern const char basesyntax[];
-extern const char dqsyntax[];
-extern const char sqsyntax[];
-extern const char arisyntax[];
-extern const char is_type[];
-#endif
diff --git a/src/ash/sys_signame.c b/src/ash/sys_signame.c
deleted file mode 100644
index 2fb554a..0000000
--- a/src/ash/sys_signame.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Fake sys_signame.  
- */
-
-#include <signal.h>
-#include <string.h>
-#include <stdio.h>
-
-static char sys_signame_initialized = 0;
-char sys_signame[NSIG][16];
-              
-void init_sys_signame(void)
-{
-    unsigned i;
-	if (sys_signame_initialized)
-        return;
-    for (i = 0; i < NSIG; ++i)
-        sprintf(sys_signame[i], "%d", i);
-#define SET_SIG_STR(sig) strcpy(sys_signame[SIG##sig], #sig);
-#ifdef SIGHUP
-    SET_SIG_STR(HUP);
-#endif 
-#ifdef SIGINT
-    SET_SIG_STR(INT);
-#endif 
-#ifdef SIGQUIT
-    SET_SIG_STR(QUIT);
-#endif 
-#ifdef SIGILL
-    SET_SIG_STR(ILL);
-#endif 
-#ifdef SIGTRAP
-    SET_SIG_STR(TRAP);
-#endif 
-#ifdef SIGABRT
-    SET_SIG_STR(ABRT);
-#endif 
-#ifdef SIGIOT
-    SET_SIG_STR(IOT);
-#endif 
-#ifdef SIGBUS
-    SET_SIG_STR(BUS);
-#endif 
-#ifdef SIGFPE
-    SET_SIG_STR(FPE);
-#endif 
-#ifdef SIGKILL
-    SET_SIG_STR(KILL);
-#endif 
-#ifdef SIGUSR1
-    SET_SIG_STR(USR1);
-#endif 
-#ifdef SIGSEGV
-    SET_SIG_STR(SEGV);
-#endif 
-#ifdef SIGUSR2
-    SET_SIG_STR(USR2);
-#endif 
-#ifdef SIGPIPE
-    SET_SIG_STR(PIPE);
-#endif 
-#ifdef SIGALRM
-    SET_SIG_STR(ALRM);
-#endif 
-#ifdef SIGTERM
-    SET_SIG_STR(TERM);
-#endif 
-#ifdef SIGSTKFLT
-    SET_SIG_STR(STKFLT);
-#endif 
-#ifdef SIGCHLD
-    SET_SIG_STR(CHLD);
-#endif 
-#ifdef SIGCONT
-    SET_SIG_STR(CONT);
-#endif 
-#ifdef SIGSTOP
-    SET_SIG_STR(STOP);
-#endif 
-#ifdef SIGTSTP
-    SET_SIG_STR(TSTP);
-#endif 
-#ifdef SIGTTIN
-    SET_SIG_STR(TTIN);
-#endif 
-#ifdef SIGTTOU
-    SET_SIG_STR(TTOU);
-#endif 
-#ifdef SIGURG
-    SET_SIG_STR(URG);
-#endif 
-#ifdef SIGXCPU
-    SET_SIG_STR(XCPU);
-#endif 
-#ifdef SIGXFSZ
-    SET_SIG_STR(XFSZ);
-#endif 
-#ifdef SIGVTALRM
-    SET_SIG_STR(VTALRM);
-#endif 
-#ifdef SIGPROF
-    SET_SIG_STR(PROF);
-#endif 
-#ifdef SIGWINCH
-    SET_SIG_STR(WINCH);
-#endif 
-#ifdef SIGIO
-    SET_SIG_STR(IO);
-#endif 
-#ifdef SIGPWR
-    SET_SIG_STR(PWR);
-#endif 
-#ifdef SIGSYS
-    SET_SIG_STR(SYS);
-#endif 
-#ifdef SIGBREAK
-    SET_SIG_STR(BREAK);
-#endif 
-#undef SET_SIG_STR
-    sys_signame_initialized = 1;
-}
diff --git a/src/ash/trap.c b/src/ash/trap.c
deleted file mode 100644
index 6a246e6..0000000
--- a/src/ash/trap.c
+++ /dev/null
@@ -1,468 +0,0 @@
-/*	$NetBSD: trap.c,v 1.31 2005/01/11 19:38:57 christos Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)trap.c	8.5 (Berkeley) 6/5/95";
-#else
-__RCSID("$NetBSD: trap.c,v 1.31 2005/01/11 19:38:57 christos Exp $");
-#endif
-#endif /* not lint */
-
-#include <signal.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "shell.h"
-#include "main.h"
-#include "nodes.h"	/* for other headers */
-#include "eval.h"
-#include "jobs.h"
-#include "show.h"
-#include "options.h"
-#include "syntax.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "trap.h"
-#include "mystring.h"
-#include "var.h"
-
-#ifndef HAVE_SYS_SIGNAME
-extern void init_sys_signame(void);
-extern char sys_signame[NSIG][16];
-#endif
-
-/*
- * Sigmode records the current value of the signal handlers for the various
- * modes.  A value of zero means that the current handler is not known.
- * S_HARD_IGN indicates that the signal was ignored on entry to the shell,
- */
-
-#define S_DFL 1			/* default signal handling (SIG_DFL) */
-#define S_CATCH 2		/* signal is caught */
-#define S_IGN 3			/* signal is ignored (SIG_IGN) */
-#define S_HARD_IGN 4		/* signal is ignored permenantly */
-#define S_RESET 5		/* temporary - to reset a hard ignored sig */
-
-
-char *trap[NSIG+1];		/* trap handler commands */
-MKINIT char sigmode[NSIG];	/* current value of signal */
-char gotsig[NSIG];		/* indicates specified signal received */
-int pendingsigs;		/* indicates some signal received */
-
-#ifdef __sun__
-typedef void (*sig_t) (int);
-#endif
-static int getsigaction(int, sig_t *);
-
-/*
- * return the signal number described by `p' (as a number or a name)
- * or -1 if it isn't one
- */
-
-static int
-signame_to_signum(const char *p)
-{
-	int i;
-
-	if (is_number(p))
-		return number(p);
-
-	if (strcasecmp(p, "exit") == 0 )
-		return 0;
-
-	if (strncasecmp(p, "sig", 3) == 0)
-		p += 3;
-
-#ifndef HAVE_SYS_SIGNAME
-	init_sys_signame();
-#endif
-	for (i = 0; i < NSIG; ++i)
-		if (strcasecmp (p, sys_signame[i]) == 0)
-			return i;
-	return -1;
-}
-
-/*
- * Print a list of valid signal names
- */
-static void
-printsignals(void)
-{
-	int n;
-
-	out1str("EXIT ");
-#ifndef HAVE_SYS_SIGNAME
-	init_sys_signame();
-#endif
-
-	for (n = 1; n < NSIG; n++) {
-		out1fmt("%s", sys_signame[n]);
-		if ((n == NSIG/2) ||  n == (NSIG - 1))
-			out1str("\n");
-		else
-			out1c(' ');
-	}
-}
-
-/*
- * The trap builtin.
- */
-
-int
-trapcmd(int argc, char **argv)
-{
-	char *action;
-	char **ap;
-	int signo;
-#ifndef HAVE_SYS_SIGNAME
-	init_sys_signame();
-#endif
-
-	if (argc <= 1) {
-		for (signo = 0 ; signo <= NSIG ; signo++)
-			if (trap[signo] != NULL) {
-				out1fmt("trap -- ");
-				print_quoted(trap[signo]);
-				out1fmt(" %s\n",
-				    (signo) ? sys_signame[signo] : "EXIT");
-			}
-		return 0;
-	}
-	ap = argv + 1;
-
-	action = NULL;
-
-	if (strcmp(*ap, "--") == 0)
-		if (*++ap == NULL)
-			return 0;
-
-	if (signame_to_signum(*ap) == -1) {
-		if ((*ap)[0] == '-') {
-			if ((*ap)[1] == '\0')
-				ap++;
-			else if ((*ap)[1] == 'l' && (*ap)[2] == '\0') {
-				printsignals();
-				return 0;
-			}
-			else
-				error("bad option %s\n", *ap);
-		}
-		else
-			action = *ap++;
-	}
-
-	while (*ap) {
-		if (is_number(*ap))
-			signo = number(*ap);
-		else
-			signo = signame_to_signum(*ap);
-
-		if (signo < 0 || signo > NSIG)
-			error("%s: bad trap", *ap);
-
-		INTOFF;
-		if (action)
-			action = savestr(action);
-
-		if (trap[signo])
-			ckfree(trap[signo]);
-
-		trap[signo] = action;
-
-		if (signo != 0)
-			setsignal(signo, 0);
-		INTON;
-		ap++;
-	}
-	return 0;
-}
-
-
-
-/*
- * Clear traps on a fork or vfork.
- * Takes one arg vfork, to tell it to not be destructive of
- * the parents variables.
- */
-
-void
-clear_traps(int vforked)
-{
-	char **tp;
-
-	for (tp = trap ; tp <= &trap[NSIG] ; tp++) {
-		if (*tp && **tp) {	/* trap not NULL or SIG_IGN */
-			INTOFF;
-			if (!vforked) {
-				ckfree(*tp);
-				*tp = NULL;
-			}
-			if (tp != &trap[0])
-				setsignal(tp - trap, vforked);
-			INTON;
-		}
-	}
-}
-
-
-
-/*
- * Set the signal handler for the specified signal.  The routine figures
- * out what it should be set to.
- */
-
-long
-setsignal(int signo, int vforked)
-{
-	int action;
-	sig_t sigact = SIG_DFL;
-	char *t, tsig;
-
-	if ((t = trap[signo]) == NULL)
-		action = S_DFL;
-	else if (*t != '\0')
-		action = S_CATCH;
-	else
-		action = S_IGN;
-	if (rootshell && !vforked && action == S_DFL) {
-		switch (signo) {
-		case SIGINT:
-			if (iflag || minusc || sflag == 0)
-				action = S_CATCH;
-			break;
-		case SIGQUIT:
-#ifdef DEBUG
-			if (debug)
-				break;
-#endif
-			/* FALLTHROUGH */
-		case SIGTERM:
-			if (iflag)
-				action = S_IGN;
-			break;
-#if JOBS
-		case SIGTSTP:
-		case SIGTTOU:
-			if (mflag)
-				action = S_IGN;
-			break;
-#endif
-		}
-	}
-
-	t = &sigmode[signo - 1];
-	tsig = *t;
-	if (tsig == 0) {
-		/*
-		 * current setting unknown
-		 */
-		if (!getsigaction(signo, &sigact)) {
-			/*
-			 * Pretend it worked; maybe we should give a warning
-			 * here, but other shells don't. We don't alter
-			 * sigmode, so that we retry every time.
-			 */
-			return 0;
-		}
-		if (sigact == SIG_IGN) {
-			if (mflag && (signo == SIGTSTP ||
-			     signo == SIGTTIN || signo == SIGTTOU)) {
-				tsig = S_IGN;	/* don't hard ignore these */
-			} else
-				tsig = S_HARD_IGN;
-		} else {
-			tsig = S_RESET;	/* force to be set */
-		}
-	}
-	if (tsig == S_HARD_IGN || tsig == action)
-		return 0;
-	switch (action) {
-		case S_DFL:	sigact = SIG_DFL;	break;
-		case S_CATCH:  	sigact = onsig;		break;
-		case S_IGN:	sigact = SIG_IGN;	break;
-	}
-	if (!vforked)
-		*t = action;
-	siginterrupt(signo, 1);
-	return (long)signal(signo, sigact);
-}
-
-/*
- * Return the current setting for sig w/o changing it.
- */
-static int
-getsigaction(int signo, sig_t *sigact)
-{
-	struct sigaction sa;
-
-	if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
-		return 0;
-	*sigact = (sig_t) sa.sa_handler;
-	return 1;
-}
-
-/*
- * Ignore a signal.
- */
-
-void
-ignoresig(int signo, int vforked)
-{
-	if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
-		signal(signo, SIG_IGN);
-	}
-	if (!vforked)
-		sigmode[signo - 1] = S_HARD_IGN;
-}
-
-
-#ifdef mkinit
-INCLUDE <signal.h>
-INCLUDE "trap.h"
-
-SHELLPROC {
-	char *sm;
-
-	clear_traps(0);
-	for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
-		if (*sm == S_IGN)
-			*sm = S_HARD_IGN;
-	}
-}
-#endif
-
-
-
-/*
- * Signal handler.
- */
-
-void
-onsig(int signo)
-{
-	signal(signo, onsig);
-	if (signo == SIGINT && trap[SIGINT] == NULL) {
-		onint();
-		return;
-	}
-	gotsig[signo - 1] = 1;
-	pendingsigs++;
-}
-
-
-
-/*
- * Called to execute a trap.  Perhaps we should avoid entering new trap
- * handlers while we are executing a trap handler.
- */
-
-void
-dotrap(void)
-{
-	int i;
-	int savestatus;
-
-	for (;;) {
-		for (i = 1 ; ; i++) {
-			if (gotsig[i - 1])
-				break;
-			if (i >= NSIG)
-				goto done;
-		}
-		gotsig[i - 1] = 0;
-		savestatus=exitstatus;
-		evalstring(trap[i], 0);
-		exitstatus=savestatus;
-	}
-done:
-	pendingsigs = 0;
-}
-
-
-
-/*
- * Controls whether the shell is interactive or not.
- */
-
-
-void
-setinteractive(int on)
-{
-	static int is_interactive;
-
-	if (on == is_interactive)
-		return;
-	setsignal(SIGINT, 0);
-	setsignal(SIGQUIT, 0);
-	setsignal(SIGTERM, 0);
-	is_interactive = on;
-}
-
-
-
-/*
- * Called to exit the shell.
- */
-
-void
-exitshell(int status)
-{
-	struct jmploc loc1, loc2;
-	char *p;
-
-	TRACE(("pid %d, exitshell(%d)\n", getpid(), status));
-	if (setjmp(loc1.loc)) {
-		goto l1;
-	}
-	if (setjmp(loc2.loc)) {
-		goto l2;
-	}
-	handler = &loc1;
-	if ((p = trap[0]) != NULL && *p != '\0') {
-		trap[0] = NULL;
-		evalstring(p, 0);
-	}
-l1:   handler = &loc2;			/* probably unnecessary */
-	output_flushall();
-#if JOBS
-	setjobctl(0);
-#endif
-l2:   _exit(status);
-	/* NOTREACHED */
-}
diff --git a/src/ash/trap.h b/src/ash/trap.h
deleted file mode 100644
index 125ef40..0000000
--- a/src/ash/trap.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*	$NetBSD: trap.h,v 1.17 2003/08/07 09:05:39 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)trap.h	8.3 (Berkeley) 6/5/95
- */
-
-extern int pendingsigs;
-
-int trapcmd(int, char **);
-void clear_traps(int);
-long setsignal(int, int);
-void ignoresig(int, int);
-void onsig(int);
-void dotrap(void);
-void setinteractive(int);
-void exitshell(int) __attribute__((__noreturn__));
diff --git a/src/ash/var.c b/src/ash/var.c
deleted file mode 100644
index 4f2e2a3..0000000
--- a/src/ash/var.c
+++ /dev/null
@@ -1,933 +0,0 @@
-/*	$NetBSD: var.c,v 1.36 2004/10/06 10:23:43 enami Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 5/4/95";
-#else
-__RCSID("$NetBSD: var.c,v 1.36 2004/10/06 10:23:43 enami Exp $");
-#endif
-#endif /* not lint */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <strings.h>
-#ifndef __sun__
-#include <paths.h>
-#else
-#define _PATH_DEFPATH        "/usr/bin:/usr/sbin"
-#include <iso/limits_iso.h>
-#endif
-
-#ifdef PC_OS2_LIBPATHS
-#define INCL_BASE
-#include <os2.h>
-
-#ifndef LIBPATHSTRICT
-#define LIBPATHSTRICT 3
-#endif
-
-extern APIRET
-#ifdef APIENTRY
-    APIENTRY
-#endif
-    DosQueryHeaderInfo(HMODULE hmod, ULONG ulIndex, PVOID pvBuffer, ULONG cbBuffer, ULONG ulSubFunction);
-#define QHINF_EXEINFO       1 /* NE exeinfo. */
-#define QHINF_READRSRCTBL   2 /* Reads from the resource table. */
-#define QHINF_READFILE      3 /* Reads from the executable file. */
-#define QHINF_LIBPATHLENGTH 4 /* Gets the libpath length. */
-#define QHINF_LIBPATH       5 /* Gets the entire libpath. */
-#define QHINF_FIXENTRY      6 /* NE only */
-#define QHINF_STE           7 /* NE only */
-#define QHINF_MAPSEL        8 /* NE only */
-
-#endif
-
-
-/*
- * Shell variables.
- */
-
-#include "shell.h"
-#include "output.h"
-#include "expand.h"
-#include "nodes.h"	/* for other headers */
-#include "eval.h"	/* defines cmdenviron */
-#include "exec.h"
-#include "syntax.h"
-#include "options.h"
-#include "mail.h"
-#include "var.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#include "parser.h"
-#include "show.h"
-#ifndef SMALL
-#include "myhistedit.h"
-#endif
-
-#ifdef SMALL
-#define VTABSIZE 39
-#else
-#define VTABSIZE 517
-#endif
-
-
-struct varinit {
-	struct var *var;
-	int flags;
-	const char *text;
-	void (*func)(const char *);
-};
-
-
-#if ATTY
-struct var vatty;
-#endif
-#ifndef SMALL
-struct var vhistsize;
-struct var vterm;
-#endif
-struct var vifs;
-struct var vmail;
-struct var vmpath;
-struct var vpath;
-#ifdef _MSC_VER
-struct var vpath2;
-#endif
-struct var vps1;
-struct var vps2;
-struct var vps4;
-struct var vvers;
-struct var voptind;
-
-#ifdef PC_OS2_LIBPATHS
-static struct var libpath_vars[4];
-static const char *libpath_envs[4] = {"LIBPATH=", "BEGINLIBPATH=", "ENDLIBPATH=", "LIBPATHSTRICT="};
-#endif
-
-const struct varinit varinit[] = {
-#if ATTY
-	{ &vatty,	VSTRFIXED|VTEXTFIXED|VUNSET,	"ATTY=",
-	  NULL },
-#endif
-#ifndef SMALL
-	{ &vhistsize,	VSTRFIXED|VTEXTFIXED|VUNSET,	"HISTSIZE=",
-	  sethistsize },
-#endif
-	{ &vifs,	VSTRFIXED|VTEXTFIXED,		"IFS= \t\n",
-	  NULL },
-	{ &vmail,	VSTRFIXED|VTEXTFIXED|VUNSET,	"MAIL=",
-	  NULL },
-	{ &vmpath,	VSTRFIXED|VTEXTFIXED|VUNSET,	"MAILPATH=",
-	  NULL },
-	{ &vpath,	VSTRFIXED|VTEXTFIXED,		"PATH=" _PATH_DEFPATH,
-	  changepath },
-#ifdef _MSC_VER
-	{ &vpath2,	VSTRFIXED|VTEXTFIXED,		"Path=",
-	  changepath },
-#endif
-	/*
-	 * vps1 depends on uid
-	 */
-	{ &vps2,	VSTRFIXED|VTEXTFIXED,		"PS2=> ",
-	  NULL },
-	{ &vps4,	VSTRFIXED|VTEXTFIXED,		"PS4=+ ",
-	  NULL },
-#ifndef SMALL
-	{ &vterm,	VSTRFIXED|VTEXTFIXED|VUNSET,	"TERM=",
-	  setterm },
-#endif
-	{ &voptind,	VSTRFIXED|VTEXTFIXED|VNOFUNC,	"OPTIND=1",
-	  getoptsreset },
-	{ NULL,	0,				NULL,
-	  NULL }
-};
-
-struct var *vartab[VTABSIZE];
-
-STATIC int strequal(const char *, const char *);
-STATIC struct var *find_var(const char *, struct var ***, int *);
-
-/*
- * Initialize the varable symbol tables and import the environment
- */
-
-#ifdef mkinit
-INCLUDE "var.h"
-MKINIT char **environ;
-INIT {
-	char **envp;
-
-	initvar();
-	for (envp = environ ; *envp ; envp++) {
-		if (strchr(*envp, '=')) {
-			setvareq(*envp, VEXPORT|VTEXTFIXED);
-		}
-	}
-}
-#endif
-
-
-/*
- * This routine initializes the builtin variables.  It is called when the
- * shell is initialized and again when a shell procedure is spawned.
- */
-
-void
-initvar(void)
-{
-	const struct varinit *ip;
-	struct var *vp;
-	struct var **vpp;
-
-#ifdef PC_OS2_LIBPATHS
-        char *psz = ckmalloc(2048);
-        int rc;
-        int i;
-        for (i = 0; i < 4; i++)
-        {
-            libpath_vars[i].flags = VSTRFIXED | VOS2LIBPATH;
-            libpath_vars[i].func = NULL;
-
-            if (i > 0)
-            {
-                psz[0] = psz[1] = psz[2] = psz[3] = '\0'; 
-                rc = DosQueryExtLIBPATH(psz, i);
-            }
-            else
-            {
-                rc = DosQueryHeaderInfo(NULLHANDLE, 0, psz, 2048, QHINF_LIBPATH);
-                libpath_vars[i].flags |= VREADONLY;
-            }
-            if (!rc && *psz)
-            {
-                int cch1 = strlen(libpath_envs[i]);
-                int cch2 = strlen(psz) + 1;
-                libpath_vars[i].text = ckmalloc(cch1 + cch2);
-                memcpy(libpath_vars[i].text, libpath_envs[i], cch1);
-                memcpy(libpath_vars[i].text + cch1, psz, cch2);
-            }
-            else
-            {
-                libpath_vars[i].flags |= VUNSET | VTEXTFIXED;
-                libpath_vars[i].text = (char*)libpath_envs[i];
-            }
-            if (find_var(libpath_vars[i].text, &vpp, &libpath_vars[i].name_len) != NULL)
-                    continue;
-            libpath_vars[i].next = *vpp;
-            *vpp = &libpath_vars[i];
-        }
-        free(psz);
-#endif
-
-	for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
-		if (find_var(ip->text, &vpp, &vp->name_len) != NULL)
-			continue;
-		vp->next = *vpp;
-		*vpp = vp;
-		vp->text = strdup(ip->text);
-		vp->flags = ip->flags;
-		vp->func = ip->func;
-	}
-	/*
-	 * PS1 depends on uid
-	 */
-	if (find_var("PS1", &vpp, &vps1.name_len) == NULL) {
-		vps1.next = *vpp;
-		*vpp = &vps1;
-		vps1.text = strdup(geteuid() ? "PS1=$ " : "PS1=# ");
-		vps1.flags = VSTRFIXED|VTEXTFIXED;
-	}
-}
-
-/*
- * Safe version of setvar, returns 1 on success 0 on failure.
- */
-
-int
-setvarsafe(const char *name, const char *val, int flags)
-{
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler = handler;
-	int err = 0;
-#ifdef __GNUC__
-	(void) &err;
-#endif
-
-	if (setjmp(jmploc.loc))
-		err = 1;
-	else {
-		handler = &jmploc;
-		setvar(name, val, flags);
-	}
-	handler = savehandler;
-	return err;
-}
-
-/*
- * Set the value of a variable.  The flags argument is ored with the
- * flags of the variable.  If val is NULL, the variable is unset.
- */
-
-void
-setvar(const char *name, const char *val, int flags)
-{
-	const char *p;
-	const char *q;
-	char *d;
-	int len;
-	int namelen;
-	char *nameeq;
-	int isbad;
-
-	isbad = 0;
-	p = name;
-	if (! is_name(*p))
-		isbad = 1;
-	p++;
-	for (;;) {
-		if (! is_in_name(*p)) {
-			if (*p == '\0' || *p == '=')
-				break;
-			isbad = 1;
-		}
-		p++;
-	}
-	namelen = p - name;
-	if (isbad)
-		error("%.*s: bad variable name", namelen, name);
-	len = namelen + 2;		/* 2 is space for '=' and '\0' */
-	if (val == NULL) {
-		flags |= VUNSET;
-	} else {
-		len += strlen(val);
-	}
-	d = nameeq = ckmalloc(len);
-	q = name;
-	while (--namelen >= 0)
-		*d++ = *q++;
-	*d++ = '=';
-	*d = '\0';
-	if (val)
-		scopy(val, d);
-	setvareq(nameeq, flags);
-}
-
-
-
-/*
- * Same as setvar except that the variable and value are passed in
- * the first argument as name=value.  Since the first argument will
- * be actually stored in the table, it should not be a string that
- * will go away.
- */
-
-void
-setvareq(char *s, int flags)
-{
-	struct var *vp, **vpp;
-	int nlen;
-
-	if (aflag)
-		flags |= VEXPORT;
-	vp = find_var(s, &vpp, &nlen);
-	if (vp != NULL) {
-		if (vp->flags & VREADONLY)
-			error("%.*s: is read only", vp->name_len, s);
-		if (flags & VNOSET)
-			return;
-		INTOFF;
-
-		if (vp->func && (flags & VNOFUNC) == 0)
-			(*vp->func)(s + vp->name_len + 1);
-
-		if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
-			ckfree(vp->text);
-
-		vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET);
-		vp->flags |= flags & ~VNOFUNC;
-		vp->text = s;
-#ifdef PC_OS2_LIBPATHS
-                if ((vp->flags & VOS2LIBPATH) && (vp->flags & VEXPORT))
-                    vp->flags &= ~VEXPORT;
-#endif
-
-		/*
-		 * We could roll this to a function, to handle it as
-		 * a regular variable function callback, but why bother?
-		 */
-		if (vp == &vmpath || (vp == &vmail && ! mpathset()))
-			chkmail(1);
-		INTON;
-		return;
-	}
-	/* not found */
-	if (flags & VNOSET)
-		return;
-	vp = ckmalloc(sizeof (*vp));
-	vp->flags = flags & ~VNOFUNC;
-	vp->text = s;
-	vp->name_len = nlen;
-	vp->next = *vpp;
-	vp->func = NULL;
-	*vpp = vp;
-}
-
-
-
-/*
- * Process a linked list of variable assignments.
- */
-
-void
-listsetvar(struct strlist *list, int flags)
-{
-	struct strlist *lp;
-
-	INTOFF;
-	for (lp = list ; lp ; lp = lp->next) {
-		setvareq(savestr(lp->text), flags);
-	}
-	INTON;
-}
-
-void
-listmklocal(struct strlist *list, int flags)
-{
-	struct strlist *lp;
-
-	for (lp = list ; lp ; lp = lp->next)
-		mklocal(lp->text, flags);
-}
-
-
-/*
- * Find the value of a variable.  Returns NULL if not set.
- */
-
-char *
-lookupvar(const char *name)
-{
-	struct var *v;
-
-	v = find_var(name, NULL, NULL);
-	if (v == NULL || v->flags & VUNSET)
-		return NULL;
-	return v->text + v->name_len + 1;
-}
-
-
-
-/*
- * Search the environment of a builtin command.  If the second argument
- * is nonzero, return the value of a variable even if it hasn't been
- * exported.
- */
-
-char *
-bltinlookup(const char *name, int doall)
-{
-	struct strlist *sp;
-	struct var *v;
-
-	for (sp = cmdenviron ; sp ; sp = sp->next) {
-		if (strequal(sp->text, name))
-			return strchr(sp->text, '=') + 1;
-	}
-
-	v = find_var(name, NULL, NULL);
-
-	if (v == NULL || v->flags & VUNSET || (!doall && !(v->flags & VEXPORT)))
-		return NULL;
-	return v->text + v->name_len + 1;
-}
-
-
-
-/*
- * Generate a list of exported variables.  This routine is used to construct
- * the third argument to execve when executing a program.
- */
-
-char **
-environment(void)
-{
-	int nenv;
-	struct var **vpp;
-	struct var *vp;
-	char **env;
-	char **ep;
-
-	nenv = 0;
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (vp = *vpp ; vp ; vp = vp->next)
-			if (vp->flags & VEXPORT)
-				nenv++;
-	}
-	ep = env = stalloc((nenv + 1) * sizeof *env);
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (vp = *vpp ; vp ; vp = vp->next)
-			if (vp->flags & VEXPORT)
-				*ep++ = vp->text;
-	}
-	*ep = NULL;
-
-#ifdef PC_OS2_LIBPATHS
-        /*
-         * Set the libpaths now as this is exec() time.
-         */
-        for (nenv = 0; nenv < 3; nenv++)
-            DosSetExtLIBPATH(strchr(libpath_vars[nenv].text, '=') + 1, nenv);
-#endif
-
-	return env;
-}
-
-
-/*
- * Called when a shell procedure is invoked to clear out nonexported
- * variables.  It is also necessary to reallocate variables of with
- * VSTACK set since these are currently allocated on the stack.
- */
-
-#ifdef mkinit
-void shprocvar(void);
-
-SHELLPROC {
-	shprocvar();
-}
-#endif
-
-void
-shprocvar(void)
-{
-	struct var **vpp;
-	struct var *vp, **prev;
-
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (prev = vpp ; (vp = *prev) != NULL ; ) {
-			if ((vp->flags & VEXPORT) == 0) {
-				*prev = vp->next;
-				if ((vp->flags & VTEXTFIXED) == 0)
-					ckfree(vp->text);
-				if ((vp->flags & VSTRFIXED) == 0)
-					ckfree(vp);
-			} else {
-				if (vp->flags & VSTACK) {
-					vp->text = savestr(vp->text);
-					vp->flags &=~ VSTACK;
-				}
-				prev = &vp->next;
-			}
-		}
-	}
-	initvar();
-}
-
-
-
-/*
- * Command to list all variables which are set.  Currently this command
- * is invoked from the set command when the set command is called without
- * any variables.
- */
-
-void
-print_quoted(const char *p)
-{
-	const char *q;
-
-	if (strcspn(p, "|&;<>()$`\\\"' \t\n*?[]#~=%") == strlen(p)) {
-		out1fmt("%s", p);
-		return;
-	}
-	while (*p) {
-		if (*p == '\'') {
-			out1fmt("\\'");
-			p++;
-			continue;
-		}
-		q = index(p, '\'');
-		if (!q) {
-			out1fmt("'%s'", p );
-			return;
-		}
-		out1fmt("'%.*s'", (int)(q - p), p );
-		p = q;
-	}
-}
-
-static int
-sort_var(const void *v_v1, const void *v_v2)
-{
-	const struct var * const *v1 = v_v1;
-	const struct var * const *v2 = v_v2;
-
-	/* XXX Will anyone notice we include the '=' of the shorter name? */
-	return strcoll((*v1)->text, (*v2)->text);
-}
-
-/*
- * POSIX requires that 'set' (but not export or readonly) output the
- * variables in lexicographic order - by the locale's collating order (sigh).
- * Maybe we could keep them in an ordered balanced binary tree
- * instead of hashed lists.
- * For now just roll 'em through qsort for printing...
- */
-
-int
-showvars(const char *name, int flag, int show_value)
-{
-	struct var **vpp;
-	struct var *vp;
-	const char *p;
-
-	static struct var **list;	/* static in case we are interrupted */
-	static int list_len;
-	int count = 0;
-
-	if (!list) {
-		list_len = 32;
-		list = ckmalloc(list_len * sizeof *list);
-	}
-
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (vp = *vpp ; vp ; vp = vp->next) {
-			if (flag && !(vp->flags & flag))
-				continue;
-			if (vp->flags & VUNSET && !(show_value & 2))
-				continue;
-			if (count >= list_len) {
-				list = ckrealloc(list,
-					(list_len << 1) * sizeof *list);
-				list_len <<= 1;
-			}
-			list[count++] = vp;
-		}
-	}
-
-	qsort(list, count, sizeof *list, sort_var);
-
-	for (vpp = list; count--; vpp++) {
-		vp = *vpp;
-		if (name)
-			out1fmt("%s ", name);
-		for (p = vp->text ; *p != '=' ; p++)
-			out1c(*p);
-		if (!(vp->flags & VUNSET) && show_value) {
-			out1fmt("=");
-			print_quoted(++p);
-		}
-		out1c('\n');
-	}
-	return 0;
-}
-
-
-
-/*
- * The export and readonly commands.
- */
-
-int
-exportcmd(int argc, char **argv)
-{
-	struct var *vp;
-	char *name;
-	const char *p;
-	int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
-	int pflag;
-
-	pflag = nextopt("p") == 'p' ? 3 : 0;
-	if (argc <= 1 || pflag) {
-		showvars( pflag ? argv[0] : 0, flag, pflag );
-		return 0;
-	}
-
-	while ((name = *argptr++) != NULL) {
-		if ((p = strchr(name, '=')) != NULL) {
-			p++;
-		} else {
-			vp = find_var(name, NULL, NULL);
-			if (vp != NULL) {
-				vp->flags |= flag;
-				continue;
-			}
-		}
-		setvar(name, p, flag);
-	}
-	return 0;
-}
-
-
-/*
- * The "local" command.
- */
-
-int
-localcmd(int argc, char **argv)
-{
-	char *name;
-
-	if (! in_function())
-		error("Not in a function");
-	while ((name = *argptr++) != NULL) {
-		mklocal(name, 0);
-	}
-	return 0;
-}
-
-
-/*
- * Make a variable a local variable.  When a variable is made local, it's
- * value and flags are saved in a localvar structure.  The saved values
- * will be restored when the shell function returns.  We handle the name
- * "-" as a special case.
- */
-
-void
-mklocal(const char *name, int flags)
-{
-	struct localvar *lvp;
-	struct var **vpp;
-	struct var *vp;
-
-	INTOFF;
-	lvp = ckmalloc(sizeof (struct localvar));
-	if (name[0] == '-' && name[1] == '\0') {
-		char *p;
-		p = ckmalloc(sizeof_optlist);
-		lvp->text = memcpy(p, optlist, sizeof_optlist);
-		vp = NULL;
-	} else {
-		vp = find_var(name, &vpp, NULL);
-		if (vp == NULL) {
-			if (strchr(name, '='))
-				setvareq(savestr(name), VSTRFIXED|flags);
-			else
-				setvar(name, NULL, VSTRFIXED|flags);
-			vp = *vpp;	/* the new variable */
-			lvp->text = NULL;
-			lvp->flags = VUNSET;
-		} else {
-			lvp->text = vp->text;
-			lvp->flags = vp->flags;
-			vp->flags |= VSTRFIXED|VTEXTFIXED;
-			if (name[vp->name_len] == '=')
-				setvareq(savestr(name), flags);
-		}
-	}
-	lvp->vp = vp;
-	lvp->next = localvars;
-	localvars = lvp;
-	INTON;
-}
-
-
-/*
- * Called after a function returns.
- */
-
-void
-poplocalvars(void)
-{
-	struct localvar *lvp;
-	struct var *vp;
-
-	while ((lvp = localvars) != NULL) {
-		localvars = lvp->next;
-		vp = lvp->vp;
-		TRACE(("poplocalvar %s", vp ? vp->text : "-"));
-		if (vp == NULL) {	/* $- saved */
-			memcpy(optlist, lvp->text, sizeof_optlist);
-			ckfree(lvp->text);
-		} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
-			(void)unsetvar(vp->text, 0);
-		} else {
-			if (vp->func && (vp->flags & VNOFUNC) == 0)
-				(*vp->func)(lvp->text + vp->name_len + 1);
-			if ((vp->flags & VTEXTFIXED) == 0)
-				ckfree(vp->text);
-			vp->flags = lvp->flags;
-			vp->text = lvp->text;
-		}
-		ckfree(lvp);
-	}
-}
-
-
-int
-setvarcmd(int argc, char **argv)
-{
-	if (argc <= 2)
-		return unsetcmd(argc, argv);
-	else if (argc == 3)
-		setvar(argv[1], argv[2], 0);
-	else
-		error("List assignment not implemented");
-	return 0;
-}
-
-
-/*
- * The unset builtin command.  We unset the function before we unset the
- * variable to allow a function to be unset when there is a readonly variable
- * with the same name.
- */
-
-int
-unsetcmd(int argc, char **argv)
-{
-	char **ap;
-	int i;
-	int flg_func = 0;
-	int flg_var = 0;
-	int ret = 0;
-
-	while ((i = nextopt("evf")) != '\0') {
-		if (i == 'f')
-			flg_func = 1;
-		else
-			flg_var = i;
-	}
-	if (flg_func == 0 && flg_var == 0)
-		flg_var = 1;
-
-	for (ap = argptr; *ap ; ap++) {
-		if (flg_func)
-			ret |= unsetfunc(*ap);
-		if (flg_var)
-			ret |= unsetvar(*ap, flg_var == 'e');
-	}
-	return ret;
-}
-
-
-/*
- * Unset the specified variable.
- */
-
-int
-unsetvar(const char *s, int unexport)
-{
-	struct var **vpp;
-	struct var *vp;
-
-	vp = find_var(s, &vpp, NULL);
-	if (vp == NULL)
-		return 1;
-
-	if (vp->flags & VREADONLY)
-		return (1);
-
-	INTOFF;
-	if (unexport) {
-		vp->flags &= ~VEXPORT;
-	} else {
-		if (vp->text[vp->name_len + 1] != '\0')
-			setvar(s, nullstr, 0);
-		vp->flags &= ~VEXPORT;
-		vp->flags |= VUNSET;
-		if ((vp->flags & VSTRFIXED) == 0) {
-			if ((vp->flags & VTEXTFIXED) == 0)
-				ckfree(vp->text);
-			*vpp = vp->next;
-			ckfree(vp);
-		}
-	}
-	INTON;
-	return 0;
-}
-
-
-/*
- * Returns true if the two strings specify the same varable.  The first
- * variable name is terminated by '='; the second may be terminated by
- * either '=' or '\0'.
- */
-
-STATIC int
-strequal(const char *p, const char *q)
-{
-	while (*p == *q++) {
-		if (*p++ == '=')
-			return 1;
-	}
-	if (*p == '=' && *(q - 1) == '\0')
-		return 1;
-	return 0;
-}
-
-/*
- * Search for a variable.
- * 'name' may be terminated by '=' or a NUL.
- * vppp is set to the pointer to vp, or the list head if vp isn't found
- * lenp is set to the number of charactets in 'name'
- */
-
-STATIC struct var *
-find_var(const char *name, struct var ***vppp, int *lenp)
-{
-	unsigned int hashval;
-	int len;
-	struct var *vp, **vpp;
-	const char *p = name;
-
-	hashval = 0;
-	while (*p && *p != '=')
-		hashval = 2 * hashval + (unsigned char)*p++;
-	len = p - name;
-
-	if (lenp)
-		*lenp = len;
-	vpp = &vartab[hashval % VTABSIZE];
-	if (vppp)
-		*vppp = vpp;
-
-	for (vp = *vpp ; vp ; vpp = &vp->next, vp = *vpp) {
-		if (vp->name_len != len)
-			continue;
-		if (memcmp(vp->text, name, len) != 0)
-			continue;
-		if (vppp)
-			*vppp = vpp;
-		return vp;
-	}
-	return NULL;
-}
diff --git a/src/ash/var.h b/src/ash/var.h
deleted file mode 100644
index a803b9e..0000000
--- a/src/ash/var.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*	$NetBSD: var.h,v 1.23 2004/10/02 12:16:53 dsl Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * 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 the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)var.h	8.2 (Berkeley) 5/4/95
- */
-
-/*
- * Shell variables.
- */
-
-/* flags */
-#define VEXPORT		0x01	/* variable is exported */
-#define VREADONLY	0x02	/* variable cannot be modified */
-#define VSTRFIXED	0x04	/* variable struct is statically allocated */
-#define VTEXTFIXED	0x08	/* text is statically allocated */
-#define VSTACK		0x10	/* text is allocated on the stack */
-#define VUNSET		0x20	/* the variable is not set */
-#define VNOFUNC		0x40	/* don't call the callback function */
-#define VNOSET		0x80	/* do not set variable - just readonly test */
-#ifdef PC_OS2_LIBPATHS
-#define VOS2LIBPATH     0x8000  /* OS/2 LIBPATH related variable. */
-#endif
-
-
-struct var {
-	struct var *next;		/* next entry in hash list */
-	int flags;			/* flags are defined above */
-	char *text;			/* name=value */
-	int name_len;			/* length of name */
-	void (*func)(const char *);
-					/* function to be called when  */
-					/* the variable gets set/unset */
-};
-
-
-struct localvar {
-	struct localvar *next;		/* next local variable in list */
-	struct var *vp;			/* the variable that was made local */
-	int flags;			/* saved flags */
-	char *text;			/* saved text */
-};
-
-
-struct localvar *localvars;
-
-#if ATTY
-extern struct var vatty;
-#endif
-extern struct var vifs;
-extern struct var vmail;
-extern struct var vmpath;
-extern struct var vpath;
-#ifdef _MSC_VER
-extern struct var vpath2;
-#endif 
-extern struct var vps1;
-extern struct var vps2;
-extern struct var vps4;
-#ifndef SMALL
-extern struct var vterm;
-extern struct var vtermcap;
-extern struct var vhistsize;
-#endif
-
-/*
- * The following macros access the values of the above variables.
- * They have to skip over the name.  They return the null string
- * for unset variables.
- */
-
-#define ifsval()	(vifs.text + 4)
-#define ifsset()	((vifs.flags & VUNSET) == 0)
-#define mailval()	(vmail.text + 5)
-#define mpathval()	(vmpath.text + 9)
-#ifdef _MSC_VER
-#define pathval()	(vpath.text[5] ? &vpath.text[5] : &vpath2.text[5])
-#else
-#define pathval()	(vpath.text + 5)
-#endif
-#define ps1val()	(vps1.text + 4)
-#define ps2val()	(vps2.text + 4)
-#define ps4val()	(vps4.text + 4)
-#define optindval()	(voptind.text + 7)
-#ifndef SMALL
-#define histsizeval()	(vhistsize.text + 9)
-#define termval()	(vterm.text + 5)
-#endif
-
-#if ATTY
-#define attyset()	((vatty.flags & VUNSET) == 0)
-#endif
-#define mpathset()	((vmpath.flags & VUNSET) == 0)
-
-void initvar(void);
-void setvar(const char *, const char *, int);
-void setvareq(char *, int);
-struct strlist;
-void listsetvar(struct strlist *, int);
-char *lookupvar(const char *);
-char *bltinlookup(const char *, int);
-char **environment(void);
-void shprocvar(void);
-int showvars(const char *, int, int);
-int exportcmd(int, char **);
-int localcmd(int, char **);
-void mklocal(const char *, int);
-void listmklocal(struct strlist *, int);
-void poplocalvars(void);
-int setvarcmd(int, char **);
-int unsetcmd(int, char **);
-int unsetvar(const char *, int);
-int setvarsafe(const char *, const char *, int);
-void print_quoted(const char *);
diff --git a/src/ash/win/dirent.c b/src/ash/win/dirent.c
deleted file mode 100644
index aa3ece5..0000000
--- a/src/ash/win/dirent.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/* Directory entry code for Window platforms.
-Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-2006 Free Software Foundation, Inc.
-This file is part of GNU Make.
-
-GNU Make is free software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2, or (at your option) any later version.
-
-GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-GNU Make; see the file COPYING.  If not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "dirent.h"
-
-
-DIR*
-opendir(const char* pDirName)
-{
-	struct stat sb;
-	DIR*	pDir;
-	char*	pEndDirName;
-	int	nBufferLen;
-
-	/* sanity checks */
-	if (!pDirName) {
-		errno = EINVAL;
-		return NULL;
-	}
-	if (stat(pDirName, &sb) != 0) {
-		errno = ENOENT;
-		return NULL;
-	}
-	if ((sb.st_mode & S_IFMT) != S_IFDIR) {
-		errno = ENOTDIR;
-		return NULL;
-	}
-
-	/* allocate a DIR structure to return */
-	pDir = (DIR *) malloc(sizeof (DIR));
-
-	if (!pDir)
-		return NULL;
-
-	/* input directory name length */
-	nBufferLen = strlen(pDirName);
-
-	/* copy input directory name to DIR buffer */
-	strcpy(pDir->dir_pDirectoryName, pDirName);
-
-	/* point to end of the copied directory name */
-	pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1];
-
-	/* if directory name did not end in '/' or '\', add '/' */
-	if ((*pEndDirName != '/') && (*pEndDirName != '\\')) {
-		pEndDirName++;
-		*pEndDirName = '/';
-	}
-
-	/* now append the wildcard character to the buffer */
-	pEndDirName++;
-	*pEndDirName = '*';
-	pEndDirName++;
-	*pEndDirName = '\0';
-
-	/* other values defaulted */
-	pDir->dir_nNumFiles = 0;
-	pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
-	pDir->dir_ulCookie = __DIRENT_COOKIE;
-
-	return pDir;
-}
-
-void
-closedir(DIR *pDir)
-{
-	/* got a valid pointer? */
-	if (!pDir) {
-		errno = EINVAL;
-		return;
-	}
-
-	/* sanity check that this is a DIR pointer */
-	if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
-		errno = EINVAL;
-		return;
-	}
-
-	/* close the WINDOWS32 directory handle */
-	if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
-		FindClose(pDir->dir_hDirHandle);
-
-	free(pDir);
-
-	return;
-}
-
-struct dirent *
-readdir(DIR* pDir)
-{
-	WIN32_FIND_DATA wfdFindData;
-
-	if (!pDir) {
-		errno = EINVAL;
-		return NULL;
-	}
-
-	/* sanity check that this is a DIR pointer */
-	if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
-		errno = EINVAL;
-		return NULL;
-	}
-
-	if (pDir->dir_nNumFiles == 0) {
-		pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData);
-		if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE)
-			return NULL;
-	} else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData))
-			return NULL;
-
-	/* bump count for next call to readdir() or telldir() */
-	pDir->dir_nNumFiles++;
-
-	/* fill in struct dirent values */
-	pDir->dir_sdReturn.d_ino = -1;
-	strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName);
-
-	return &pDir->dir_sdReturn;
-}
-
-void
-rewinddir(DIR* pDir)
-{
-	if (!pDir) {
-		errno = EINVAL;
-		return;
-	}
-
-	/* sanity check that this is a DIR pointer */
-	if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
-		errno = EINVAL;
-		return;
-	}
-
-	/* close the WINDOWS32 directory handle */
-	if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
-		if (!FindClose(pDir->dir_hDirHandle))
-			errno = EBADF;
-
-	/* reset members which control readdir() */
-	pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
-	pDir->dir_nNumFiles = 0;
-
-	return;
-}
-
-int
-telldir(DIR* pDir)
-{
-	if (!pDir) {
-		errno = EINVAL;
-		return -1;
-	}
-
-	/* sanity check that this is a DIR pointer */
-	if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
-		errno = EINVAL;
-		return -1;
-	}
-
-	/* return number of times readdir() called */
-	return pDir->dir_nNumFiles;
-}
-
-void
-seekdir(DIR* pDir, long nPosition)
-{
-	if (!pDir)
-		return;
-
-	/* sanity check that this is a DIR pointer */
-	if (pDir->dir_ulCookie != __DIRENT_COOKIE)
-		return;
-
-	/* go back to beginning of directory */
-	rewinddir(pDir);
-
-	/* loop until we have found position we care about */
-	for (--nPosition; nPosition && readdir(pDir); nPosition--);
-
-	/* flag invalid nPosition value */
-	if (nPosition)
-		errno = EINVAL;
-
-	return;
-}
diff --git a/src/ash/win/err.c b/src/ash/win/err.c
deleted file mode 100644
index 5bbaa44..0000000
--- a/src/ash/win/err.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* $Id: err.c 2413 2010-09-11 17:43:04Z bird $ */
-/** @file
- *
- * Override err.h so we get the program name right.
- *
- * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with This program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include "err.h"
-
-
-/** The current program name. */
-const char *g_progname = "kmk";
-
-
-int err(int eval, const char *fmt, ...)
-{
-    va_list args;
-    int error = errno;
-    fprintf(stderr, "%s: ", g_progname);
-    va_start(args, fmt);
-    vfprintf(stderr, fmt, args);
-    va_end(args);
-    fprintf(stderr, ": %s\n", strerror(error));
-
-    return eval;
-}
-
-
-int errx(int eval, const char *fmt, ...)
-{
-    va_list args;
-    fprintf(stderr, "%s: ", g_progname);
-    va_start(args, fmt);
-    vfprintf(stderr, fmt, args);
-    va_end(args);
-    fprintf(stderr, "\n");
-
-    return eval;
-}
-
-void warn(const char *fmt, ...)
-{
-    int error = errno;
-    va_list args;
-    fprintf(stderr, "%s: ", g_progname);
-    va_start(args, fmt);
-    vfprintf(stderr, fmt, args);
-    va_end(args);
-    fprintf(stderr, ": %s\n", strerror(error));
-}
-
-void warnx(const char *fmt, ...)
-{
-    int err = errno;
-    va_list args;
-    fprintf(stderr, "%s: ", g_progname);
-    va_start(args, fmt);
-    vfprintf(stderr, fmt, args);
-    va_end(args);
-    fprintf(stderr, "\n");
-}
-
diff --git a/src/ash/win/err.h b/src/ash/win/err.h
deleted file mode 100644
index 1bd6945..0000000
--- a/src/ash/win/err.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* $Id: err.h 2413 2010-09-11 17:43:04Z bird $ */
-/** @file
- *
- * Override err.h stuff so we get the program names right.
- *
- * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with This program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-#ifndef __err_h__
-#define __err_h__
-
-extern const char *g_progname;
-int err(int eval, const char *fmt, ...);
-int errx(int eval, const char *fmt, ...);
-void warn(const char *fmt, ...);
-void warnx(const char *fmt, ...);
-
-#endif
-
diff --git a/src/ash/win/getopt.h b/src/ash/win/getopt.h
deleted file mode 100644
index 80efe96..0000000
--- a/src/ash/win/getopt.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Declarations for getopt.
-Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
-
-NOTE: The canonical source of this file is maintained with the GNU C Library.
-Bugs can be reported to bug-glibc at gnu.org.
-
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; see the file COPYING.  If not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
-
-#ifndef _GETOPT_H
-#define _GETOPT_H 1
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-/* For communication from `getopt' to the caller.
-   When `getopt' finds an option that takes an argument,
-   the argument value is returned here.
-   Also, when `ordering' is RETURN_IN_ORDER,
-   each non-option ARGV-element is returned here.  */
-
-extern char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
-   This is used for communication to and from the caller
-   and for communication between successive calls to `getopt'.
-
-   On entry to `getopt', zero means this is the first call; initialize.
-
-   When `getopt' returns -1, this is the index of the first of the
-   non-option elements that the caller should itself scan.
-
-   Otherwise, `optind' communicates from one call to the next
-   how much of ARGV has been scanned so far.  */
-
-extern int optind;
-
-/* Callers store zero here to inhibit the error message `getopt' prints
-   for unrecognized options.  */
-
-extern int opterr;
-
-/* Set to an option character which was unrecognized.  */
-
-extern int optopt;
-
-/* Describe the long-named options requested by the application.
-   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
-   of `struct option' terminated by an element containing a name which is
-   zero.
-
-   The field `has_arg' is:
-   no_argument		(or 0) if the option does not take an argument,
-   required_argument	(or 1) if the option requires an argument,
-   optional_argument 	(or 2) if the option takes an optional argument.
-
-   If the field `flag' is not NULL, it points to a variable that is set
-   to the value given in the field `val' when the option is found, but
-   left unchanged if the option is not found.
-
-   To have a long-named option do something other than set an `int' to
-   a compiled-in constant, such as set a value from `optarg', set the
-   option's `flag' field to zero and its `val' field to a nonzero
-   value (the equivalent single-letter option character, if there is
-   one).  For long options that have a zero `flag' field, `getopt'
-   returns the contents of the `val' field.  */
-
-struct option
-{
-#if defined (__STDC__) && __STDC__
-  const char *name;
-#else
-  char *name;
-#endif
-  /* has_arg can't be an enum because some compilers complain about
-     type mismatches in all the code that assumes it is an int.  */
-  int has_arg;
-  int *flag;
-  int val;
-};
-
-/* Names for the values of the `has_arg' field of `struct option'.  */
-
-#define	no_argument		0
-#define required_argument	1
-#define optional_argument	2
-
-#if defined (__STDC__) && __STDC__
-#ifdef __GNU_LIBRARY__
-/* Many other libraries have conflicting prototypes for getopt, with
-   differences in the consts, in stdlib.h.  To avoid compilation
-   errors, only prototype getopt for the GNU C library.  */
-extern int getopt (int argc, char *const *argv, const char *shortopts);
-#else /* not __GNU_LIBRARY__ */
-extern int getopt ();
-#endif /* __GNU_LIBRARY__ */
-extern int getopt_long (int argc, char *const *argv, const char *shortopts,
-		        const struct option *longopts, int *longind);
-extern int getopt_long_only (int argc, char *const *argv,
-			     const char *shortopts,
-		             const struct option *longopts, int *longind);
-
-/* Internal only.  Users should not call this directly.  */
-extern int _getopt_internal (int argc, char *const *argv,
-			     const char *shortopts,
-		             const struct option *longopts, int *longind,
-			     int long_only);
-#else /* not __STDC__ */
-extern int getopt ();
-extern int getopt_long ();
-extern int getopt_long_only ();
-
-extern int _getopt_internal ();
-#endif /* __STDC__ */
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif /* getopt.h */
diff --git a/src/ash/win/mscfakes.c b/src/ash/win/mscfakes.c
deleted file mode 100644
index a20d130..0000000
--- a/src/ash/win/mscfakes.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/* $Id: mscfakes.c 2413 2010-09-11 17:43:04Z bird $ */
-/** @file
- *
- * Fake Unix stuff for MSC.
- *
- * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with This program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <io.h>
-#include <fcntl.h>
-#include <sys/times.h>
-#include "err.h"
-#include "mscfakes.h"
-#undef mkdir
-
-
-int optind = 1;
-
-
-char *dirname(char *path)
-{
-    /** @todo later */
-    return path;
-}
-
-
-int link(const char *pszDst, const char *pszLink)
-{
-    errno = ENOSYS;
-    err(1, "link() is not implemented on windows!");
-    return -1;
-}
-
-
-int mkdir_msc(const char *path, mode_t mode)
-{
-    int rc = mkdir(path);
-    if (rc)
-    {
-        int len = strlen(path);
-        if (len > 0 && (path[len - 1] == '/' || path[len - 1] == '\\'))
-        {
-            char *str = strdup(path);
-            while (len > 0 && (str[len - 1] == '/' || str[len - 1] == '\\'))
-                str[--len] = '\0';
-            rc = mkdir(str);
-            free(str);
-        }
-    }
-    return rc;
-}
-
-
-static int doname(char *pszX, char *pszEnd)
-{
-    static char s_szChars[] = "Xabcdefghijklmnopqrstuwvxyz1234567890";
-    int rc = 0;
-    do
-    {
-        char ch;
-
-        pszEnd++;
-        ch = *(strchr(s_szChars, *pszEnd) + 1);
-        if (ch)
-        {
-            *pszEnd = ch;
-            return 0;
-        }
-        *pszEnd = 'a';
-    } while (pszEnd != pszX);
-    return 1;
-}
-
-
-int mkstemp(char *temp)
-{
-    char *pszX = strchr(temp, 'X');
-    char *pszEnd = strchr(pszX, '\0');
-    int cTries = 1000;
-    while (--cTries > 0)
-    {
-        int fd;
-        if (doname(pszX, pszEnd))
-            return -1;
-        fd = open(temp, _O_EXCL | _O_CREAT | _O_BINARY | _O_RDWR, 0777);
-        if (fd >= 0)
-            return fd;
-    }
-    return -1;
-}
-
-
-int symlink(const char *pszDst, const char *pszLink)
-{
-    errno = ENOSYS;
-    err(1, "symlink() is not implemented on windows!");
-    return -1;
-}
-
-
-#if _MSC_VER < 1400
-int snprintf(char *buf, size_t size, const char *fmt, ...)
-{
-    int cch;
-    va_list args;
-    va_start(args, fmt);
-    cch = vsprintf(buf, fmt, args);
-    va_end(args);
-    return cch;
-}
-#endif
-
-
-int utimes(const char *pszPath, const struct timeval *paTimes)
-{
-    /** @todo implement me! */
-    return 0;
-}
-
-
-int writev(int fd, const struct iovec *vector, int count)
-{
-    int size = 0;
-    int i;
-    for (i = 0; i < count; i++)
-    {
-        int cb = write(fd, vector[i].iov_base, vector[i].iov_len);
-        if (cb < 0)
-            return -1;
-        size += cb;
-    }
-    return size;
-}
-
-
-int fcntl(int fd, int iCmd, ...)
-{
-    fprintf(stderr, "fcntl(%d, %d,..)\n", fd, iCmd);
-    return 0;
-}
-
-int ioctl(int fd, unsigned long iCmd, ...)
-{
-    fprintf(stderr, "ioctl(%d, %d,..)\n", fd, iCmd);
-    return 0;
-}
-
-int tcsetpgrp(int fd, pid_t pgrp)
-{
-    fprintf(stderr, "tcgetpgrp(%d, %d)\n", fd, pgrp);
-    return 0;
-}
-
-pid_t tcgetpgrp(int fd)
-{
-    fprintf(stderr, "tcgetpgrp(%d)\n", fd);
-    return 0;
-}
-
-pid_t getpgrp(void)
-{
-    fprintf(stderr, "getpgrp\n");
-    return _getpid();
-}
-
-uid_t getuid(void)
-{
-    fprintf(stderr, "getuid\n");
-    return 0;
-}
-
-gid_t getgid(void)
-{
-    fprintf(stderr, "getgid\n");
-    return 0;
-}
-
-gid_t getegid(void)
-{
-    fprintf(stderr, "getegid\n");
-    return 0;
-}
-
-int setpgid(pid_t pid, pid_t pgid)
-{
-    fprintf(stderr, "setpgid(%d,%d)\n", pid, pgid);
-    return 0;
-}
-
-pid_t getpgid(pid_t pid)
-{
-    fprintf(stderr, "getpgid(%d)\n", pid);
-    return 0;
-}
-
-long sysconf(int name)
-{
-    fprintf(stderr, "sysconf(%d)\n", name);
-    return 0;
-}
-
-clock_t times(struct tms *pBuf)
-{
-    struct timeval tv = {0};
-    if (pBuf)
-    {
-        pBuf->tms_utime = clock();  /* clock () * HZ / CLOCKS_PER_SEC */
-        pBuf->tms_stime = pBuf->tms_cutime = pBuf->tms_cstime = 0;
-    }
-/*
-    gettimeofday(&tv, NULL); */
-    fprintf(stderr, "times(%p)\n", pBuf);
-    return CLK_TCK * tv.tv_sec + (CLK_TCK * tv.tv_usec) / 1000000;
-}
-
-struct passwd *getpwnam(const char *pszName)
-{
-    printf("getpwnam(%s)\n",  pszName);
-    return NULL;
-}
-
-int setrlimit(int iResId, const struct rlimit *pLimit)
-{
-    printf("setrlimit(%d,  %p)\n", iResId, pLimit);
-    return -1;
-}
-
-int getrlimit(int iResId, struct rlimit *pLimit)
-{
-    printf("getrlimit(%d,  %p)\n", iResId, pLimit);
-    return -1;
-}
-
-
-pid_t fork(void)
-{
-    fprintf(stderr, "fork()\n");
-    return -1;
-}
-
-pid_t wait3(int *piStatus, int fOptions, struct rusage *pRUsage)
-{
-    fprintf(stderr, "wait3()\n");
-    return -1;
-}
-
-
-/* signal stuff */
-
-int	sigprocmask(int iOperation, const sigset_t *pNew, sigset_t *pOld)
-{
-    fprintf(stderr, "sigprocmask(%d, %p, %p)\n", iOperation, pNew, pOld);
-    return 0;
-}
-
-int	sigemptyset(sigset_t *pSet)
-{
-    pSet->__bitmap[0] = 0;
-    return 0;
-}
-
-int siginterrupt(int iSignalNo, int fFlag)
-{
-    fprintf(stderr, "siginterrupt(%d, %#x)\n", iSignalNo, fFlag);
-    return 0;
-}
-
-int sigaction(int iSignalNo, const struct sigaction *pSigAct, struct sigaction *pSigActOld)
-{
-    fprintf(stderr, "sigaction(%d, %p, %p)\n", iSignalNo, pSigAct, pSigActOld);
-    return 0;
-}
-
-int kill(pid_t pid, int iSignalNo)
-{
-    fprintf(stderr, "kill(%d, %d)\n", pid, iSignalNo);
-    return 0;
-}
-
-int killpg(pid_t pgrp, int iSignalNo)
-{
-    if (pgrp < 0)
-    {
-        errno = EINVAL;
-        return -1;
-    }
-    return kill(-pgrp, iSignalNo);
-}
-
-const char * const  sys_siglist[NSIG] =
-{
-    "0",
-    "1",
-    "2",
-    "3",
-    "4",
-    "5",
-    "6",
-    "7",
-    "8",
-    "9",
-    "10",
-    "11",
-    "12",
-    "13",
-    "14",
-    "15",
-    "16",
-    "17",
-    "18",
-    "19",
-    "20",
-    "21",
-    "22"
-};
-
-
-/* */
diff --git a/src/ash/win/mscfakes.h b/src/ash/win/mscfakes.h
deleted file mode 100644
index bcb3081..0000000
--- a/src/ash/win/mscfakes.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/* $Id: mscfakes.h 2413 2010-09-11 17:43:04Z bird $ */
-/** @file
- *
- * Unix fakes for MSC.
- *
- * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with This program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-#ifndef __mscfakes_h__
-#define __mscfakes_h__
-#ifdef _MSC_VER
-
-#define setmode setmode_msc
-#include <sys/cdefs.h>
-#include <io.h>
-#include <direct.h>
-#include <time.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <process.h>
-#undef setmode
-//#include "getopt.h"
-
-#if !defined(__GNUC__) && !defined(__attribute__)
-#define __attribute__(a)
-#endif
-
-#define S_ISDIR(m)  (((m) & _S_IFMT) == _S_IFDIR)
-#define S_ISREG(m)  (((m) & _S_IFMT) == _S_IFREG)
-#define S_ISLNK(m)  0
-#define	S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
-#define	S_IXUSR _S_IEXEC
-#define	S_IWUSR _S_IWRITE
-#define	S_IRUSR _S_IREAD
-#define S_IRWXG 0000070
-#define S_IRGRP	0000040
-#define S_IWGRP	0000020
-#define S_IXGRP 0000010
-#define S_IRWXO 0000007
-#define S_IROTH	0000004
-#define S_IWOTH	0000002
-#define S_IXOTH 0000001
-#define	S_ISUID 0004000
-#define	S_ISGID 0002000
-#define ALLPERMS 0000777
-
-#define PATH_MAX _MAX_PATH
-#define MAXPATHLEN _MAX_PATH
-
-#define EX_OK 0
-#define EX_OSERR 1
-#define EX_NOUSER 1
-#define EX_USAGE 1
-
-#define STDIN_FILENO 0
-#define STDOUT_FILENO 1
-#define STDERR_FILENO 2
-
-#define F_OK 0
-#define X_OK 1
-#define W_OK 2
-#define R_OK 4
-
-#define EFTYPE EINVAL
-
-#define _PATH_DEVNULL "/dev/null"
-
-#define MAX(a,b) ((a) >= (b) ? (a) : (b))
-
-typedef int mode_t;
-typedef unsigned short nlink_t;
-typedef long ssize_t;
-typedef unsigned long u_long;
-typedef unsigned int u_int;
-typedef unsigned short u_short;
-
-#ifndef timerisset
-struct timeval
-{
-    long tv_sec;
-    long tv_usec;
-};
-#endif
-
-struct iovec
-{
-    char *iov_base;
-    size_t iov_len;
-};
-
-
-#define chown(path, uid, gid) 0         /** @todo implement fchmod! */
-char *dirname(char *path);
-#define fsync(fd)  0
-#define fchown(fd,uid,gid) 0
-#define fchmod(fd, mode) 0              /** @todo implement fchmod! */
-#define geteuid()  0
-#define lstat(path, s) stat(path, s)
-#define lchmod(path, mod) chmod(path, mod)
-#define lchown(path, uid, gid) chown(path, uid, gid)
-#define lutimes(path, tvs) utimes(path, tvs)
-int link(const char *pszDst, const char *pszLink);
-int mkdir_msc(const char *path, mode_t mode);
-#define mkdir(path, mode) mkdir_msc(path, mode)
-#define mkfifo(path, mode) -1
-#define mknod(path, mode, devno) -1
-#define pipe(v) _pipe(v,0,0)
-int mkstemp(char *temp);
-#define readlink(link, buf, size) -1
-#define reallocf(old, size) realloc(old, size)
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#if _MSC_VER < 1400
-int snprintf(char *buf, size_t size, const char *fmt, ...);
-#else
-#define snprintf _snprintf
-#endif
-size_t strlcpy(char *, const char *, size_t);
-int symlink(const char *pszDst, const char *pszLink);
-int utimes(const char *pszPath, const struct timeval *paTimes);
-int writev(int fd, const struct iovec *vector, int count);
-#define	F_DUPFD	0
-#define F_GETFD 1
-#define F_SETFD 2
-#define F_GETFL 3
-#define F_SETFL 4
-#define	FD_CLOEXEC 1
-#define O_NONBLOCK 0 /// @todo
-#define EWOULDBLOCK 512
-int fcntl(int, int, ...);
-int ioctl(int, unsigned long, ...);
-pid_t tcgetpgrp(int fd);
-
-
-/* signal hacks */
-#include <signal.h>
-typedef struct sigset
-{
-    unsigned long __bitmap[1];
-} sigset_t;
-typedef void __sighandler_t(int);
-typedef	void __siginfohandler_t(int, struct __siginfo *, void *);
-typedef __sighandler_t *sig_t; /** BSD 4.4 type. */
-struct sigaction
-{
-    union
-    {
-        __siginfohandler_t *__sa_sigaction;
-        __sighandler_t     *__sa_handler;
-    }  __sigaction_u;
-    sigset_t    sa_mask;
-    int         sa_flags;
-};
-#define sa_handler      __sigaction_u.__sa_handler
-#define sa_sigaction    __sigaction_u.__sa_sigaction
-
-int	sigprocmask(int, const sigset_t *, sigset_t *);
-#define SIG_BLOCK           1
-#define SIG_UNBLOCK         2
-#define SIG_SETMASK         3
-
-#define SIGTTIN 19
-#define SIGTSTP 18
-#define SIGTTOU 17
-#define SIGCONT 20
-#define SIGPIPE 12
-#define SIGQUIT 9
-#define SIGHUP  5
-
-extern const char *const sys_siglist[NSIG]; /* NSIG == 23 */
-
-int	kill(pid_t, int);
-int	sigaction(int, const struct sigaction *, struct sigaction *);
-//int	sigaddset(sigset_t *, int);
-//int	sigdelset(sigset_t *, int);
-int	sigemptyset(sigset_t *);
-//int	sigfillset(sigset_t *);
-//int	sigismember(const sigset_t *, int);
-//int	sigpending(sigset_t *);
-//int	sigsuspend(const sigset_t *);
-//int	sigwait(const sigset_t *, int *);
-int	siginterrupt(int, int);
-
-#endif /* _MSC_VER */
-#endif
-
diff --git a/src/ash/win/paths.h b/src/ash/win/paths.h
deleted file mode 100644
index b4538a4..0000000
--- a/src/ash/win/paths.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "mscfakes.h"
-#define _PATH_DEFPATH ""
diff --git a/src/ash/win/pwd.h b/src/ash/win/pwd.h
deleted file mode 100644
index e4bb926..0000000
--- a/src/ash/win/pwd.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __pwd_h__
-#define __pwd_h__
-#include <time.h>
-
-struct passwd {
-	char	*pw_name;		/* user name */
-	char	*pw_passwd;		/* encrypted password */
-	int	pw_uid;			/* user uid */
-	int	pw_gid;			/* user gid */
-	time_t	pw_change;		/* password change time */
-	char	*pw_class;		/* user access class */
-	char	*pw_gecos;		/* Honeywell login info */
-	char	*pw_dir;		/* home directory */
-	char	*pw_shell;		/* default shell */
-	time_t	pw_expire;		/* account expiration */
-	int	pw_fields;		/* internal: fields filled in */
-};
-
-struct passwd	*getpwnam(const char *);
-struct passwd	*getpwuid(int);
-
-
-#endif
diff --git a/src/ash/win/strings.h b/src/ash/win/strings.h
deleted file mode 100644
index 6e70388..0000000
--- a/src/ash/win/strings.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#include <string.h>
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#define index(str, ch) strchr((str), (ch))
diff --git a/src/ash/win/sys/cdefs.h b/src/ash/win/sys/cdefs.h
deleted file mode 100644
index 72be664..0000000
--- a/src/ash/win/sys/cdefs.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef __sys_cdefs_h__
-#define __sys_cdefs_h__
-
-#define __attribute__(a)
-typedef int pid_t;
-typedef unsigned short uid_t;
-typedef unsigned short gid_t;
-
-#endif
diff --git a/src/ash/win/sys/fcntl.h b/src/ash/win/sys/fcntl.h
deleted file mode 100644
index 53220f4..0000000
--- a/src/ash/win/sys/fcntl.h
+++ /dev/null
@@ -1 +0,0 @@
-#include "../mscfakes.h"
diff --git a/src/ash/win/sys/ioctl.h b/src/ash/win/sys/ioctl.h
deleted file mode 100644
index 79a9626..0000000
--- a/src/ash/win/sys/ioctl.h
+++ /dev/null
@@ -1 +0,0 @@
-/* */
diff --git a/src/ash/win/sys/param.h b/src/ash/win/sys/param.h
deleted file mode 100644
index 80be80e..0000000
--- a/src/ash/win/sys/param.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#include <limits.h>
-
diff --git a/src/ash/win/sys/resource.h b/src/ash/win/sys/resource.h
deleted file mode 100644
index 050f7e5..0000000
--- a/src/ash/win/sys/resource.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (c) 1982, 1986, 1993
- *	The Regents of the University of California.  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.
- * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
- *
- *	@(#)resource.h	8.4 (Berkeley) 1/9/95
- * $FreeBSD: src/sys/sys/resource.h,v 1.23 2004/06/13 22:07:58 das Exp $
- */
-
-/** @file
- * FreeBSD 5.3
- * @changed bird: get/setpriority takes id_t not int according to SuS.
- * @changed bird: include sys/types.h to get id_t.
- */
-
-#ifndef _SYS_RESOURCE_H_
-#define	_SYS_RESOURCE_H_
-
-#include <sys/cdefs.h>
-#include "mscfakes.h"
-
-
-/*
- * Process priority specifications to get/setpriority.
- */
-#define	PRIO_MIN	-20
-#define	PRIO_MAX	20
-
-#define	PRIO_PROCESS	0
-#define	PRIO_PGRP	1
-#define	PRIO_USER	2
-
-/*
- * Resource utilization information.
- */
-
-#define	RUSAGE_SELF	0
-#define	RUSAGE_CHILDREN	-1
-
-struct rusage {
-	struct timeval ru_utime;	/* user time used */
-	struct timeval ru_stime;	/* system time used */
-	long	ru_maxrss;		/* max resident set size */
-#define	ru_first	ru_ixrss
-	long	ru_ixrss;		/* integral shared memory size */
-	long	ru_idrss;		/* integral unshared data " */
-	long	ru_isrss;		/* integral unshared stack " */
-	long	ru_minflt;		/* page reclaims */
-	long	ru_majflt;		/* page faults */
-	long	ru_nswap;		/* swaps */
-	long	ru_inblock;		/* block input operations */
-	long	ru_oublock;		/* block output operations */
-	long	ru_msgsnd;		/* messages sent */
-	long	ru_msgrcv;		/* messages received */
-	long	ru_nsignals;		/* signals received */
-	long	ru_nvcsw;		/* voluntary context switches */
-	long	ru_nivcsw;		/* involuntary " */
-#define	ru_last		ru_nivcsw
-};
-
-/*
- * Resource limits
- */
-#define	RLIMIT_CPU	0		/* cpu time in milliseconds */
-#define	RLIMIT_FSIZE	1		/* maximum file size */
-#define	RLIMIT_DATA	2		/* data size */
-#define	RLIMIT_STACK	3		/* stack size */
-#define	RLIMIT_CORE	4		/* core file size */
-#define	RLIMIT_RSS	5		/* resident set size */
-#define	RLIMIT_MEMLOCK	6		/* locked-in-memory address space */
-#define	RLIMIT_NPROC	7		/* number of processes */
-#define	RLIMIT_NOFILE	8		/* number of open files */
-#define	RLIMIT_SBSIZE	9		/* maximum size of all socket buffers */
-#define RLIMIT_VMEM	10		/* virtual process size (inclusive of mmap) */
-#define	RLIMIT_AS	RLIMIT_VMEM	/* standard name for RLIMIT_VMEM */
-#define RLIMIT_OBJREST  11		/* bird: size left in the top heap object. kLIBC specific. */
-
-#define	RLIM_NLIMITS	12		/* number of resource limits */ /* bird: was 11 */
-
-#define	RLIM_INFINITY	(((rlim_t)1 << 63) - 1)
-/* XXX Missing: RLIM_SAVED_MAX, RLIM_SAVED_CUR */
-
-
-/*
- * Resource limit string identifiers
- */
-
-#ifdef _RLIMIT_IDENT
-static char *rlimit_ident[] = {
-	"cpu",
-	"fsize",
-	"data",
-	"stack",
-	"core",
-	"rss",
-	"memlock",
-	"nproc",
-	"nofile",
-	"sbsize",
-	"vmem",
-};
-#endif
-
-typedef	__int64	rlim_t;
-
-struct rlimit {
-	rlim_t	rlim_cur;		/* current (soft) limit */
-	rlim_t	rlim_max;		/* maximum value for rlim_cur */
-};
-
-
-/* XXX 2nd arg to [gs]etpriority() should be an id_t */
-//int	getpriority(int, /*int*/ id_t);         /* bird: SuS uses id_t */
-//int	getrlimit(int, struct rlimit *);
-int	getrusage(int, struct rusage *);
-//int	setpriority(int, /*int*/ id_t, int);    /* bird: SuS uses id_t */
-int	setrlimit(int, const struct rlimit *);
-
-#endif	/* !_SYS_RESOURCE_H_ */
-
diff --git a/src/ash/win/sys/time.h b/src/ash/win/sys/time.h
deleted file mode 100644
index 91fd187..0000000
--- a/src/ash/win/sys/time.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <time.h>
diff --git a/src/ash/win/sys/times.h b/src/ash/win/sys/times.h
deleted file mode 100644
index 68ce11d..0000000
--- a/src/ash/win/sys/times.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef __sys_times_h__
-#define __sys_times_h__
-#include <time.h>
-
-struct tms
-{
-    clock_t tms_utime;      /**< User mode CPU time. */
-    clock_t tms_stime;      /**< Kernel mode CPU time. */
-    clock_t tms_cutime;     /**< User mode CPU time for waited for children. */
-    clock_t tms_cstime;     /**< Kernel mode CPU time for waited for children. */
-};
-
-clock_t times(struct tms *);
-
-#endif 
diff --git a/src/ash/win/sys/wait.h b/src/ash/win/sys/wait.h
deleted file mode 100644
index 8c644d5..0000000
--- a/src/ash/win/sys/wait.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef __sys_wait_h__
-#define __sys_wait_h__
-
-#include "mscfakes.h"
-
-#define	WNOHANG		1	/* Don't hang in wait. */
-#define	WUNTRACED	2	/* Tell about stopped, untraced children. */
-#define	WCONTINUED	4	/* Report a job control continued process. */
-#define	_W_INT(w)	(*(int *)&(w))	/* Convert union wait to int. */
-#define	WCOREFLAG	0200
-
-#define	_WSTATUS(x)	(_W_INT(x) & 0177)
-#define	_WSTOPPED	0177		/* _WSTATUS if process is stopped */
-#define	WIFSTOPPED(x)	(_WSTATUS(x) == _WSTOPPED)
-#define	WSTOPSIG(x)	(_W_INT(x) >> 8)
-#define	WIFSIGNALED(x)	(_WSTATUS(x) != 0 && !WIFSTOPPED(x) && !WIFCONTINUED(x)) /* bird: made GLIBC tests happy. */
-#define	WTERMSIG(x)	(_WSTATUS(x))
-#define	WIFEXITED(x)	(_WSTATUS(x) == 0)
-#define	WEXITSTATUS(x)	(_W_INT(x) >> 8)
-#define	WIFCONTINUED(x)	(x == 0x13)	/* 0x13 == SIGCONT */
-#define	WCOREDUMP(x)	(_W_INT(x) & WCOREFLAG)
-#define	W_EXITCODE(ret, sig)	((ret) << 8 | (sig))
-#define	W_STOPCODE(sig)		((sig) << 8 | _WSTOPPED)
-
-#endif 
diff --git a/src/ash/win/termios.h b/src/ash/win/termios.h
deleted file mode 100644
index 79a9626..0000000
--- a/src/ash/win/termios.h
+++ /dev/null
@@ -1 +0,0 @@
-/* */
diff --git a/src/ash/win/unistd.h b/src/ash/win/unistd.h
deleted file mode 100644
index c725c42..0000000
--- a/src/ash/win/unistd.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "mscfakes.h"
-#include "getopt.h"
-#include "process.h"
-
-#define _SC_CLK_TCK 0x101
-long _sysconf(int);
-pid_t fork(void);
-pid_t getpid(void);
-
diff --git a/src/kmk/Makefile.am b/src/kmk/Makefile.am
index e588fb6..99a9a6a 100644
--- a/src/kmk/Makefile.am
+++ b/src/kmk/Makefile.am
@@ -52,7 +52,7 @@ kmk_SOURCES =	ar.c arscan.c commands.c default.c dir.c expand.c file.c \
 		strcache2.c \
 		alloccache.c \
 		kbuild.c \
-		kbuild-read.c \
+		kbuild-object.c \
 		electric.c \
 		../lib/md5.c \
 		../lib/kDep.c \
diff --git a/src/kmk/Makefile.kmk b/src/kmk/Makefile.kmk
index 84c6e9f..7b7e11c 100644
--- a/src/kmk/Makefile.kmk
+++ b/src/kmk/Makefile.kmk
@@ -1,4 +1,4 @@
-# $Id: Makefile.kmk 2667 2012-11-25 19:52:26Z bird $
+# $Id: Makefile.kmk 2719 2014-01-01 17:40:56Z bird $
 ## @file
 # Sub-makefile for kmk / GNU Make.
 #
@@ -129,7 +129,6 @@ kmkmissing_SOURCES.win += \
 	w32/subproc/misc.c \
 	w32/subproc/sub_proc.c \
 	w32/subproc/w32err.c \
-	w32/compat/dirent.c \
 	w32/pathstuff.c \
 	w32/imagecache.c
 
@@ -205,7 +204,7 @@ kmk_DEFS.debug = CONFIG_WITH_MAKE_STATS
 kmk_SOURCES = \
 	main.c \
 	kbuild.c \
-	kbuild-read.c \
+	kbuild-object.c \
 	read.c \
 	expreval.c \
 	incdep.c \
diff --git a/src/kmk/config.h.win b/src/kmk/config.h.win
index 394dcc8..4cb172a 100644
--- a/src/kmk/config.h.win
+++ b/src/kmk/config.h.win
@@ -272,7 +272,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
 /* #undef HAVE_SYS_RESOURCE_H */
 
 /* Define to 1 if you have the <sys/stat.h> header file. */
-/* #define HAVE_SYS_STAT_H 1 */
+#define HAVE_SYS_STAT_H 1
 
 /* Define to 1 if you have the <sys/timeb.h> header file. */
 /*#define HAVE_SYS_TIMEB_H 1*/
@@ -383,7 +383,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
 #define STDC_HEADERS 1
 
 /* Define if struct stat contains a nanoseconds field */
-/* #undef ST_MTIM_NSEC */
+#define ST_MTIM_NSEC tv_nsec
 
 /* Define to 1 on System V Release 4. */
 /* #undef SVR4 */
@@ -522,16 +522,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
 #undef BATCH_MODE_ONLY_SHELL
 #endif
 
-/* bird hacks - similar in mscfakes.h */
-#include <sys/stat.h>
+/* bird stat hacks. */
 #include <io.h>
 #include <direct.h>
-#ifndef STAT_REDEFINED_ALREADY
-# define STAT_REDEFINED_ALREADY
-# undef stat
-# define stat(_path, _st) bird_w32_stat(_path, _st)
-extern int bird_w32_stat(const char *, struct stat *);
-#endif
+#include "nt/ntstat.h"
+
+/* bird dirent hack. */
+#define _DIRENT_H /* see w32/dirent.h */
+#include "nt/ntdir.h"
+#define _DIRENT_HAVE_D_NAMLEN 1
+#define _DIRENT_HAVE_D_TYPE   1
+
 
 /* cygwin sucks to much in one end or the other. */
 #define BATCH_MODE_ONLY_SHELL
diff --git a/src/kmk/dir.c b/src/kmk/dir.c
index fae0a7b..4fffe62 100644
--- a/src/kmk/dir.c
+++ b/src/kmk/dir.c
@@ -119,6 +119,7 @@ dosify (const char *filename)
 #endif /* __MSDOS__ */
 
 #ifdef WINDOWS32
+#include <Windows.h>
 #include "pathstuff.h"
 #endif
 
@@ -241,6 +242,9 @@ struct directory_contents
 # define FS_FAT      0x1
 # define FS_NTFS     0x2
 # define FS_UNKNOWN  0x4
+# ifdef KMK
+    time_t last_updated; /**< The last time the directory was re-read. */
+# endif
 #else
 # ifdef VMS
     ino_t ino[3];
@@ -607,6 +611,9 @@ find_directory (const char *name)
 
 	      dc->ctime = st.st_ctime;
               dc->mtime = st.st_mtime;
+# ifdef KMK
+              dc->last_updated = time(NULL);
+# endif
 
               /*
                * NTFS is the only WINDOWS32 filesystem that bumps mtime
@@ -686,9 +693,14 @@ dir_contents_file_exists_p (struct directory_contents *dir,
   struct dirfile *df;
   struct dirent *d;
 #ifdef WINDOWS32
+# ifndef KMK
   struct stat st;
+# endif
   int rehash = 0;
 #endif
+#ifdef KMK
+  int ret = 0;
+#endif
 
   if (dir == 0 || dir->dirfiles.ht_vec == 0)
     /* The directory could not be stat'd or opened.  */
@@ -740,26 +752,36 @@ dir_contents_file_exists_p (struct directory_contents *dir,
 
   if (dir->dirstream == 0)
     {
-#ifdef WINDOWS32
+#if defined(WINDOWS32) && !defined(KMK)
       /*
        * Check to see if directory has changed since last read. FAT
        * filesystems force a rehash always as mtime does not change
        * on directories (ugh!).
        */
+# ifdef KMK
+      if (dir->path_key && time(NULL) > dc->last_updated + 2) /* KMK: Only recheck every 2 seconds. */
+# else
       if (dir->path_key)
+# endif
 	{
           if ((dir->fs_flags & FS_FAT) != 0)
 	    {
 	      dir->mtime = time ((time_t *) 0);
 	      rehash = 1;
 	    }
+# ifdef KMK
+	  else if (   birdStatModTimeOnly (dir->path_key, &st.st_mtim, 1) == 0
+                   && st.st_mtime > dir->mtime)
+# else
 	  else if (stat (dir->path_key, &st) == 0 && st.st_mtime > dir->mtime)
+# endif
 	    {
 	      /* reset date stamp to show most recent re-process.  */
 	      dir->mtime = st.st_mtime;
 	      rehash = 1;
 	    }
 
+
           /* If it has been already read in, all done.  */
 	  if (!rehash)
 	    return 0;
@@ -768,6 +790,9 @@ dir_contents_file_exists_p (struct directory_contents *dir,
           dir->dirstream = opendir (dir->path_key);
           if (!dir->dirstream)
             return 0;
+# ifdef KMK
+          dc->last_updated = time(NULL);
+# endif
 	}
       else
 #endif
@@ -867,7 +892,11 @@ dir_contents_file_exists_p (struct directory_contents *dir,
 #else
       if (filename != 0 && dirfile_key.name == filename)
 #endif
+#ifdef KMK
+        ret = 1; /* Cache the whole dir. Prevents trouble on windows and os2 during 'rebuild'. */
+#else
         return 1;
+#endif
     }
 
   /* If the directory has been completely read in,
@@ -878,7 +907,11 @@ dir_contents_file_exists_p (struct directory_contents *dir,
       closedir (dir->dirstream);
       dir->dirstream = 0;
     }
+#ifdef KMK
+  return ret;
+#else
   return 0;
+#endif
 }
 
 /* Return 1 if the name FILENAME in directory DIRNAME
@@ -1389,6 +1422,19 @@ local_stat (const char *path, struct stat *buf)
 }
 #endif
 
+#ifdef KMK
+static int dir_exists_p (const char *dirname)
+{
+  if (file_exists_p (dirname))
+    {
+      struct directory *dir = find_directory (dirname);
+      if (dir != NULL && dir->contents && dir->contents->dirfiles.ht_vec != NULL)
+        return 1;
+    }
+  return 0;
+}
+#endif
+
 void
 dir_setup_glob (glob_t *gl)
 {
@@ -1399,6 +1445,10 @@ dir_setup_glob (glob_t *gl)
 #ifdef __EMX__ /* The FreeBSD implementation actually uses gl_lstat!! */
   gl->gl_lstat = local_stat;
 #endif
+#ifdef KMK
+  gl->gl_exists = file_exists_p;
+  gl->gl_isdir = dir_exists_p;
+#endif
   /* We don't bother setting gl_lstat, since glob never calls it.
      The slot is only there for compatibility with 4.4 BSD.  */
 }
@@ -1425,3 +1475,4 @@ hash_init_directories (void)
                    "dirfile", NULL, NULL);
 #endif /* CONFIG_WITH_ALLOC_CACHES */
 }
+
diff --git a/src/kmk/function.c b/src/kmk/function.c
index 2af48c6..68409f7 100644
--- a/src/kmk/function.c
+++ b/src/kmk/function.c
@@ -2854,38 +2854,51 @@ func_substr (char *o, char **argv, const char *funcname UNUSED)
             }
         }
       length = math_int_from_string (argv[2]);
-      if (length < 0 || (pad != NULL && length > 16*1024*1024 /* 16MB */))
-        fatal (NILF, _("$(substr ): length=%s is out of bounds\n"), argv[3]);
+      if (pad != NULL && length > 16*1024*1024 /* 16MB */)
+        fatal (NILF, _("$(substr ): length=%s is out of bounds\n"), argv[2]);
+      if (pad != NULL && length < 0)
+        fatal (NILF, _("$(substr ): negative length (%s) and padding doesn't mix.\n"), argv[2]);
       if (length == 0)
         return o;
     }
 
-  /* adjust start and length. */
+  /* Note that negative start is and length are used for referencing from the
+     end of the string. */
   if (pad == NULL)
     {
       if (start > 0)
-        {
-          start--;      /* one-origin */
-          if (start >= str_len)
-            return o;
-          if (length == 0 || start + length > str_len)
-            length = str_len - start;
-        }
+        start--;      /* one-origin */
       else
         {
           start = str_len + start;
           if (start <= 0)
             {
+              if (length < 0)
+                return o;
               start += length;
               if (start <= 0)
                 return o;
               length = start;
               start = 0;
             }
-          else if (length == 0 || start + length > str_len)
-            length = str_len - start;
         }
 
+      if (start >= str_len)
+        return o;
+      if (length == 0)
+        length = str_len - start;
+      else if (length < 0)
+        {
+          if (str_len <= -length)
+            return o;
+          length += str_len;
+          if (length <= start)
+            return o;
+          length -= start;
+        }
+      else if (start + length > str_len)
+        length = str_len - start;
+
       o = variable_buffer_output (o, str + start, length);
     }
   else
@@ -4407,18 +4420,18 @@ func_which (char *o, char **argv, const char *funcname UNUSED)
                 {
                   const char *src = comp;
                   const char *end = strchr (comp, PATH_SEPARATOR_CHAR);
-                  size_t comp_len = end ? (size_t)(end - comp) : strlen (comp);
-                  if (!comp_len)
+                  size_t src_len = end ? (size_t)(end - comp) : strlen (comp);
+                  if (!src_len)
                     {
-                      comp_len = 1;
+                      src_len = 1;
                       src = ".";
                     }
-                  if (len + comp_len + 2 + 4 < GET_PATH_MAX) /* +4 for .exe */
+                  if (len + src_len + 2 + 4 < GET_PATH_MAX) /* +4 for .exe */
                     {
-                      memcpy (buf, comp, comp_len);
-                      buf [comp_len] = '/';
-                      memcpy (&buf[comp_len + 1], cur, len);
-                      buf[comp_len + 1 + len] = '\0';
+                      memcpy (buf, src, src_len);
+                      buf [src_len] = '/';
+                      memcpy (&buf[src_len + 1], cur, len);
+                      buf[src_len + 1 + len] = '\0';
 
                       if (func_which_test_x (buf))
                         {
diff --git a/src/kmk/glob/glob.c b/src/kmk/glob/glob.c
index a948e41..7f16284 100644
--- a/src/kmk/glob/glob.c
+++ b/src/kmk/glob/glob.c
@@ -805,10 +805,17 @@ glob (pattern, flags, errfunc, pglob)
 
       /* Return the directory if we don't check for error or if it exists.  */
       if ((flags & GLOB_NOCHECK)
+#ifdef KMK
+	  || (flags & GLOB_ALTDIRFUNC
+	      ? (*pglob->gl_isdir) (dirname)
+	      : __stat (dirname, &st) == 0 && S_ISDIR (st.st_mode))
+#else
 	  || (((flags & GLOB_ALTDIRFUNC)
 	       ? (*pglob->gl_stat) (dirname, &st)
 	       : __stat (dirname, &st)) == 0
-	      && S_ISDIR (st.st_mode)))
+	      && S_ISDIR (st.st_mode))
+#endif
+	  )
 	{
 	  pglob->gl_pathv
 	    = (char **) realloc (pglob->gl_pathv,
@@ -952,9 +959,15 @@ glob (pattern, flags, errfunc, pglob)
 		  size_t dir_len = strlen (dir);
 
 		  /* First check whether this really is a directory.  */
+#ifdef KMK
+		  if (flags & GLOB_ALTDIRFUNC
+		      ? !pglob->gl_isdir (dir)
+		      : __stat (dir, &st) != 0 || !S_ISDIR (st.st_mode))
+#else
 		  if (((flags & GLOB_ALTDIRFUNC)
 		       ? (*pglob->gl_stat) (dir, &st) : __stat (dir, &st)) != 0
 		      || !S_ISDIR (st.st_mode))
+#endif
 		    /* No directory, ignore this entry.  */
 		    continue;
 
@@ -1027,10 +1040,16 @@ glob (pattern, flags, errfunc, pglob)
       __size_t i; /* bird: correct type. */
       struct stat st;
       for (i = oldcount; i < pglob->gl_pathc; ++i)
+#ifdef KMK
+	if (flags & GLOB_ALTDIRFUNC
+	    ? pglob->gl_isdir (pglob->gl_pathv[i])
+	    : __stat (pglob->gl_pathv[i], &st) == 0 && S_ISDIR (st.st_mode) )
+#else
 	if (((flags & GLOB_ALTDIRFUNC)
 	     ? (*pglob->gl_stat) (pglob->gl_pathv[i], &st)
 	     : __stat (pglob->gl_pathv[i], &st)) == 0
 	    && S_ISDIR (st.st_mode))
+#endif
 	  {
  	    size_t len = strlen (pglob->gl_pathv[i]) + 2;
 	    char *new = realloc (pglob->gl_pathv[i], len);
@@ -1260,9 +1279,13 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
 	  fullname[dirlen] = '/';
 	  memcpy (&fullname[dirlen + 1], pattern, patlen + 1);
 # endif
+# ifdef KMK
+	  if (flags & GLOB_ALTDIRFUNC ? pglob->gl_exists (fullname) : __stat (fullname, &st) == 0)
+# else
 	  if (((flags & GLOB_ALTDIRFUNC)
 	       ? (*pglob->gl_stat) (fullname, &st)
 	       : __stat (fullname, &st)) == 0)
+# endif
 	    /* We found this file to be existing.  Now tell the rest
 	       of the function to copy this name into the result.  */
 	    flags |= GLOB_NOCHECK;
diff --git a/src/kmk/glob/glob.h b/src/kmk/glob/glob.h
index a613aff..f987d03 100644
--- a/src/kmk/glob/glob.h
+++ b/src/kmk/glob/glob.h
@@ -136,6 +136,10 @@ typedef struct
 #else
     int (*gl_stat) __PMT ((__const char *, struct stat *));
 #endif
+#ifdef KMK
+    int (*gl_exists) __PMT ((__const char *));
+    int (*gl_isdir) __PMT ((__const char *));
+#endif
   } glob_t;
 
 #ifdef _LARGEFILE64_SOURCE
diff --git a/src/kmk/kbuild-object.c b/src/kmk/kbuild-object.c
new file mode 100644
index 0000000..07c4b9f
--- /dev/null
+++ b/src/kmk/kbuild-object.c
@@ -0,0 +1,1407 @@
+/* $Id: kbuild-object.c 2720 2014-01-01 22:59:50Z bird $ */
+/** @file
+ * kBuild objects.
+ */
+
+/*
+ * Copyright (c) 2011-2014 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * This file is part of kBuild.
+ *
+ * kBuild is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * kBuild is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with kBuild.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/* No GNU coding style here! */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include "make.h"
+#include "filedef.h"
+#include "variable.h"
+#include "dep.h"
+#include "debug.h"
+#include "kbuild.h"
+
+#include <assert.h>
+#include <stdarg.h>
+
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+#define WORD_IS(a_pszWord, a_cchWord, a_szWord2) \
+        (  (a_cchWord) == sizeof(a_szWord2) - 1 && memcmp((a_pszWord), a_szWord2, sizeof(a_szWord2) - 1) == 0)
+
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
+/** kBuild object type.  */
+enum kBuildType
+{
+    kBuildType_Invalid,
+    kBuildType_Target,
+    kBuildType_Template,
+    kBuildType_Tool,
+    kBuildType_Sdk,
+    kBuildType_Unit
+};
+
+enum kBuildSeverity
+{
+    kBuildSeverity_Warning,
+    kBuildSeverity_Error,
+    kBuildSeverity_Fatal
+};
+
+
+/**
+ * kBuild object data.
+ */
+struct kbuild_object
+{
+    /** The object type. */
+    enum kBuildType             enmType;
+    /** Object name length.  */
+    size_t                      cchName;
+    /** The bare name of the define. */
+    char                       *pszName;
+    /** The file location where this define was declared. */
+    struct floc                 FileLoc;
+
+    /** Pointer to the next element in the global list. */
+    struct kbuild_object       *pGlobalNext;
+
+    /** The variable set associated with this define. */
+    struct variable_set_list   *pVariables;
+
+    /** The parent name, NULL if none. */
+    char                       *pszParent;
+    /** The length of the parent name. */
+    size_t                      cchParent;
+    /** Pointer to the parent.  Resolved lazily, so it can be NULL even if we
+     * have a parent. */
+    struct kbuild_object       *pParent;
+
+    /** The template, NULL if none.  Only applicable to targets.  Only covers the
+     * primary template, not target or type specific templates.
+     * @todo not sure if this is really necessary. */
+    char const                 *pszTemplate;
+
+    /** The variable prefix. */
+    char                       *pszVarPrefix;
+    /** The length of the variable prefix. */
+    size_t                      cchVarPrefix;
+};
+
+
+/**
+ * The data we stack during eval.
+ */
+struct kbuild_eval_data
+{
+    /** Pointer to the element below us on the stack. */
+    struct kbuild_eval_data    *pStackDown;
+    /** Pointer to the object. */
+    struct kbuild_object       *pObj;
+    /** The saved current variable set, for restoring in kBuild-endef. */
+    struct variable_set_list   *pVariablesSaved;
+};
+
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** Linked list (LIFO) of kBuild defines.
+ * @todo use a hash! */
+static struct kbuild_object    *g_pHeadKbObjs = NULL;
+/** Stack of kBuild evalutation contexts.
+ * This is for dealing with potential recursive kBuild object definition,
+ * generally believed to only happen via $(eval ) or include similar. */
+struct kbuild_eval_data        *g_pTopKbEvalData = NULL;
+
+/** Cached variable name '_TEMPLATE'.  */
+static const char              *g_pszVarNmTemplate = NULL;
+
+/** Zero if compatibility mode is disabled, non-zero if enabled.
+ * If explicitily enabled, the value will be greater than 1. */
+int                             g_fKbObjCompMode = 1;
+
+
+/*******************************************************************************
+*   Internal Functions                                                         *
+*******************************************************************************/
+static struct kbuild_object *
+resolve_kbuild_object_parent(struct kbuild_object *pObj, int fQuiet);
+static struct kbuild_object *
+get_kbuild_object_parent(struct kbuild_object *pObj, enum kBuildSeverity enmSeverity);
+
+static struct kbuild_object *
+parse_kbuild_object_variable_accessor(const char *pchExpr, size_t cchExpr,
+                                      enum kBuildSeverity enmSeverity, const struct floc *pFileLoc,
+                                      const char **ppchVarNm, size_t *pcchVarNm, enum kBuildType *penmType);
+
+
+/**
+ * Initializes the kBuild object stuff.
+ *
+ * Requires the variable_cache to be initialized.
+ */
+void init_kbuild_object(void)
+{
+    g_pszVarNmTemplate = strcache2_add(&variable_strcache, STRING_SIZE_TUPLE("_TEMPLATE"));
+}
+
+
+/**
+ * Reports a problem with dynamic severity level.
+ *
+ * @param   enmSeverity         The severity level.
+ * @param   pFileLoc            The file location.
+ * @param   pszFormat           The format string.
+ * @param   ...                 Arguments for the format string.
+ */
+static void kbuild_report_problem(enum kBuildSeverity enmSeverity, const struct floc *pFileLoc,
+                                  const char *pszFormat, ...)
+{
+    char    szBuf[8192];
+    va_list va;
+
+    va_start(va, pszFormat);
+#ifdef _MSC_VER
+    _vsnprintf(szBuf, sizeof(szBuf), pszFormat, va);
+#else
+    vsnprintf(szBuf, sizeof(szBuf), pszFormat, va);
+#endif
+    va_end(va);
+
+    switch (enmSeverity)
+    {
+        case kBuildSeverity_Warning:
+            message(0, "%s", szBuf);
+            break;
+        case kBuildSeverity_Error:
+            error(pFileLoc, "%s", szBuf);
+            break;
+        default:
+        case kBuildSeverity_Fatal:
+            fatal(pFileLoc, "%s", szBuf);
+            break;
+    }
+}
+
+
+static const char *
+eval_kbuild_type_to_string(enum kBuildType enmType)
+{
+    switch (enmType)
+    {
+        case kBuildType_Target:      return "target";
+        case kBuildType_Template:    return "template";
+        case kBuildType_Tool:        return "tool";
+        case kBuildType_Sdk:         return "sdk";
+        case kBuildType_Unit:        return "unit";
+        default:
+        case kBuildType_Invalid:     return "invalid";
+    }
+}
+
+/**
+ * Gets the length of the string representation of the given type.
+ *
+ * @returns The string length.
+ * @param   enmType             The kBuild object type in question.
+ */
+static unsigned
+eval_kbuild_type_to_string_length(enum kBuildType enmType)
+{
+    switch (enmType)
+    {
+        case kBuildType_Target:      return sizeof("target") - 1;
+        case kBuildType_Template:    return sizeof("template") - 1;
+        case kBuildType_Tool:        return sizeof("tool") - 1;
+        case kBuildType_Sdk:         return sizeof("sdk") - 1;
+        case kBuildType_Unit:        return sizeof("unit") - 1;
+        default:
+        case kBuildType_Invalid:     return sizeof("invalid") - 1;
+    }
+}
+
+/**
+ * Converts a string into an kBuild object type.
+ *
+ * @returns The type on success, kBuildType_Invalid on failure.
+ * @param   pchWord             The pchWord.  Not necessarily zero terminated.
+ * @param   cchWord             The length of the word.
+ */
+static enum kBuildType
+eval_kbuild_type_from_string(const char *pchWord, size_t cchWord)
+{
+    if (cchWord >= 3)
+    {
+        if (*pchWord == 't')
+        {
+            if (WORD_IS(pchWord, cchWord, "target"))
+                return kBuildType_Target;
+            if (WORD_IS(pchWord, cchWord, "template"))
+                return kBuildType_Template;
+            if (WORD_IS(pchWord, cchWord, "tool"))
+                return kBuildType_Tool;
+        }
+        else
+        {
+            if (WORD_IS(pchWord, cchWord, "sdk"))
+                return kBuildType_Sdk;
+            if (WORD_IS(pchWord, cchWord, "unit"))
+                return kBuildType_Unit;
+        }
+    }
+
+    return kBuildType_Invalid;
+}
+
+
+
+/**
+ * Helper function for caching variable name strings.
+ *
+ * @returns The string cache variable name.
+ * @param   pszName             The variable name.
+ * @param   ppszCache           Cache variable, static or global.  Initialize to
+ *                              NULL.
+ */
+static const char *
+kbuild_variable_name(const char *pszName, const char **ppszCache)
+{
+    const char *pszRet = *ppszCache;
+    if (!pszRet)
+        *ppszCache = pszRet = strcache2_add(&variable_strcache, pszName, strlen(pszName));
+    return pszRet;
+}
+
+static struct kbuild_object *
+lookup_kbuild_object(enum kBuildType enmType, const char *pchName, size_t cchName)
+{
+    /* Linear lookup for now. */
+    struct kbuild_object *pCur = g_pHeadKbObjs;
+    while (pCur)
+    {
+        if (   pCur->enmType == enmType
+            && pCur->cchName == cchName
+            && !memcmp(pCur->pszName, pchName, cchName))
+            return pCur;
+        pCur = pCur->pGlobalNext;
+    }
+    return NULL;
+}
+
+
+/** @name Defining and modifying variables
+ * @{
+ */
+
+/**
+ * Checks if the variable name is valid.
+ *
+ * @returns 1 if valid, 0 if not.
+ * @param   pchName             The variable name.
+ * @param   cchName             The length of the variable name.
+ */
+static int
+is_valid_kbuild_object_variable_name(const char *pchName, size_t cchName)
+{
+    if (cchName > 0)
+    {
+        if (!memchr(pchName, '[', cchName))
+        {
+            /** @todo more? */
+            return 1;
+        }
+    }
+    return 0;
+}
+
+static const char *
+kbuild_replace_special_accessors(const char *pchValue, size_t *pcchValue, int *pfDuplicateValue,
+                                 const struct floc *pFileLoc)
+{
+    size_t      cchValue    = *pcchValue;
+    size_t      cbAllocated = *pfDuplicateValue ? 0 : cchValue + 1;
+
+    /*
+     * Loop thru each potential special accessor occurance in the string.
+     *
+     * Unfortunately, we don't have a strnstr function in the C library, so
+     * we'll using memchr and doing a few more rounds in this loop.
+     */
+    size_t  cchLeft  = cchValue;
+    char   *pchLeft  = (char *)pchValue;
+    for (;;)
+    {
+        int     fSuper;
+        char   *pch = (char *)memchr(pchLeft, '$', cchLeft);
+        if (!pch)
+            break;
+
+        pch++;
+        cchLeft -= pch - pchLeft;
+        pchLeft  = pch;
+
+        /* [@self] is the shorter, quit if there isn't enough room for even it. */
+        if (cchLeft < sizeof("([@self]") - 1)
+            break;
+
+        /* We don't care how many dollars there are in front of a special accessor. */
+        if (*pchLeft == '$')
+        {
+            do
+            {
+                cchLeft--;
+                pchLeft++;
+            } while (cchLeft >= sizeof("([@self]") - 1 && *pchLeft == '$');
+            if (cchLeft < sizeof("([@self]") - 1)
+                break;
+        }
+
+        /* Is it a special accessor? */
+        if (   pchLeft[2] != '@'
+            || pchLeft[1] != '['
+            || pchLeft[0] != '(')
+            continue;
+        pchLeft += 2;
+        cchLeft -= 2;
+        if (!memcmp(pchLeft, STRING_SIZE_TUPLE("@self]")))
+            fSuper = 0;
+        else if (   cchLeft >= sizeof("@super]")
+                 && !memcmp(pchLeft, STRING_SIZE_TUPLE("@super]")))
+            fSuper = 1;
+        else
+            continue;
+
+        /*
+         * We've got something to replace. First figure what with and then
+         * resize the value buffer.
+         */
+        if (g_pTopKbEvalData)
+        {
+            struct kbuild_object   *pObj       = g_pTopKbEvalData->pObj;
+            size_t const            cchSpecial = fSuper ? sizeof("@super") - 1 : sizeof("@self") - 1;
+            size_t                  cchName;
+            size_t                  cchType;
+            long                    cchDelta;
+            const char             *pszName;
+
+            if (fSuper)
+            {
+                pObj = get_kbuild_object_parent(pObj, kBuildSeverity_Error);
+                if (!pObj)
+                    continue;
+            }
+            pszName = pObj->pszName;
+            cchName = pObj->cchName;
+            cchType = eval_kbuild_type_to_string_length(pObj->enmType);
+            cchDelta = cchType + 1 + cchName - cchSpecial;
+
+            if (cchValue + cchDelta >= cbAllocated)
+            {
+                size_t  offLeft = pchLeft - pchValue;
+                char   *pszNewValue;
+
+                cbAllocated = cchValue + cchDelta + 1;
+                if (cchValue < 1024)
+                    cbAllocated = (cbAllocated + 31) & ~(size_t)31;
+                else
+                    cbAllocated = (cbAllocated + 255) & ~(size_t)255;
+                pszNewValue = (char *)xmalloc(cbAllocated);
+
+                memcpy(pszNewValue, pchValue, offLeft);
+                memcpy(pszNewValue + offLeft + cchSpecial + cchDelta,
+                       pchLeft + cchSpecial,
+                       cchLeft - cchSpecial + 1);
+
+                if (*pfDuplicateValue == 0)
+                    free((char *)pchValue);
+                else
+                    *pfDuplicateValue = 0;
+
+                pchValue = pszNewValue;
+                pchLeft  = pszNewValue + offLeft;
+            }
+            else
+            {
+                assert(*pfDuplicateValue == 0);
+                memmove(pchLeft + cchSpecial + cchDelta,
+                        pchLeft + cchSpecial,
+                        cchLeft - cchSpecial + 1);
+            }
+
+            cchLeft  += cchDelta;
+            cchValue += cchDelta;
+            *pcchValue = cchValue;
+
+            memcpy(pchLeft, eval_kbuild_type_to_string(pObj->enmType), cchType);
+            pchLeft += cchType;
+            *pchLeft++ = '@';
+            memcpy(pchLeft, pszName, cchName);
+            pchLeft += cchName;
+            cchLeft -= cchType + 1 + cchName;
+        }
+        else
+            error(pFileLoc, _("The '$([%.*s...' accessor can only be used in the context of a kBuild object"),
+                  MAX(cchLeft, 20), pchLeft);
+    }
+
+    return pchValue;
+}
+
+static struct variable *
+define_kbuild_object_variable_cached(struct kbuild_object *pObj, const char *pszName,
+                                     const char *pchValue, size_t cchValue,
+                                     int fDuplicateValue, enum variable_origin enmOrigin,
+                                     int fRecursive, int fNoSpecialAccessors, const struct floc *pFileLoc)
+{
+    struct variable *pVar;
+    size_t cchName = strcache2_get_len(&variable_strcache, pszName);
+
+    if (fRecursive && !fNoSpecialAccessors)
+        pchValue = kbuild_replace_special_accessors(pchValue, &cchValue, &fDuplicateValue, pFileLoc);
+
+    pVar = define_variable_in_set(pszName, cchName,
+                                  pchValue, cchValue, fDuplicateValue,
+                                  enmOrigin, fRecursive,
+                                  pObj->pVariables->set,
+                                  pFileLoc);
+
+    /* Single underscore prefixed variables gets a global alias. */
+    if (   pszName[0] == '_'
+        && pszName[1] != '_'
+        && g_fKbObjCompMode)
+    {
+        struct variable *pAlias;
+        size_t           cchPrefixed = pObj->cchVarPrefix + cchName;
+        char            *pszPrefixed = xmalloc(cchPrefixed + 1);
+        memcpy(pszPrefixed, pObj->pszVarPrefix, pObj->cchVarPrefix);
+        memcpy(&pszPrefixed[pObj->cchVarPrefix], pszName, cchName);
+        pszPrefixed[cchPrefixed] = '\0';
+
+        pAlias = define_variable_alias_in_set(pszPrefixed, cchPrefixed, pVar, enmOrigin,
+                                              &global_variable_set, pFileLoc);
+        if (!pAlias->alias)
+            error(pFileLoc, _("Error defining alias '%s'"), pszPrefixed);
+    }
+
+    return pVar;
+}
+
+#if 0
+struct variable *
+define_kbuild_object_variable(struct kbuild_object *pObj, const char *pchName, size_t cchName,
+                              const char *pchValue, size_t cchValue,
+                              int fDuplicateValue, enum variable_origin enmOrigin,
+                              int fRecursive, const struct floc *pFileLoc)
+{
+    return define_kbuild_object_variable_cached(pObj, strcache2_add(&variable_strcache, pchName, cchName),
+                                                pchValue, cchValue,
+                                                fDuplicateValue, enmOrigin,
+                                                fRecursive, pFileLoc);
+}
+#endif
+
+/**
+ * Try define a kBuild object variable via a possible accessor
+ * ([type at object]var).
+ *
+ * @returns Pointer to the defined variable on success.
+ * @retval  VAR_NOT_KBUILD_ACCESSOR if it isn't an accessor.
+ *
+ * @param   pchName         The variable name, not cached.
+ * @param   cchName         The variable name length.  This will not be ~0U.
+ * @param   pszValue        The variable value.  If @a fDuplicateValue is clear,
+ *                          this should be assigned as the actual variable
+ *                          value, otherwise it will be duplicated.  In the
+ *                          latter case it might not be properly null
+ *                          terminated.
+ * @param   cchValue        The value length.
+ * @param   fDuplicateValue Whether @a pszValue need to be duplicated on the
+ *                          heap or is already there.
+ * @param   enmOrigin       The variable origin.
+ * @param   fRecursive      Whether it's a recursive variable.
+ * @param   pFileLoc        The location of the variable definition.
+ */
+struct variable *
+try_define_kbuild_object_variable_via_accessor(const char *pchName, size_t cchName,
+                                               const char *pszValue, size_t cchValue, int fDuplicateValue,
+                                               enum variable_origin enmOrigin, int fRecursive,
+                                               struct floc const *pFileLoc)
+{
+    struct kbuild_object   *pObj;
+    const char             *pchVarNm;
+    size_t                  cchVarNm;
+
+    pObj = parse_kbuild_object_variable_accessor(pchName, cchName, kBuildSeverity_Fatal, pFileLoc,
+                                                 &pchVarNm, &cchVarNm, NULL);
+    if (pObj != KOBJ_NOT_KBUILD_ACCESSOR)
+    {
+        assert(pObj != NULL);
+        if (!is_valid_kbuild_object_variable_name(pchVarNm, cchVarNm))
+            fatal(pFileLoc, _("Invalid kBuild object variable name: '%.*s' ('%s')"),
+                  (int)cchVarNm, pchVarNm, (int)cchName, pchName);
+        return define_kbuild_object_variable_cached(pObj, strcache2_add(&variable_strcache, pchVarNm, cchVarNm),
+                                                    pszValue, cchValue, fDuplicateValue, enmOrigin, fRecursive,
+                                                    0 /*fNoSpecialAccessors*/, pFileLoc);
+    }
+
+    return VAR_NOT_KBUILD_ACCESSOR;
+}
+
+/**
+ * Define a kBuild object variable in the topmost kBuild object.
+ *
+ * This won't be an variable accessor.
+ *
+ * @returns Pointer to the defined variable on success.
+ *
+ * @param   pchName         The variable name, not cached.
+ * @param   cchName         The variable name length.  This will not be ~0U.
+ * @param   pszValue        The variable value.  If @a fDuplicateValue is clear,
+ *                          this should be assigned as the actual variable
+ *                          value, otherwise it will be duplicated.  In the
+ *                          latter case it might not be properly null
+ *                          terminated.
+ * @param   cchValue        The value length.
+ * @param   fDuplicateValue Whether @a pszValue need to be duplicated on the
+ *                          heap or is already there.
+ * @param   enmOrigin       The variable origin.
+ * @param   fRecursive      Whether it's a recursive variable.
+ * @param   pFileLoc        The location of the variable definition.
+ */
+struct variable *
+define_kbuild_object_variable_in_top_obj(const char *pchName, size_t cchName,
+                                         const char *pszValue, size_t cchValue, int fDuplicateValue,
+                                         enum variable_origin enmOrigin, int fRecursive,
+                                         struct floc const *pFileLoc)
+{
+    assert(g_pTopKbEvalData != NULL);
+
+    if (!is_valid_kbuild_object_variable_name(pchName, cchName))
+        fatal(pFileLoc, _("Invalid kBuild object variable name: '%.*s'"), (int)cchName, pchName);
+
+    return define_kbuild_object_variable_cached(g_pTopKbEvalData->pObj, strcache2_add(&variable_strcache, pchName, cchName),
+                                                pszValue, cchValue, fDuplicateValue, enmOrigin, fRecursive,
+                                                0 /*fNoSpecialAccessors*/, pFileLoc);
+}
+
+/**
+ * Implements appending and prepending to a kBuild object variable.
+ *
+ * The variable is either accessed thru an accessor or by the topmost kBuild
+ * object.
+ *
+ * @returns Pointer to the defined variable on success.
+ *
+ * @param   pchName         The variable name, not cached.
+ * @param   cchName         The variable name length.  This will not be ~0U.
+ * @param   pszValue        The variable value. Must be duplicated.
+ * @param   cchValue        The value length.
+ * @param   fSimpleValue    Whether we've already figured that it's a simple
+ *                          value.  This is for optimizing appending/prepending
+ *                          to an existing simple value variable.
+ * @param   enmOrigin       The variable origin.
+ * @param   fAppend         Append if set, prepend if clear.
+ * @param   pFileLoc        The location of the variable definition.
+ */
+struct variable *
+kbuild_object_variable_pre_append(const char *pchName, size_t cchName,
+                                  const char *pchValue, size_t cchValue, int fSimpleValue,
+                                  enum variable_origin enmOrigin, int fAppend,
+                                  const struct floc *pFileLoc)
+{
+    struct kbuild_object   *pObj;
+    struct variable         VarKey;
+
+    /*
+     * Resolve the relevant kBuild object first.
+     */
+    if (cchName > 3 && pchName[0] == '[')
+    {
+        const char *pchVarNm;
+        size_t      cchVarNm;
+        pObj = parse_kbuild_object_variable_accessor(pchName, cchName, kBuildSeverity_Fatal, pFileLoc,
+                                                     &pchVarNm, &cchVarNm, NULL);
+        if (pObj != KOBJ_NOT_KBUILD_ACCESSOR)
+        {
+            pchName = pchVarNm;
+            cchName = cchVarNm;
+        }
+        else
+            pObj = g_pTopKbEvalData->pObj;
+    }
+    else
+        pObj = g_pTopKbEvalData->pObj;
+
+    /*
+     * Make sure the variable name is valid.  Raise fatal error if not.
+     */
+    if (!is_valid_kbuild_object_variable_name(pchName, cchName))
+        fatal(pFileLoc, _("Invalid kBuild object variable name: '%.*s'"), (int)cchName, pchName);
+
+    /*
+     * Get the cached name and look it up in the object's variables.
+     */
+    VarKey.name = strcache2_lookup(&variable_strcache, pchName, cchName);
+    if (VarKey.name)
+    {
+        struct variable *pVar;
+
+        VarKey.length = cchName;
+        pVar = (struct variable *)hash_find_item_strcached(&pObj->pVariables->set->table, &VarKey);
+        if (pVar)
+        {
+            /* Append/prepend to existing variable. */
+            int fDuplicateValue = 1;
+            if (pVar->recursive && !fSimpleValue)
+                pchValue = kbuild_replace_special_accessors(pchValue, &cchValue, &fDuplicateValue, pFileLoc);
+
+            pVar = do_variable_definition_append(pFileLoc, pVar, pchValue, cchValue, fSimpleValue, enmOrigin, fAppend);
+
+            if (fDuplicateValue == 0)
+                free((char *)pchValue);
+            return pVar;
+        }
+
+        /*
+         * Not found. Check ancestors if the 'override' directive isn't applied.
+         */
+        if (pObj->pszParent && enmOrigin != o_override)
+        {
+            struct kbuild_object *pParent = pObj;
+            for (;;)
+            {
+                pParent = resolve_kbuild_object_parent(pParent, 0 /*fQuiet*/);
+                if (!pParent)
+                    break;
+
+                pVar = (struct variable *)hash_find_item_strcached(&pParent->pVariables->set->table, &VarKey);
+                if (pVar)
+                {
+                    if (pVar->value_length != ~0U)
+                        assert(pVar->value_length == strlen(pVar->value));
+                    else
+                        pVar->value_length = strlen(pVar->value);
+
+                    /*
+                     * Combine the two values and define the variable in the
+                     * specified child object.  We must disregard 'origin' a
+                     * little here, so we must do the gritty stuff our selves.
+                     */
+                    if (   pVar->recursive
+                        || fSimpleValue
+                        || !cchValue
+                        || memchr(pchValue, '$', cchValue) == NULL )
+                    {
+                        int     fDuplicateValue = 1;
+                        size_t  cchNewValue;
+                        char   *pszNewValue;
+                        char   *pszTmp;
+
+                        /* Just join up the two values. */
+                        if (pVar->recursive && !fSimpleValue)
+                            pchValue = kbuild_replace_special_accessors(pchValue, &cchValue, &fDuplicateValue, pFileLoc);
+                        if (pVar->value_length == 0)
+                        {
+                            cchNewValue = cchValue;
+                            pszNewValue = xstrndup(pchValue, cchValue);
+                        }
+                        else if (!cchValue)
+                        {
+                            cchNewValue = pVar->value_length;
+                            pszNewValue = xmalloc(cchNewValue + 1);
+                            memcpy(pszNewValue, pVar->value, cchNewValue + 1);
+                        }
+                        else
+                        {
+                            cchNewValue = pVar->value_length + 1 + cchValue;
+                            pszNewValue = xmalloc(cchNewValue + 1);
+                            if (fAppend)
+                            {
+                                memcpy(pszNewValue, pVar->value, pVar->value_length);
+                                pszTmp = pszNewValue + pVar->value_length;
+                                *pszTmp++ = ' ';
+                                memcpy(pszTmp, pchValue, cchValue);
+                                pszTmp[cchValue] = '\0';
+                            }
+                            else
+                            {
+                                memcpy(pszNewValue, pchValue, cchValue);
+                                pszTmp = pszNewValue + cchValue;
+                                *pszTmp++ = ' ';
+                                memcpy(pszNewValue, pVar->value, pVar->value_length);
+                                pszTmp[pVar->value_length] = '\0';
+                            }
+                        }
+
+                        /* Define the new variable in the child. */
+                        pVar = define_kbuild_object_variable_cached(pObj, VarKey.name,
+                                                                    pszNewValue, cchNewValue, 0 /*fDuplicateValue*/,
+                                                                    enmOrigin, pVar->recursive, 1 /*fNoSpecialAccessors*/,
+                                                                    pFileLoc);
+                        if (fDuplicateValue == 0)
+                            free((char *)pchValue);
+                    }
+                    else
+                    {
+                        /* Lazy bird: Copy the variable from the ancestor and
+                                      then do a normal append/prepend on it. */
+                        pVar = define_kbuild_object_variable_cached(pObj, VarKey.name,
+                                                                    pVar->value, pVar->value_length, 1 /*fDuplicateValue*/,
+                                                                    enmOrigin, pVar->recursive, 1 /*fNoSpecialAccessors*/,
+                                                                    pFileLoc);
+                        append_expanded_string_to_variable(pVar, pchValue, cchValue, fAppend);
+                    }
+                    return pVar;
+                }
+            }
+        }
+    }
+    else
+        VarKey.name = strcache2_add(&variable_strcache, pchName, cchName);
+
+    /* Variable not found. */
+    return define_kbuild_object_variable_cached(pObj, VarKey.name,
+                                                pchValue, cchValue, 1 /*fDuplicateValue*/, enmOrigin,
+                                                1 /*fRecursive */, 0 /*fNoSpecialAccessors*/, pFileLoc);
+}
+
+/** @} */
+
+
+static char *
+allocate_expanded_next_token(const char **ppszCursor, const char *pszEos, size_t *pcchToken, int fStrip)
+{
+    unsigned int cchToken;
+    char *pszToken = find_next_token_eos(ppszCursor, pszEos, &cchToken);
+    if (pszToken)
+    {
+        pszToken = allocated_variable_expand_2(pszToken, cchToken, &cchToken);
+        if (pszToken)
+        {
+            if (fStrip)
+            {
+                unsigned int off = 0;
+                while (MY_IS_BLANK(pszToken[off]))
+                    off++;
+                if (off)
+                {
+                    cchToken -= off;
+                    memmove(pszToken, &pszToken[off], cchToken + 1);
+                }
+
+                while (cchToken > 0 && MY_IS_BLANK(pszToken[cchToken - 1]))
+                    pszToken[--cchToken] = '\0';
+            }
+
+            assert(cchToken == strlen(pszToken));
+            if (pcchToken)
+                *pcchToken = cchToken;
+            return pszToken;
+        }
+    }
+
+    if (pcchToken)
+        *pcchToken = 0;
+    return NULL;
+}
+
+static struct kbuild_object *
+resolve_kbuild_object_parent(struct kbuild_object *pObj, int fQuiet)
+{
+    if (   !pObj->pParent
+        && pObj->pszParent)
+    {
+        struct kbuild_object *pCur = g_pHeadKbObjs;
+        while (pCur)
+        {
+            if (   pCur->enmType == pObj->enmType
+                && !strcmp(pCur->pszName, pObj->pszParent))
+            {
+                if (    pCur->pszParent
+                    &&  (   pCur->pParent == pObj
+                         || !strcmp(pCur->pszParent, pObj->pszName)) )
+                    fatal(&pObj->FileLoc, _("'%s' and '%s' are both trying to be each other children..."),
+                          pObj->pszName, pCur->pszName);
+
+                pObj->pParent = pCur;
+                pObj->pVariables->next = pObj->pVariables;
+                return pCur;
+            }
+
+            pCur = pCur->pGlobalNext;
+        }
+
+        /* Not found. */
+        if (!fQuiet)
+            error(&pObj->FileLoc, _("Could not locate parent '%s' of '%s'"), pObj->pszParent, pObj->pszName);
+    }
+    return pObj->pParent;
+}
+
+/**
+ * Get the parent of the given object, it is expected to have one.
+ *
+ * @returns Pointer to the parent. NULL if we survive failure.
+ * @param   pObj                The kBuild object.
+ * @param   enmSeverity         The severity of a missing parent.
+ */
+static struct kbuild_object *
+get_kbuild_object_parent(struct kbuild_object *pObj, enum kBuildSeverity enmSeverity)
+{
+    struct kbuild_object *pParent = pObj->pParent;
+    if (pParent)
+        return pParent;
+
+    pParent = resolve_kbuild_object_parent(pObj, 1 /*fQuiet - complain below */);
+    if (pParent)
+        return pParent;
+
+    if (pObj->pszParent)
+        kbuild_report_problem(enmSeverity, &pObj->FileLoc,
+                              _("Could not local parent '%s' for kBuild object '%s'"),
+                              pObj->pszParent, pObj->pszName);
+    else
+        kbuild_report_problem(enmSeverity, &pObj->FileLoc,
+                              _("kBuild object '%s' has no parent ([@super])"),
+                              pObj->pszName);
+    return NULL;
+}
+
+static int
+eval_kbuild_define_xxxx(struct kbuild_eval_data **ppData, const struct floc *pFileLoc,
+                        const char *pszLine, const char *pszEos, int fIgnoring, enum kBuildType enmType)
+{
+    unsigned int            cch;
+    char                    ch;
+    char                   *psz;
+    const char             *pszPrefix;
+    struct kbuild_object   *pObj;
+    struct kbuild_eval_data *pData;
+
+    if (fIgnoring)
+        return 0;
+
+    /*
+     * Create a new kBuild object.
+     */
+    pObj = xmalloc(sizeof(*pObj));
+    pObj->enmType           = enmType;
+    pObj->pszName           = NULL;
+    pObj->cchName           = 0;
+    pObj->FileLoc           = *pFileLoc;
+
+    pObj->pGlobalNext       = g_pHeadKbObjs;
+    g_pHeadKbObjs           = pObj;
+
+    pObj->pVariables        = create_new_variable_set();
+
+    pObj->pszParent         = NULL;
+    pObj->cchParent         = 0;
+    pObj->pParent           = NULL;
+
+    pObj->pszTemplate       = NULL;
+
+    pObj->pszVarPrefix      = NULL;
+    pObj->cchVarPrefix      = 0;
+
+    /*
+     * The first word is the name.
+     */
+    pObj->pszName = allocate_expanded_next_token(&pszLine, pszEos, &pObj->cchName, 1 /*strip*/);
+    if (!pObj->pszName || !*pObj->pszName)
+        fatal(pFileLoc, _("The kBuild define requires a name"));
+
+    psz = pObj->pszName;
+    while ((ch = *psz++) != '\0')
+        if (!isgraph(ch))
+        {
+            error(pFileLoc, _("The 'kBuild-define-%s' name '%s' contains one or more invalid characters"),
+                  eval_kbuild_type_to_string(enmType), pObj->pszName);
+            break;
+        }
+
+    /*
+     * Calc the variable prefix.
+     */
+    switch (enmType)
+    {
+        case kBuildType_Target:      pszPrefix = ""; break;
+        case kBuildType_Template:    pszPrefix = "TEMPLATE_"; break;
+        case kBuildType_Tool:        pszPrefix = "TOOL_"; break;
+        case kBuildType_Sdk:         pszPrefix = "SDK_"; break;
+        case kBuildType_Unit:        pszPrefix = "UNIT_"; break;
+        default:
+            fatal(pFileLoc, _("enmType=%d"), enmType);
+            return -1;
+    }
+    cch = strlen(pszPrefix);
+    pObj->cchVarPrefix = cch + pObj->cchName;
+    pObj->pszVarPrefix = xmalloc(pObj->cchVarPrefix + 1);
+    memcpy(pObj->pszVarPrefix, pszPrefix, cch);
+    memcpy(&pObj->pszVarPrefix[cch], pObj->pszName, pObj->cchName);
+
+    /*
+     * Parse subsequent words.
+     */
+    psz = find_next_token_eos(&pszLine, pszEos, &cch);
+    while (psz)
+    {
+        if (WORD_IS(psz, cch, "extending"))
+        {
+            /* Inheritance directive. */
+            if (pObj->pszParent != NULL)
+                fatal(pFileLoc, _("'extending' can only occure once"));
+            pObj->pszParent = allocate_expanded_next_token(&pszLine, pszEos, &pObj->cchParent, 1 /*strip*/);
+            if (!pObj->pszParent || !*pObj->pszParent)
+                fatal(pFileLoc, _("'extending' requires a parent name"));
+        }
+        else if (WORD_IS(psz, cch, "using"))
+        {
+            char   *pszTemplate;
+            size_t  cchTemplate;
+
+            /* Template directive. */
+            if (enmType != kBuildType_Target)
+                fatal(pFileLoc, _("'using <template>' can only be used with 'kBuild-define-target'"));
+            if (pObj->pszTemplate != NULL)
+                fatal(pFileLoc, _("'using' can only occure once"));
+
+            pszTemplate = allocate_expanded_next_token(&pszLine, pszEos, &cchTemplate, 1 /*fStrip*/);
+            if (!pszTemplate || !*pszTemplate)
+                fatal(pFileLoc, _("'using' requires a template name"));
+
+            define_kbuild_object_variable_cached(pObj, g_pszVarNmTemplate, pszTemplate, cchTemplate,
+                                                 0 /*fDuplicateValue*/, o_default, 0 /*fRecursive*/,
+                                                 1 /*fNoSpecialAccessors*/, pFileLoc);
+
+        }
+        else
+            fatal(pFileLoc, _("Don't know what '%.*s' means"), (int)cch, psz);
+
+        /* next token */
+        psz = find_next_token_eos(&pszLine, pszEos, &cch);
+    }
+
+    /*
+     * Try resolve the parent.
+     */
+    resolve_kbuild_object_parent(pObj, 1 /*fQuiet*/);
+
+    /*
+     * Create an eval stack entry and change the current variable set.
+     */
+    pData = xmalloc(sizeof(*pData));
+    pData->pObj             = pObj;
+    pData->pVariablesSaved  = current_variable_set_list;
+    current_variable_set_list = pObj->pVariables;
+
+    pData->pStackDown       = *ppData;
+    *ppData                 = pData;
+    g_pTopKbEvalData        = pData;
+
+    return 0;
+}
+
+static int
+eval_kbuild_endef_xxxx(struct kbuild_eval_data **ppData, const struct floc *pFileLoc,
+                       const char *pszLine, const char *pszEos, int fIgnoring, enum kBuildType enmType)
+{
+    struct kbuild_eval_data *pData;
+    struct kbuild_object    *pObj;
+    size_t                   cchName;
+    char                    *pszName;
+
+    if (fIgnoring)
+        return 0;
+
+    /*
+     * Is there something to pop?
+     */
+    pData = *ppData;
+    if (!pData)
+    {
+        error(pFileLoc, _("kBuild-endef-%s is missing kBuild-define-%s"),
+              eval_kbuild_type_to_string(enmType), eval_kbuild_type_to_string(enmType));
+        return 0;
+    }
+
+    /*
+     * ... and does it have a matching kind?
+     */
+    pObj = pData->pObj;
+    if (pObj->enmType != enmType)
+        error(pFileLoc, _("'kBuild-endef-%s' does not match 'kBuild-define-%s %s'"),
+              eval_kbuild_type_to_string(enmType), eval_kbuild_type_to_string(pObj->enmType), pObj->pszName);
+
+    /*
+     * The endef-kbuild may optionally be followed by the target name.
+     * It should match the name given to the kBuild-define.
+     */
+    pszName = allocate_expanded_next_token(&pszLine, pszEos, &cchName, 1 /*fStrip*/);
+    if (pszName)
+    {
+        if (   cchName != pObj->cchName
+            || strcmp(pszName, pObj->pszName))
+            error(pFileLoc, _("'kBuild-endef-%s %s' does not match 'kBuild-define-%s %s'"),
+                  eval_kbuild_type_to_string(enmType), pszName,
+                  eval_kbuild_type_to_string(pObj->enmType), pObj->pszName);
+        free(pszName);
+    }
+
+    /*
+     * Pop a define off the stack.
+     */
+    assert(pData == g_pTopKbEvalData);
+    *ppData = g_pTopKbEvalData = pData->pStackDown;
+    pData->pStackDown      = NULL;
+    current_variable_set_list = pData->pVariablesSaved;
+    pData->pVariablesSaved = NULL;
+    free(pData);
+
+    return 0;
+}
+
+int eval_kbuild_read_hook(struct kbuild_eval_data **kdata, const struct floc *flocp,
+                          const char *pchWord, size_t cchWord, const char *line, const char *eos, int ignoring)
+{
+    enum kBuildType enmType;
+
+    /*
+     * Skip the 'kBuild-' prefix that the caller already matched.
+     */
+    assert(memcmp(pchWord, "kBuild-", sizeof("kBuild-") - 1) == 0);
+    pchWord += sizeof("kBuild-") - 1;
+    cchWord -= sizeof("kBuild-") - 1;
+
+    /*
+     * String switch.
+     */
+    if (   cchWord >= sizeof("define-") - 1
+        && strneq(pchWord, "define-", sizeof("define-") - 1))
+    {
+        enmType = eval_kbuild_type_from_string(pchWord + sizeof("define-") - 1, cchWord - sizeof("define-") + 1);
+        if (enmType != kBuildType_Invalid)
+            return eval_kbuild_define_xxxx(kdata, flocp, line, eos, ignoring, enmType);
+    }
+    else if (   cchWord >= sizeof("endef-") - 1
+             && strneq(pchWord, "endef-", sizeof("endef-") - 1))
+    {
+        enmType = eval_kbuild_type_from_string(pchWord + sizeof("endif-") - 1, cchWord - sizeof("endif-") + 1);
+        if (enmType != kBuildType_Invalid)
+            return eval_kbuild_endef_xxxx(kdata, flocp, line, eos, ignoring, enmType);
+    }
+    else if (WORD_IS(pchWord, cchWord, "endef"))
+    {
+        /* Terminate whatever definition is on top. */
+
+    }
+
+    /*
+     * Everything that is prefixed with 'kBuild-' is reserved for language
+     * extensions, at least until legacy assignments/whatever turns up.
+     */
+    error(flocp, _("Unknown syntax 'kBuild-%.*s'"), (int)cchWord, pchWord);
+    return 0;
+}
+
+
+/** @name kBuild object variable accessor related functions
+ * @{
+ */
+
+/**
+ * Checks if the given name is an object variable accessor.
+ *
+ * @returns 1 if it is, 0 if it isn't.
+ * @param   pchName             The potential kBuild variable accessor
+ *                              expression.
+ * @param   cchName             Length of the expression.
+ */
+int is_kbuild_object_variable_accessor(const char *pchName, size_t cchName)
+{
+    char const *pchTmp;
+
+    /* See lookup_kbuild_object_variable for the rules. */
+    if (cchName >= 1+1+1+1 && *pchName == '[')
+    {
+        pchName++;
+        cchName--;
+
+        pchTmp = memchr(pchName, '@', cchName);
+        if (pchTmp)
+        {
+            cchName -= pchTmp + 1 - pchName;
+            pchName  = pchTmp + 1;
+            pchTmp = memchr(pchName, ']', cchName);
+            if (pchTmp)
+            {
+                cchName -= pchTmp + 1 - pchName;
+                if (cchName > 0)
+                    return 1;
+            }
+        }
+    }
+    return 0;
+}
+
+/**
+ * Parses a kBuild object variable accessor, resolving the object.
+ *
+ * @returns Pointer to the variable if found.
+ * @retval  NULL if the object (or type) couldn't be resolved.
+ * @retval  KOBJ_NOT_KBUILD_ACCESSOR if no a kBuild variable accessor.
+ *
+ * @param   pchExpr             The kBuild variable accessor expression.
+ * @param   cchExpr             Length of the expression.
+ * @param   enmSeverity         The minimum severity level for errors.
+ * @param   pFileLoc            The file location any errors should be reported
+ *                              at. Optional.
+ * @param   ppchVarNm           Where to return the pointer to the start of the
+ *                              variable name within the string @a pchExpr
+ *                              points to. Mandatory.
+ * @param   pcchVarNm           Where to return the length of the variable name.
+ *                              Mandatory.
+ * @param   penmType            Where to return the object type. Optional.
+ */
+static struct kbuild_object *
+parse_kbuild_object_variable_accessor(const char *pchExpr, size_t cchExpr,
+                                      enum kBuildSeverity enmSeverity, const struct floc *pFileLoc,
+                                      const char **ppchVarNm, size_t *pcchVarNm, enum kBuildType *penmType)
+{
+    const char * const pchOrgExpr = pchExpr;
+    size_t       const cchOrgExpr = cchExpr;
+    char const        *pchTmp;
+
+    /*
+     * To accept this as an kBuild accessor, we require:
+     *   1. Open bracket.
+     *   2. At sign separating the type from the name.
+     *   3. Closing bracket.
+     *   4. At least one character following it.
+     */
+    if (cchExpr >= 1+1+1+1 && *pchExpr == '[')
+    {
+        pchExpr++;
+        cchExpr--;
+
+        pchTmp = memchr(pchExpr, '@', cchExpr);
+        if (pchTmp)
+        {
+            const char  * const pchType = pchExpr;
+            size_t        const cchType = pchTmp - pchExpr;
+
+            cchExpr -= cchType + 1;
+            pchExpr  = pchTmp + 1;
+            pchTmp = memchr(pchExpr, ']', cchExpr);
+            if (pchTmp)
+            {
+                const char * const pchObjName = pchExpr;
+                size_t       const cchObjName = pchTmp - pchExpr;
+
+                cchExpr -= cchObjName + 1;
+                pchExpr  = pchTmp + 1;
+                if (cchExpr > 0)
+                {
+
+                    /*
+                     * It's an kBuild define variable accessor, alright.
+                     */
+                    *pcchVarNm = cchExpr;
+                    *ppchVarNm = pchExpr;
+
+                    /* Deal with known special accessors: [@self]VAR, [@super]VAR. */
+                    if (cchType == 0)
+                    {
+                        int fSuper;
+
+                        if (WORD_IS(pchObjName, cchObjName, "self"))
+                            fSuper = 0;
+                        else if (WORD_IS(pchObjName, cchObjName, "super"))
+                            fSuper = 1;
+                        else
+                        {
+                            kbuild_report_problem(MAX(enmSeverity, kBuildSeverity_Error), pFileLoc,
+                                                  _("Invalid special kBuild object accessor: '%.*s'"),
+                                                  (int)cchOrgExpr, pchOrgExpr);
+                            if (penmType)
+                                *penmType = kBuildType_Invalid;
+                            return NULL;
+                        }
+                        if (g_pTopKbEvalData)
+                        {
+                            struct kbuild_object *pObj = g_pTopKbEvalData->pObj;
+                            struct kbuild_object *pParent;
+
+                            if (penmType)
+                                *penmType = pObj->enmType;
+
+                            if (!fSuper)
+                                return pObj;
+
+                            pParent = get_kbuild_object_parent(pObj, MAX(enmSeverity, kBuildSeverity_Error));
+                            if (pParent)
+                                return pParent;
+                        }
+                        else
+                            kbuild_report_problem(MAX(enmSeverity, kBuildSeverity_Error), pFileLoc,
+                                                  _("The '%.*s' accessor can only be used in the context of a kBuild object"),
+                                                  (int)cchOrgExpr, pchOrgExpr);
+                        if (penmType)
+                            *penmType = kBuildType_Invalid;
+                    }
+                    else
+                    {
+                        /* Genric accessor. Check the type and look up the object. */
+                        enum kBuildType enmType = eval_kbuild_type_from_string(pchType, cchType);
+                        if (penmType)
+                            *penmType = enmType;
+                        if (enmType != kBuildType_Invalid)
+                        {
+                            struct kbuild_object *pObj = lookup_kbuild_object(enmType, pchObjName, cchObjName);
+                            if (pObj)
+                                return pObj;
+
+                            /* failed. */
+                            kbuild_report_problem(enmSeverity, pFileLoc,
+                                                  _("kBuild object '%s' not found in kBuild variable accessor '%.*s'"),
+                                                  (int)cchObjName, pchObjName, (int)cchOrgExpr, pchOrgExpr);
+                        }
+                        else
+                            kbuild_report_problem(MAX(enmSeverity, kBuildSeverity_Error), pFileLoc,
+                                                  _("Invalid type '%.*s' specified in kBuild variable accessor '%.*s'"),
+                                                  (int)cchType, pchType, (int)cchOrgExpr, pchOrgExpr);
+                    }
+                    return NULL;
+                }
+            }
+        }
+    }
+
+    *ppchVarNm = NULL;
+    *pcchVarNm = 0;
+    if (penmType)
+        *penmType = kBuildType_Invalid;
+    return KOBJ_NOT_KBUILD_ACCESSOR;
+}
+
+/**
+ * Looks up a variable in a kBuild object.
+ *
+ * The caller has done minimal matching, i.e. starting square brackets and
+ * minimum length.  We do the rest here.
+ *
+ * @returns Pointer to the variable if found.
+ * @retval  NULL if not found.
+ * @retval  VAR_NOT_KBUILD_ACCESSOR if no a kBuild variable accessor.
+ *
+ * @param   pchName             The kBuild variable accessor expression.
+ * @param   cchName             Length of the expression.
+ */
+struct variable *
+lookup_kbuild_object_variable_accessor(const char *pchName, size_t cchName)
+{
+    const char * const     pchOrgName = pchName;
+    size_t       const     cchOrgName = cchName;
+    const char *           pchVarNm;
+    size_t                 cchVarNm;
+    struct kbuild_object  *pObj;
+
+    pObj = parse_kbuild_object_variable_accessor(pchName, cchName, kBuildSeverity_Warning, NULL, &pchVarNm, &cchVarNm, NULL);
+    if (pObj != KOBJ_NOT_KBUILD_ACCESSOR)
+    {
+        if (pObj)
+        {
+            /*
+             * Do the variable lookup.
+             */
+            const char *pszCachedName = strcache2_lookup(&variable_strcache, pchVarNm, cchVarNm);
+            if (pszCachedName)
+            {
+                struct variable  VarKey;
+                struct variable *pVar;
+                VarKey.name   = pszCachedName;
+                VarKey.length = cchName;
+
+                pVar = (struct variable *)hash_find_item_strcached(&pObj->pVariables->set->table, &VarKey);
+                if (pVar)
+                    return pVar;
+
+                /*
+                 * Not found, check ancestors if any.
+                 */
+                if (pObj->pszParent || pObj->pszTemplate)
+                {
+                    struct kbuild_object *pParent = pObj;
+                    for (;;)
+                    {
+                        pParent = resolve_kbuild_object_parent(pParent, 0 /*fQuiet*/);
+                        if (!pParent)
+                            break;
+                        pVar = (struct variable *)hash_find_item_strcached(&pParent->pVariables->set->table, &VarKey);
+                        if (pVar)
+                            return pVar;
+                    }
+                }
+            }
+        }
+
+        /* Not found one way or the other. */
+        return NULL;
+    }
+
+    /* Not a kBuild object variable accessor. */
+    return VAR_NOT_KBUILD_ACCESSOR;
+}
+
+/** @} */
+
+void print_kbuild_data_base(void)
+{
+    struct kbuild_object *pCur;
+
+    puts(_("\n# kBuild defines"));
+
+    for (pCur = g_pHeadKbObjs; pCur; pCur = pCur->pGlobalNext)
+    {
+        printf("\nkBuild-define-%s %s",
+               eval_kbuild_type_to_string(pCur->enmType), pCur->pszName);
+        if (pCur->pszParent)
+            printf(" extending %s", pCur->pszParent);
+        if (pCur->pszTemplate)
+            printf(" using %s", pCur->pszTemplate);
+        putchar('\n');
+
+        print_variable_set(pCur->pVariables->set, "");
+
+        printf("kBuild-endef-%s  %s\n",
+               eval_kbuild_type_to_string(pCur->enmType), pCur->pszName);
+    }
+    /** @todo hash stats. */
+}
+
+void print_kbuild_define_stats(void)
+{
+    /* later when hashing stuff */
+}
+
diff --git a/src/kmk/kbuild-read.c b/src/kmk/kbuild-read.c
deleted file mode 100644
index a8fd424..0000000
--- a/src/kmk/kbuild-read.c
+++ /dev/null
@@ -1,511 +0,0 @@
-/* $Id: kbuild-read.c 2549 2011-11-09 01:22:04Z bird $ */
-/** @file
- * kBuild specific make functionality related to read.c.
- */
-
-/*
- * Copyright (c) 2011 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
- *
- * This file is part of kBuild.
- *
- * kBuild is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * kBuild is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with kBuild.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/* No GNU coding style here! */
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#include "make.h"
-#include "filedef.h"
-#include "variable.h"
-#include "dep.h"
-#include "debug.h"
-#include "kbuild.h"
-
-#include <assert.h>
-
-
-/*******************************************************************************
-*   Defined Constants And Macros                                               *
-*******************************************************************************/
-#define WORD_IS(a_pszWord, a_cchWord, a_szWord2) \
-        (  (a_cchWord) == sizeof(a_szWord2) - 1 && memcmp((a_pszWord), a_szWord2, sizeof(a_szWord2) - 1) == 0)
-
-
-/*******************************************************************************
-*   Structures and Typedefs                                                    *
-*******************************************************************************/
-/** Indicate which kind of kBuild define we're working on.  */
-enum kBuildDef
-{
-    kBuildDef_Invalid,
-    kBuildDef_Target,
-    kBuildDef_Template,
-    kBuildDef_Tool,
-    kBuildDef_Sdk,
-    kBuildDef_Unit
-};
-
-enum kBuildExtendBy
-{
-    kBuildExtendBy_NoParent,
-    kBuildExtendBy_Overriding,
-    kBuildExtendBy_Appending,
-    kBuildExtendBy_Prepending
-};
-
-
-/**
- * The data we stack during eval.
- */
-struct kbuild_eval_data
-{
-    /** The kind of define. */
-    enum kBuildDef              enmKind;
-    /** The bare name of the define. */
-    char                       *pszName;
-    /** The file location where this define was declared. */
-    struct floc                 FileLoc;
-
-    /** Pointer to the next element in the global list. */
-    struct kbuild_eval_data    *pGlobalNext;
-    /** Pointer to the element below us on the stack. */
-    struct kbuild_eval_data    *pStackDown;
-
-    /** The variable set associated with this define. */
-    struct variable_set_list   *pVariables;
-    /** The saved current variable set, for restoring in kBuild-endef. */
-    struct variable_set_list   *pVariablesSaved;
-
-    /** The parent name, NULL if none. */
-    char                       *pszParent;
-    /** The inheritance method. */
-    enum kBuildExtendBy         enmExtendBy;
-    /** Pointer to the parent. Resolved lazily, so it can be NULL even if we have
-     *  a parent. */
-    struct kbuild_eval_data    *pParent;
-
-    /** The template, NULL if none. Only applicable to targets. */
-    char                       *pszTemplate;
-    /** Pointer to the template. Resolved lazily, so it can be NULL even if we have
-     *  a parent. */
-    struct kbuild_eval_data    *pTemplate;
-
-    /** The variable prefix.  */
-    char                       *pszVarPrefix;
-    /** The length of the variable prefix. */
-    size_t                      cchVarPrefix;
-};
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-/** Linked list (LIFO) of kBuild defines.
- * @todo use a hash! */
-struct kbuild_eval_data *g_pHeadKbDefs = NULL;
-/** Stack of kBuild defines. */
-struct kbuild_eval_data *g_pTopKbDef = NULL;
-
-
-struct variable_set *
-get_top_kbuild_variable_set(void)
-{
-    struct kbuild_eval_data *pTop = g_pTopKbDef;
-    assert(pTop != NULL);
-    return pTop->pVariables->set;
-}
-
-
-char *
-kbuild_prefix_variable(const char *pszName, unsigned int *pcchName)
-{
-    struct kbuild_eval_data *pTop = g_pTopKbDef;
-    char        *pszPrefixed;
-    unsigned int cchPrefixed;
-
-    assert(pTop != NULL);
-
-    cchPrefixed = pTop->cchVarPrefix + *pcchName;
-    pszPrefixed = xmalloc(cchPrefixed + 1);
-    memcpy(pszPrefixed, pTop->pszVarPrefix, pTop->cchVarPrefix);
-    memcpy(&pszPrefixed[pTop->cchVarPrefix], pszName, *pcchName);
-    pszPrefixed[cchPrefixed] = '\0';
-    *pcchName = cchPrefixed;
-    return pszPrefixed;
-}
-
-
-static const char *
-eval_kbuild_kind_to_string(enum kBuildDef enmKind)
-{
-    switch (enmKind)
-    {
-        case kBuildDef_Target:      return "target";
-        case kBuildDef_Template:    return "template";
-        case kBuildDef_Tool:        return "tool";
-        case kBuildDef_Sdk:         return "sdk";
-        case kBuildDef_Unit:        return "unit";
-        default:
-        case kBuildDef_Invalid:     return "invalid";
-    }
-}
-
-static char *
-allocate_expanded_next_token(const char **ppszCursor, const char *pszEos, unsigned int *pcchToken, int fStrip)
-{
-    unsigned int cchToken;
-    char *pszToken = find_next_token_eos(ppszCursor, pszEos, &cchToken);
-    if (pszToken)
-    {
-        pszToken = allocated_variable_expand_2(pszToken, cchToken, &cchToken);
-        if (pszToken)
-        {
-            if (fStrip)
-            {
-                unsigned int off = 0;
-                while (MY_IS_BLANK(pszToken[off]))
-                    off++;
-                if (off)
-                {
-                    cchToken -= off;
-                    memmove(pszToken, &pszToken[off], cchToken + 1);
-                }
-
-                while (cchToken > 0 && MY_IS_BLANK(pszToken[cchToken - 1]))
-                    pszToken[--cchToken] = '\0';
-            }
-
-            assert(cchToken == strlen(pszToken));
-            if (pcchToken)
-                *pcchToken = cchToken;
-        }
-    }
-    return pszToken;
-}
-
-static struct kbuild_eval_data *
-eval_kbuild_resolve_parent(struct kbuild_eval_data *pData)
-{
-    if (   !pData->pParent
-        && pData->pszParent)
-    {
-        struct kbuild_eval_data *pCur = g_pHeadKbDefs;
-        while (pCur)
-        {
-            if (   pCur->enmKind == pData->enmKind
-                && !strcmp(pCur->pszName, pData->pszParent))
-            {
-                if (    pCur->pszParent
-                    &&  (   pCur->pParent == pData
-                         || !strcmp(pCur->pszParent, pData->pszName)) )
-                    fatal(&pData->FileLoc, _("'%s' and '%s' are both trying to be each other children..."),
-                          pData->pszName, pCur->pszName);
-
-                pData->pParent = pCur;
-                pData->pVariables->next = pData->pVariables;
-                break;
-            }
-            pCur = pCur->pGlobalNext;
-        }
-    }
-    return pData->pParent;
-}
-
-static int
-eval_kbuild_define_xxxx(struct kbuild_eval_data **ppData, const struct floc *pFileLoc,
-                        const char *pszLine, const char *pszEos, int fIgnoring, enum kBuildDef enmKind)
-{
-    unsigned int            cch;
-    unsigned int            cchName;
-    char                    ch;
-    char                   *psz;
-    const char             *pszPrefix;
-    struct kbuild_eval_data *pData;
-
-    if (fIgnoring)
-        return 0;
-
-    /*
-     * Create a new kBuild eval data item.
-     */
-    pData = xmalloc(sizeof(*pData));
-    pData->enmKind          = enmKind;
-    pData->pszName          = NULL;
-    pData->FileLoc          = *pFileLoc;
-
-    pData->pGlobalNext      = g_pHeadKbDefs;
-    g_pHeadKbDefs           = pData;
-
-    pData->pStackDown       = *ppData;
-    *ppData = g_pTopKbDef   = pData;
-    pData->pVariables       = create_new_variable_set();
-    pData->pVariablesSaved  = NULL;
-
-    pData->pszParent        = NULL;
-    pData->enmExtendBy      = kBuildExtendBy_NoParent;
-    pData->pParent          = NULL;
-
-    pData->pszTemplate      = NULL;
-    pData->pTemplate        = NULL;
-
-    pData->pszVarPrefix     = NULL;
-    pData->cchVarPrefix     = 0;
-
-    /*
-     * The first word is the name.
-     */
-    pData->pszName = allocate_expanded_next_token(&pszLine, pszEos, &cchName, 1 /*strip*/);
-    if (!pData->pszName || !*pData->pszName)
-        fatal(pFileLoc, _("The kBuild define requires a name"));
-
-    psz = pData->pszName;
-    while ((ch = *psz++) != '\0')
-        if (!isgraph(ch))
-        {
-            error(pFileLoc, _("The 'kBuild-define-%s' name '%s' contains one or more invalid characters"),
-                  eval_kbuild_kind_to_string(enmKind), pData->pszName);
-            break;
-        }
-
-    /*
-     * Parse subsequent words.
-     */
-    psz = find_next_token_eos(&pszLine, pszEos, &cch);
-    while (psz)
-    {
-        if (WORD_IS(psz, cch, "extending"))
-        {
-            /* Inheritance directive. */
-            if (pData->pszParent != NULL)
-                fatal(pFileLoc, _("'extending' can only occure once"));
-            pData->pszParent = allocate_expanded_next_token(&pszLine, pszEos, &cch, 1 /*strip*/);
-            if (!pData->pszParent || !*pData->pszParent)
-                fatal(pFileLoc, _("'extending' requires a parent name"));
-
-            pData->enmExtendBy = kBuildExtendBy_Overriding;
-
-            /* optionally 'by overriding|prepending|appending' */
-            psz = find_next_token_eos(&pszLine, pszEos, &cch);
-            if (psz && WORD_IS(psz, cch, "by"))
-            {
-                cch = 0;
-                psz = find_next_token_eos(&pszLine, pszEos, &cch);
-                if (WORD_IS(psz, cch, "overriding"))
-                    pData->enmExtendBy = kBuildExtendBy_Overriding;
-                else if (WORD_IS(psz, cch, "appending"))
-                    pData->enmExtendBy = kBuildExtendBy_Appending;
-                else if (WORD_IS(psz, cch, "prepending"))
-                    pData->enmExtendBy = kBuildExtendBy_Prepending;
-                else
-                    fatal(pFileLoc, _("Unknown 'extending by' method '%.*s'"), (int)cch, psz);
-
-                /* next token */
-                psz = find_next_token_eos(&pszLine, pszEos, &cch);
-            }
-        }
-        else if (WORD_IS(psz, cch, "using"))
-        {
-            /* Template directive. */
-            if (enmKind != kBuildDef_Tool)
-                fatal(pFileLoc, _("'using <template>' can only be used with 'kBuild-define-target'"));
-            if (pData->pszTemplate != NULL)
-                fatal(pFileLoc, _("'using' can only occure once"));
-
-            pData->pszTemplate = allocate_expanded_next_token(&pszLine, pszEos, &cch, 1 /*fStrip*/);
-            if (!pData->pszTemplate || !*pData->pszTemplate)
-                fatal(pFileLoc, _("'using' requires a template name"));
-
-            /* next token */
-            psz = find_next_token_eos(&pszLine, pszEos, &cch);
-        }
-        else
-            fatal(pFileLoc, _("Don't know what '%.*s' means"), (int)cch, psz);
-    }
-
-    /*
-     * Calc the variable prefix.
-     */
-    switch (enmKind)
-    {
-        case kBuildDef_Target:      pszPrefix = ""; break;
-        case kBuildDef_Template:    pszPrefix = "TEMPLATE_"; break;
-        case kBuildDef_Tool:        pszPrefix = "TOOL_"; break;
-        case kBuildDef_Sdk:         pszPrefix = "SDK_"; break;
-        case kBuildDef_Unit:        pszPrefix = "UNIT_"; break;
-        default:
-            fatal(pFileLoc, _("enmKind=%d"), enmKind);
-            return -1;
-    }
-    cch = strlen(pszPrefix);
-    pData->cchVarPrefix = cch + cchName;
-    pData->pszVarPrefix = xmalloc(pData->cchVarPrefix + 1);
-    memcpy(pData->pszVarPrefix, pszPrefix, cch);
-    memcpy(&pData->pszVarPrefix[cch], pData->pszName, cchName);
-
-    /*
-     * Try resolve the parent and change the current variable set.
-     */
-    eval_kbuild_resolve_parent(pData);
-    pData->pVariablesSaved = current_variable_set_list;
-    current_variable_set_list = pData->pVariables;
-
-    return 0;
-}
-
-static int
-eval_kbuild_endef_xxxx(struct kbuild_eval_data **ppData, const struct floc *pFileLoc,
-                       const char *pszLine, const char *pszEos, int fIgnoring, enum kBuildDef enmKind)
-{
-    struct kbuild_eval_data *pData;
-    unsigned int             cchName;
-    char                    *pszName;
-
-    if (fIgnoring)
-        return 0;
-
-    /*
-     * Is there something to pop?
-     */
-    pData = *ppData;
-    if (!pData)
-    {
-        error(pFileLoc, _("kBuild-endef-%s is missing kBuild-define-%s"),
-              eval_kbuild_kind_to_string(enmKind), eval_kbuild_kind_to_string(enmKind));
-        return 0;
-    }
-
-    /*
-     * ... and does it have a matching kind?
-     */
-    if (pData->enmKind != enmKind)
-        error(pFileLoc, _("'kBuild-endef-%s' does not match 'kBuild-define-%s %s'"),
-              eval_kbuild_kind_to_string(enmKind), eval_kbuild_kind_to_string(pData->enmKind), pData->pszName);
-
-    /*
-     * The endef-kbuild may optionally be followed by the target name.
-     * It should match the name given to the kBuild-define.
-     */
-    pszName = allocate_expanded_next_token(&pszLine, pszEos, &cchName, 1 /*fStrip*/);
-    if (pszName)
-    {
-        if (strcmp(pszName, pData->pszName))
-            error(pFileLoc, _("'kBuild-endef-%s %s' does not match 'kBuild-define-%s %s'"),
-                  eval_kbuild_kind_to_string(enmKind), pszName,
-                  eval_kbuild_kind_to_string(pData->enmKind), pData->pszName);
-        free(pszName);
-    }
-
-    /*
-     * Pop a define off the stack.
-     */
-    assert(pData == g_pTopKbDef);
-    *ppData = g_pTopKbDef  = pData->pStackDown;
-    pData->pStackDown      = NULL;
-    current_variable_set_list = pData->pVariablesSaved;
-    pData->pVariablesSaved = NULL;
-
-    return 0;
-}
-
-int eval_kbuild_define(struct kbuild_eval_data **kdata, const struct floc *flocp,
-                       const char *word, unsigned int wlen, const char *line, const char *eos, int ignoring)
-{
-    assert(memcmp(word, "kBuild-define", sizeof("kBuild-define") - 1) == 0);
-    word += sizeof("kBuild-define") - 1;
-    wlen -= sizeof("kBuild-define") - 1;
-    if (   wlen > 1
-        && word[0] == '-')
-    {
-        if (WORD_IS(word, wlen, "-target"))
-            return eval_kbuild_define_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Target);
-        if (WORD_IS(word, wlen, "-template"))
-            return eval_kbuild_define_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Template);
-        if (WORD_IS(word, wlen, "-tool"))
-            return eval_kbuild_define_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Tool);
-        if (WORD_IS(word, wlen, "-sdk"))
-            return eval_kbuild_define_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Sdk);
-        if (WORD_IS(word, wlen, "-unit"))
-            return eval_kbuild_define_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Unit);
-    }
-
-    error(flocp, _("Unknown syntax 'kBuild-define%.*s'"), (int)wlen, word);
-    return 0;
-}
-
-int eval_kbuild_endef(struct kbuild_eval_data **kdata, const struct floc *flocp,
-                      const char *word, unsigned int wlen, const char *line, const char *eos, int ignoring)
-{
-    assert(memcmp(word, "kBuild-endef", sizeof("kBuild-endef") - 1) == 0);
-    word += sizeof("kBuild-endef") - 1;
-    wlen -= sizeof("kBuild-endef") - 1;
-    if (   wlen > 1
-        && word[0] == '-')
-    {
-        if (WORD_IS(word, wlen, "-target"))
-            return eval_kbuild_endef_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Target);
-        if (WORD_IS(word, wlen, "-template"))
-            return eval_kbuild_endef_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Template);
-        if (WORD_IS(word, wlen, "-tool"))
-            return eval_kbuild_endef_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Tool);
-        if (WORD_IS(word, wlen, "-sdk"))
-            return eval_kbuild_endef_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Sdk);
-        if (WORD_IS(word, wlen, "-unit"))
-            return eval_kbuild_endef_xxxx(kdata, flocp, line, eos,  ignoring, kBuildDef_Unit);
-    }
-
-    error(flocp, _("Unknown syntax 'kBuild-endef%.*s'"), (int)wlen, word);
-    return 0;
-}
-
-void print_kbuild_data_base(void)
-{
-    struct kbuild_eval_data *pCur;
-
-    puts(_("\n# kBuild defines"));
-
-    for (pCur = g_pHeadKbDefs; pCur; pCur = pCur->pGlobalNext)
-    {
-        printf("\nkBuild-define-%s %s",
-               eval_kbuild_kind_to_string(pCur->enmKind), pCur->pszName);
-        if (pCur->pszParent)
-        {
-            printf(" extending %s", pCur->pszParent);
-            switch (pCur->enmExtendBy)
-            {
-                case kBuildExtendBy_Overriding: break;
-                case kBuildExtendBy_Appending:  printf(" by appending"); break;
-                case kBuildExtendBy_Prepending: printf(" by prepending"); break;
-                default:                        printf(" by ?!?");
-            }
-        }
-        if (pCur->pszTemplate)
-            printf(" using %s", pCur->pszTemplate);
-        putchar('\n');
-
-        print_variable_set(pCur->pVariables->set, "");
-
-        printf("kBuild-endef-%s  %s\n",
-               eval_kbuild_kind_to_string(pCur->enmKind), pCur->pszName);
-    }
-    /** @todo hash stats. */
-}
-
-void print_kbuild_define_stats(void)
-{
-    /* later when hashing stuff */
-}
-
diff --git a/src/kmk/kbuild.h b/src/kmk/kbuild.h
index d911268..9fddde2 100644
--- a/src/kmk/kbuild.h
+++ b/src/kmk/kbuild.h
@@ -1,4 +1,4 @@
-/* $Id: kbuild.h 2549 2011-11-09 01:22:04Z bird $ */
+/* $Id: kbuild.h 2717 2013-12-30 00:58:43Z bird $ */
 /** @file
  * kBuild specific make functionality.
  */
@@ -38,18 +38,40 @@ const char *get_kbuild_path(void);
 const char *get_kbuild_bin_path(void);
 const char *get_default_kbuild_shell(void);
 
+/** @name kBuild objects
+ * @{ */
 struct kbuild_eval_data;
-extern struct kbuild_eval_data *g_pTopKbDef;
-struct variable_set *get_top_kbuild_variable_set(void);
-char *kbuild_prefix_variable(const char *pszName, unsigned int *pcchName);
+struct kbuild_object;
 
-int eval_kbuild_define(struct kbuild_eval_data **kdata, const struct floc *flocp,
-                       const char *word, unsigned int wlen, const char *line, const char *eos, int ignoring);
-int eval_kbuild_endef(struct kbuild_eval_data **kdata, const struct floc *flocp,
-                      const char *word, unsigned int wlen, const char *line, const char *eos, int ignoring);
+extern struct kbuild_eval_data *g_pTopKbEvalData;
 
-void print_kbuild_data_base(void);
-void print_kbuild_define_stats(void);
+
+/** Special return value indicating variable name isn't an accessor. */
+#define KOBJ_NOT_KBUILD_ACCESSOR    ( (struct kbuild_object *)~(size_t)0 )
+
+/** Special lookup_kbuild_object_variable return value. */
+#define VAR_NOT_KBUILD_ACCESSOR     ( (struct variable *)~(size_t)0 )
+
+struct variable    *lookup_kbuild_object_variable_accessor(const char *pchName, size_t cchName);
+int                 is_kbuild_object_variable_accessor(const char *pchName, size_t cchName);
+struct variable    *try_define_kbuild_object_variable_via_accessor(const char *pszName, size_t cchName,
+                                                                   const char *pszValue, size_t cchValue, int fDuplicateValue,
+                                                                   enum variable_origin enmOrigin, int fRecursive,
+                                                                   struct floc const *pFileLoc);
+struct variable    *define_kbuild_object_variable_in_top_obj(const char *pszName, size_t cchName,
+                                                             const char *pszValue, size_t cchValue, int fDuplicateValue,
+                                                             enum variable_origin enmOrigin, int fRecursive,
+                                                             struct floc const *pFileLoc);
+struct variable    *kbuild_object_variable_pre_append(const char *pchName, size_t cchName,
+                                                      const char *pchValue, size_t cchValue, int fSimpleValue,
+                                                      enum variable_origin enmOrigin, int fAppend,
+                                                      const struct floc *pFileLoc);
+int                 eval_kbuild_read_hook(struct kbuild_eval_data **kdata, const struct floc *flocp,
+                                          const char *word, size_t wlen, const char *line, const char *eos, int ignoring);
+void                print_kbuild_data_base(void);
+void                print_kbuild_define_stats(void);
+void                init_kbuild_object(void);
+/** @} */
 
 #endif
 
diff --git a/src/kmk/kmkbuiltin/cp.c b/src/kmk/kmkbuiltin/cp.c
index 9622cd1..f1811b5 100644
--- a/src/kmk/kmkbuiltin/cp.c
+++ b/src/kmk/kmkbuiltin/cp.c
@@ -82,7 +82,7 @@ __FBSDID("$FreeBSD: src/bin/cp/cp.c,v 1.50 2004/04/06 20:06:44 markm Exp $");
 #include "kbuild_protection.h"
 
 #if defined(_MSC_VER) || defined(__gnu_linux__) || defined(__linux__)
-extern char *strlcpy(char *, const char *, size_t);
+extern size_t strlcpy(char *, const char *, size_t);
 #endif
 
 
diff --git a/src/kmk/kmkbuiltin/fts.c b/src/kmk/kmkbuiltin/fts.c
index 9860f67..133efb4 100644
--- a/src/kmk/kmkbuiltin/fts.c
+++ b/src/kmk/kmkbuiltin/fts.c
@@ -126,12 +126,14 @@ static int	 fts_palloc(FTS *, size_t);
 static void	 fts_padjust(FTS *, FTSENT *);
 static FTSENT	*fts_sort(FTS *, FTSENT *, size_t);
 static u_short	 fts_stat(FTS *, FTSENT *, int);
+#ifdef _MSC_VER
+static u_short   fts_stat_dirent(FTS *sp, FTSENT *p, int follow, struct dirent *pDirEnt);
+#endif
 static int	 fts_safe_changedir(const FTS *, const FTSENT *, int,
     const char *);
 
 #ifdef _MSC_VER
-#undef HAVE_STRUCT_DIRENT_D_NAMLEN
-#undef HAVE_FCHDIR
+# undef HAVE_FCHDIR
 #endif
 
 #if defined(__EMX__) || defined(_MSC_VER)
@@ -386,7 +388,7 @@ fts_close(sp)
 #else
 		if (chdir(sp->fts_rdir))
 			saved_errno =  errno;
-        free(sp->fts_rdir);
+		free(sp->fts_rdir);
 		sp->fts_rdir = NULL;
 #endif
 	}
@@ -785,6 +787,8 @@ fts_build(sp, type)
 		oflag = DTF_NODUP|DTF_REWIND;
 	else
 		oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
+#elif defined(_MSC_VER)
+# define __opendir2(path, flag) birdDirOpenExtraInfo(path)
 #else
 #define __opendir2(path, flag) opendir(path)
 #endif
@@ -940,8 +944,13 @@ mem1:				saved_errno = errno;
 				        (size_t)(p->fts_namelen + 1));
 			} else
 				p->fts_accpath = p->fts_name;
+
 			/* Stat it. */
+#ifdef _MSC_VER
+			p->fts_info = fts_stat_dirent(sp, p, 0, dp);
+#else
 			p->fts_info = fts_stat(sp, p, 0);
+#endif
 
 			/* Decrement link count if applicable. */
 			if (nlinks > 0 && (p->fts_info == FTS_D ||
@@ -1011,6 +1020,87 @@ mem1:				saved_errno = errno;
 	return (head);
 }
 
+#ifdef _MSC_VER
+/** Special version of fts_stat that takes the information from the directory
+ *  entry returned by readdir().
+ *
+ *  Directory listing returns all the stat information on systems likes
+ *  Windows and OS/2. */
+static u_short
+fts_stat_dirent(FTS *sp, FTSENT *p, int follow, struct dirent *pDirEnt)
+{
+	FTSENT *t;
+	dev_t dev;
+	ino_t ino;
+	struct STAT *sbp, sb;
+	int saved_errno;
+
+	_DIAGASSERT(sp != NULL);
+	_DIAGASSERT(p != NULL);
+
+	/* If user needs stat info, stat buffer already allocated. */
+	sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
+
+	/*
+	 * Copy over the stat info from the direntry.
+	 */
+	*sbp = pDirEnt->d_stat;
+
+	/*
+	 * If doing a logical walk, or application requested FTS_FOLLOW, do
+	 * a stat(2) on symlinks.  If that fails, assume non-existent
+	 * symlink and set the errno from the stat call.
+	 */
+	if (S_ISLNK(sbp->st_mode) && (ISSET(FTS_LOGICAL) || follow)) {
+		if (stat(p->fts_accpath, sbp)) {
+			saved_errno = errno;
+			errno = 0;
+			return (FTS_SLNONE);
+		}
+	}
+
+	if (S_ISDIR(sbp->st_mode)) {
+		/*
+		 * Set the device/inode.  Used to find cycles and check for
+		 * crossing mount points.  Also remember the link count, used
+		 * in fts_build to limit the number of stat calls.  It is
+		 * understood that these fields are only referenced if fts_info
+		 * is set to FTS_D.
+		 */
+		dev = p->fts_dev = sbp->st_dev;
+		ino = p->fts_ino = sbp->st_ino;
+		p->fts_nlink = sbp->st_nlink;
+
+		if (ISDOT(p->fts_name))
+			return (FTS_DOT);
+
+		/*
+		 * Cycle detection is done by brute force when the directory
+		 * is first encountered.  If the tree gets deep enough or the
+		 * number of symbolic links to directories is high enough,
+		 * something faster might be worthwhile.
+		 */
+
+#ifdef _MSC_VER
+		if (ino && dev) /** @todo ino emulation on windows... */
+#endif
+		    for (t = p->fts_parent;
+			t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
+			    if (ino == t->fts_ino && dev == t->fts_dev) {
+				    p->fts_cycle = t;
+				    return (FTS_DC);
+			    }
+		return (FTS_D);
+	}
+	if (S_ISLNK(sbp->st_mode))
+		return (FTS_SL);
+	if (S_ISREG(sbp->st_mode))
+		return (FTS_F);
+	return (FTS_DEFAULT);
+}
+
+#endif /* fts_stat_dirent */
+
 static u_short
 fts_stat(sp, p, follow)
 	FTS *sp;
diff --git a/src/kmk/kmkbuiltin/mscfakes.c b/src/kmk/kmkbuiltin/mscfakes.c
index 3f472c9..444943e 100644
--- a/src/kmk/kmkbuiltin/mscfakes.c
+++ b/src/kmk/kmkbuiltin/mscfakes.c
@@ -1,4 +1,4 @@
-/* $Id: mscfakes.c 2645 2012-09-09 02:29:23Z bird $ */
+/* $Id: mscfakes.c 2733 2014-10-16 18:29:41Z bird $ */
 /** @file
  * Fake Unix stuff for MSC.
  */
@@ -108,8 +108,8 @@ msc_fix_path(const char **ppszPath, int *pfMustBeDir)
 }
 
 
-static int
-msc_set_errno(DWORD dwErr)
+int
+birdSetErrno(unsigned dwErr)
 {
     switch (dwErr)
     {
@@ -183,7 +183,7 @@ int lchmod(const char *pszPath, mode_t mode)
      */
     DWORD fAttr = GetFileAttributes(pszPath);
     if (fAttr == INVALID_FILE_ATTRIBUTES)
-        rc = msc_set_errno(GetLastError());
+        rc = birdSetErrno(GetLastError());
     else if (fMustBeDir & !(fAttr & FILE_ATTRIBUTE_DIRECTORY))
     {
         errno = ENOTDIR;
@@ -199,7 +199,7 @@ int lchmod(const char *pszPath, mode_t mode)
         else
             fAttr |= FILE_ATTRIBUTE_READONLY;
         if (!SetFileAttributes(pszPath, fAttr))
-            rc = msc_set_errno(GetLastError());
+            rc = birdSetErrno(GetLastError());
     }
 
     if (pszPathFree)
@@ -223,7 +223,7 @@ int msc_chmod(const char *pszPath, mode_t mode)
      */
     DWORD fAttr = GetFileAttributes(pszPath);
     if (fAttr == INVALID_FILE_ATTRIBUTES)
-        rc = msc_set_errno(GetLastError());
+        rc = birdSetErrno(GetLastError());
     else if (fMustBeDir & !(fAttr & FILE_ATTRIBUTE_DIRECTORY))
     {
         errno = ENOTDIR;
@@ -244,7 +244,7 @@ int msc_chmod(const char *pszPath, mode_t mode)
         else
             fAttr |= FILE_ATTRIBUTE_READONLY;
         if (!SetFileAttributes(pszPath, fAttr))
-            rc = msc_set_errno(GetLastError());
+            rc = birdSetErrno(GetLastError());
     }
 
     if (pszPathFree)
@@ -282,7 +282,7 @@ int link(const char *pszDst, const char *pszLink)
 
     if (s_pfnCreateHardLinkA(pszLink, pszDst, NULL))
         return 0;
-    return msc_set_errno(GetLastError());
+    return birdSetErrno(GetLastError());
 }
 
 
@@ -534,43 +534,59 @@ int vasprintf(char **strp, const char *fmt, va_list va)
 }
 
 
-/*
- * Workaround for directory names with trailing slashes.
+/**
+ * This is a kludge to make pipe handles blocking.
+ *
+ * @returns TRUE if it's now blocking, FALSE if not a pipe or we failed to fix
+ *          the blocking mode.
+ * @param   fd                  The libc file descriptor number.
  */
-#undef stat
-int
-bird_w32_stat(const char *path, struct stat *st)
+static BOOL makePipeBlocking(int fd)
 {
-    int rc = stat(path, st);
-    if (    rc != 0
-        &&  errno == ENOENT
-        &&  *path != '\0')
+    /* Is pipe? */
+    HANDLE hFile = (HANDLE)_get_osfhandle(fd);
+    if (hFile != INVALID_HANDLE_VALUE)
     {
-        char *slash = strchr(path, '\0') - 1;
-        if (*slash == '/' || *slash == '\\')
+        DWORD fType = GetFileType(hFile);
+        fType &= ~FILE_TYPE_REMOTE;
+        if (fType == FILE_TYPE_PIPE)
         {
-            size_t len_path = slash - path + 1;
-            char *tmp = alloca(len_path + 4);
-            memcpy(tmp, path, len_path);
-            tmp[len_path] = '.';
-            tmp[len_path + 1] = '\0';
-            errno = 0;
-            rc = stat(tmp, st);
-            if (    rc == 0
-                &&  !S_ISDIR(st->st_mode))
+            /* Try fix it. */
+            DWORD fState = 0;
+            if (GetNamedPipeHandleState(hFile, &fState, NULL, NULL, NULL, NULL,  0))
             {
-                errno = ENOTDIR;
-                rc = -1;
+                fState &= ~PIPE_NOWAIT;
+                fState |= PIPE_WAIT;
+                if (SetNamedPipeHandleState(hFile, &fState, NULL, NULL))
+                    return TRUE;
             }
         }
     }
-#ifdef KMK_PRF
-    {
-        int err = errno;
-        fprintf(stderr, "stat(%s,) -> %d/%d\n", path, rc, errno);
-        errno = err;
-    }
-#endif
-    return rc;
+    return FALSE;
+}
+
+
+/**
+ * Initializes the msc fake stuff.
+ * @returns 0 on success (non-zero would indicate failure, see rterr.h).
+ */
+int mscfake_init(void)
+{
+    /*
+     * Kludge against _write returning ENOSPC on non-blocking pipes.
+     */
+    makePipeBlocking(STDOUT_FILENO);
+    makePipeBlocking(STDERR_FILENO);
+
+    return 0;
 }
 
+/*
+ * Do this before main is called.
+ */
+#pragma section(".CRT$XIA", read)
+#pragma section(".CRT$XIU", read)
+#pragma section(".CRT$XIZ", read)
+typedef int (__cdecl *PFNCRTINIT)(void);
+static __declspec(allocate(".CRT$XIU")) PFNCRTINIT g_MscFakeInitVectorEntry = mscfake_init;
+
diff --git a/src/kmk/kmkbuiltin/mscfakes.h b/src/kmk/kmkbuiltin/mscfakes.h
index ec0edb5..e5a2e99 100644
--- a/src/kmk/kmkbuiltin/mscfakes.h
+++ b/src/kmk/kmkbuiltin/mscfakes.h
@@ -1,4 +1,4 @@
-/* $Id: mscfakes.h 2592 2012-06-17 22:50:38Z bird $ */
+/* $Id: mscfakes.h 2713 2013-11-21 21:11:00Z bird $ */
 /** @file
  * Unix fakes for MSC.
  */
@@ -38,44 +38,13 @@
 #include <sys/stat.h>
 #include <io.h>
 #include <direct.h>
+#include "nt/ntstat.h"
+#include "nt/ntunlink.h"
 #if defined(MSC_DO_64_BIT_IO) && _MSC_VER >= 1400 /* We want 64-bit file lengths here when possible. */
 # define off_t __int64
-# undef stat
-# define stat  _stat64
-# define fstat _fstat64
 # define lseek _lseeki64
-#else
-# ifndef STAT_REDEFINED_ALREADY
-#  define STAT_REDEFINED_ALREADY
-#  undef stat
-#  define stat(_path, _st) bird_w32_stat(_path, _st)
-extern int bird_w32_stat(const char *, struct stat *);
-# endif
 #endif
 
-#ifndef S_ISDIR
-# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
-#endif
-#ifndef S_ISREG
-# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
-#endif
-#define S_ISLNK(m)  0
-#define	S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
-#define	S_IXUSR _S_IEXEC
-#define	S_IWUSR _S_IWRITE
-#define	S_IRUSR _S_IREAD
-#define S_IRWXG 0000070
-#define S_IRGRP	0000040
-#define S_IWGRP	0000020
-#define S_IXGRP 0000010
-#define S_IRWXO 0000007
-#define S_IROTH	0000004
-#define S_IWOTH	0000002
-#define S_IXOTH 0000001
-#define	S_ISUID 0004000
-#define	S_ISGID 0002000
-#define ALLPERMS 0000777
-
 #undef  PATH_MAX
 #define PATH_MAX   _MAX_PATH
 #undef  MAXPATHLEN
@@ -140,7 +109,6 @@ char *dirname(char *path);
 #define fchmod(fd, mode) 0              /** @todo implement fchmod! */
 #define geteuid()  0
 #define getegid()  0
-#define lstat(path, s) stat(path, s)
 int lchmod(const char *path, mode_t mode);
 int msc_chmod(const char *path, mode_t mode);
 #define chmod msc_chmod
@@ -171,6 +139,13 @@ int symlink(const char *pszDst, const char *pszLink);
 int utimes(const char *pszPath, const struct timeval *paTimes);
 int writev(int fd, const struct iovec *vector, int count);
 
+
+
+/*
+ * MSC fake internals / helpers.
+ */
+int birdSetErrno(unsigned dwErr);
+
 #endif /* _MSC_VER */
 #endif
 
diff --git a/src/kmk/kmkbuiltin/redirect.c b/src/kmk/kmkbuiltin/redirect.c
index fee7828..cbcbb18 100644
--- a/src/kmk/kmkbuiltin/redirect.c
+++ b/src/kmk/kmkbuiltin/redirect.c
@@ -1,10 +1,10 @@
-/* $Id: redirect.c 2684 2013-06-19 11:01:48Z bird $ */
+/* $Id: redirect.c 2728 2014-03-05 13:09:47Z bird $ */
 /** @file
  * kmk_redirect - Do simple program <-> file redirection (++).
  */
 
 /*
- * Copyright (c) 2007-2012 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ * Copyright (c) 2007-2014 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
  *
  * This file is part of kBuild.
  *
@@ -72,11 +72,17 @@ static void quoteArguments(int argc, char **argv)
         const char *pszQuotes = (const char *)memchr(pszOrg, '"', cchOrg);
         if (   pszQuotes
             || cchOrg == 0
+            || memchr(pszOrg, ' ', cchOrg)
+            || memchr(pszOrg, '\t', cchOrg)
+            || memchr(pszOrg, '\n', cchOrg)
+            || memchr(pszOrg, '\r', cchOrg)
             || memchr(pszOrg, '&', cchOrg)
             || memchr(pszOrg, '>', cchOrg)
             || memchr(pszOrg, '<', cchOrg)
             || memchr(pszOrg, '|', cchOrg)
             || memchr(pszOrg, '%', cchOrg)
+            || memchr(pszOrg, '\'', cchOrg)
+            || memchr(pszOrg, '=', cchOrg)
             )
         {
             char   ch;
@@ -133,7 +139,7 @@ static void quoteArguments(int argc, char **argv)
         }
     }
 
-    /*for (i = 0; i < argc; i++) printf("argv[%u]=%s;;\n", i, argv[i]); */
+    /*for (i = 0; i < argc; i++) fprintf(stderr, "argv[%u]=%s;;\n", i, argv[i]);*/
 }
 #endif /* _MSC_VER */
 
@@ -310,10 +316,40 @@ int main(int argc, char **argv, char **envp)
                 }
                 else
 #endif /* __OS2__ */
-                if (putenv(psz))
                 {
-                    fprintf(pStdErr, "%s: error: putenv(\"%s\"): %s\n", name(argv[0]), psz, strerror(errno));
-                    return 1;
+                    const char *pchEqual = strchr(psz, '=');
+                    if (pchEqual && pchEqual[1] != '\0')
+                    {
+                        if (putenv(psz))
+                        {
+                            fprintf(pStdErr, "%s: error: putenv(\"%s\"): %s\n", name(argv[0]), psz, strerror(errno));
+                            return 1;
+                        }
+                    }
+                    else
+                    {
+                        size_t cchVar = pchEqual ? (size_t)(pchEqual - psz) : strlen(psz);
+                        char *pszCopy = (char *)malloc(cchVar + 2);
+                        memcpy(pszCopy, psz, cchVar);
+
+#if defined(_MSC_VER) || defined(__OS2__)
+                        pszCopy[cchVar] = '=';
+                        pszCopy[cchVar + 1] = '\0';
+                        if (putenv(pszCopy))
+                        {
+                            fprintf(pStdErr, "%s: error: putenv(\"%s\"): %s\n", name(argv[0]), pszCopy, strerror(errno));
+                            return 1;
+                        }
+#else
+                        pszCopy[cchVar] = '\0';
+                        if (unsetenv(pszCopy))
+                        {
+                            fprintf(pStdErr, "%s: error: unsetenv(\"%s\"): %s\n", name(argv[0]), pszCopy, strerror(errno));
+                            return 1;
+                        }
+#endif
+                        free(pszCopy);
+                    }
                 }
                 continue;
             }
diff --git a/src/kmk/kmkbuiltin/rm.c b/src/kmk/kmkbuiltin/rm.c
index e74d5b6..17b7ca2 100644
--- a/src/kmk/kmkbuiltin/rm.c
+++ b/src/kmk/kmkbuiltin/rm.c
@@ -66,8 +66,14 @@ static char sccsid[] = "@(#)rm.c	8.5 (Berkeley) 4/18/94";
 #ifdef __HAIKU__
 # include "haikufakes.h"
 #endif
-#ifdef _MSC_VER
-# include "mscfakes.h"
+#ifdef KBUILD_OS_WINDOWS
+# ifdef _MSC_VER
+#  include "mscfakes.h"
+# endif
+# include "nt/ntunlink.h"
+  /* Use the special unlink implementation to do rmdir too. */
+# undef  rmdir
+# define rmdir(a_pszPath) 	birdUnlinkForced(a_pszPath)
 #endif
 #if defined(__OS2__) || defined(_MSC_VER)
 # include <direct.h>
@@ -76,7 +82,7 @@ static char sccsid[] = "@(#)rm.c	8.5 (Berkeley) 4/18/94";
 #include "kmkbuiltin.h"
 #include "kbuild_protection.h"
 
-#if defined(__EMX__) || defined(_MSC_VER)
+#if defined(__EMX__) || defined(KBUILD_OS_WINDOWS)
 # define IS_SLASH(ch)   ( (ch) == '/' || (ch) == '\\' )
 # define HAVE_DOS_PATHS 1
 # define DEFAULT_PROTECTION_DEPTH 1
@@ -99,6 +105,9 @@ static char sccsid[] = "@(#)rm.c	8.5 (Berkeley) 4/18/94";
 extern void bsd_strmode(mode_t mode, char *p);
 
 static int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
+#ifdef KBUILD_OS_WINDOWS
+static int fUseNtDeleteFile;
+#endif
 static uid_t uid;
 
 static char *argv0;
@@ -113,6 +122,9 @@ static struct option long_options[] =
     { "enable-full-protection",				no_argument, 0, 265 },
     { "disable-full-protection",			no_argument, 0, 266 },
     { "protection-depth",				required_argument, 0, 267 },
+#ifdef KBUILD_OS_WINDOWS
+    { "nt-delete-file",					no_argument, 0, 268 },
+#endif
     { 0, 0,	0, 0 },
 };
 
@@ -148,6 +160,9 @@ kmk_builtin_rm(int argc, char *argv[], char **envp)
 	/* reinitialize globals */
 	argv0 = argv[0];
 	dflag = eval = fflag = iflag = Pflag = vflag = Wflag = stdin_ok = 0;
+#ifdef KBUILD_OS_WINDOWS
+	fUseNtDeleteFile = 0;
+#endif
 	uid = 0;
 	kBuildProtectionInit(&g_ProtData);
 
@@ -214,6 +229,11 @@ kmk_builtin_rm(int argc, char *argv[], char **envp)
 			    return 1;
 			}
 			break;
+#ifdef KBUILD_OS_WINDOWS
+		case 268:
+			fUseNtDeleteFile = 1;
+			break;
+#endif
 		case '?':
 		default:
 			kBuildProtectionTerm(&g_ProtData);
@@ -403,12 +423,10 @@ rm_tree(char **argv)
 				if (Pflag)
 					if (!rm_overwrite(p->fts_accpath, NULL))
 						continue;
+#ifdef KBUILD_OS_WINDOWS
+				rval = birdUnlinkForcedFast(p->fts_accpath);
+#else
 				rval = unlink(p->fts_accpath);
-#ifdef _MSC_VER
-				if (rval != 0) {
-    					chmod(p->fts_accpath, 0777);
-					rval = unlink(p->fts_accpath);
-				}
 #endif
 
 				if (rval == 0 || (fflag && errno == ENOENT)) {
@@ -505,14 +523,18 @@ rm_file(char **argv)
 				if (Pflag)
 					if (!rm_overwrite(f, &sb))
 						continue;
+#ifndef KBUILD_OS_WINDOWS
 				rval = unlink(f);
-#ifdef _MSC_VER
-				if (rval != 0) {
-					chmod(f, 0777);
-					rval = unlink(f);
+				operation = "unlink";
+#else
+				if (fUseNtDeleteFile) {
+					rval = birdUnlinkForcedFast(f);
+					operation = "NtDeleteFile";
+				} else {
+					rval = birdUnlinkForced(f);
+					operation = "unlink";
 				}
 #endif
-				operation = "unlink";
 			}
 		}
 		if (rval && (!fflag || errno != ENOENT)) {
diff --git a/src/kmk/main.c b/src/kmk/main.c
index a1e8a63..06a6cc0 100644
--- a/src/kmk/main.c
+++ b/src/kmk/main.c
@@ -1579,6 +1579,9 @@ main (int argc, char **argv, char **envp)
   initialize_global_alloc_caches ();
 #endif
   initialize_global_hash_tables ();
+#ifdef KMK
+  init_kbuild_object ();
+#endif
 
   /* Figure out where we are.  */
 
@@ -3743,7 +3746,7 @@ print_version (void)
 #ifdef KMK
   printf ("\n\
 %skBuild modifications:\n\
-%s Copyright (c) 2005-2009 knut st. osmundsen.\n\
+%s Copyright (c) 2005-2013 knut st. osmundsen.\n\
 \n\
 %skmkbuiltin commands derived from *BSD sources:\n\
 %s Copyright (c) 1983 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994\n\
diff --git a/src/kmk/read.c b/src/kmk/read.c
index ebc6a63..413df56 100644
--- a/src/kmk/read.c
+++ b/src/kmk/read.c
@@ -955,21 +955,17 @@ eval (struct ebuffer *ebuf, int set_default)
 
 #ifdef KMK
       /* Check for the kBuild language extensions. */
-      if (   wlen >= sizeof("kBuild-define") - 1
-          && strneq (p, "kBuild-define", sizeof("kBuild-define") - 1))
-        krc = eval_kbuild_define (&kdata, fstart, p, wlen, p2, eol, ignoring);
-      else if (   wlen >= sizeof("kBuild-endef") - 1
-               && strneq (p, "kBuild-endef", sizeof("kBuild-endef") - 1))
-        krc = eval_kbuild_endef (&kdata, fstart, p, wlen, p2, eol, ignoring);
-      else
-        krc = 42;
-      if (krc != 42)
+      if (   wlen > sizeof("kBuild-")
+          && strneq (p, "kBuild-", sizeof("kBuild-") - 1))
         {
-          if (krc != 0)
-            error (fstart, _("krc=%d"), krc);
-          continue;
+          krc = eval_kbuild_read_hook (&kdata, fstart, p, wlen, p2, eol, ignoring);
+          if (krc != 42)
+            {
+              if (krc != 0)
+                error (fstart, _("krc=%d"), krc);
+              continue;
+            }
         }
-
 #endif /* KMK */
 
       /* Manage the "export" keyword used outside of variable assignment
@@ -1845,7 +1841,14 @@ do_define (char *name IF_WITH_VALUE_LENGTH_PARAM(char *eos),
   else
     definition[idx - 1] = '\0';
 
+#ifndef CONFIG_WITH_VALUE_LENGTH
   v = do_variable_definition (&defstart, name, definition, origin, flavor, 0);
+#else
+  v = do_variable_definition_2 (&defstart, name, definition,
+                                idx ? idx - 1 : idx,  flavor == f_simple,
+                                0 /* free_value */, origin, flavor,
+                                0 /*target_var*/);
+#endif
   free (definition);
   free (var);
   return (v);
diff --git a/src/kmk/testcase-kBuild-define.kmk b/src/kmk/testcase-kBuild-define.kmk
index c9edd18..1074e72 100644
--- a/src/kmk/testcase-kBuild-define.kmk
+++ b/src/kmk/testcase-kBuild-define.kmk
@@ -1,10 +1,10 @@
-# $Id: testcase-kBuild-define.kmk 2658 2012-09-10 21:00:10Z bird $
+# $Id: testcase-kBuild-define.kmk 2720 2014-01-01 22:59:50Z bird $
 ## @file
 # kBuild - testcase for the kBuild-define-* directives.
 #
 
 #
-# Copyright (c) 2011-2012 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2011-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -23,50 +23,119 @@
 #
 #
 
-DEPTH = ../..
+#DEPTH = ../..
 #include $(PATH_KBUILD)/header.kmk
 
+##
+# Test if $($1) == $2 and raises an error if it isn't.
+#
+# @param   1   Something to apply '$' to.
+# @param   2   The expected value.
+TEST_EQ = $(if-expr "$($1)" == "$2",,$(error $1 is '$($1)' not '$2'))
+
+if 0
 # object definition syntax:
-#      kobject <type> <name> [extends <object>] [object specific args...]
-#      endkobj [<type> [name]]
+#      kobject <type> <name> [extends <object> [by <||>]] [object specific args...]
+#      kendobj [<type> [name]]
 kobject kb-target MyTarget
 .TOOL = GCC
 .SOURCES = file.c
-endobj
+kendobj
+else
+# Target definition.
+#      kBuild-define-target <name> [extends <target> [by <||>]] [using <template>]
+#      kBuild-endef-target [name]
+kBuild-define-target MyTarget
+_TOOL = GCC
+_SOURCES = file.c
+kBuild-endef-target
+endif
 
+if 0
 # accesses an already defined object.
 # syntax:
 #      kaccess <type> <name>
-#      endkacc [<type> [name]]
+#      kendacc [<type> [name]]
 kaccess kb-target MyTarget
 .SOURCES += file2.c
-endkacc
+kendacc
+else
+#kBuild-access-target MyTarget
+#_SOURCES += file2.c
+#kBuild-endacc-target
+endif
 
 
 # Referencing an object variable, the object must exist.
 # syntax: [<type>@<name>].<property>
-[kb-target at MyTarget].SOURCES += file3.c
-$(info [kb-target at MyTarget].SOURCES is $([kb-target at MyTarget].SOURCES))
+[target at MyTarget]_SOURCES += file3.c
+$(info [target at MyTarget]_SOURCES is $([target at MyTarget]_SOURCES))
 
 
 # Test #1
-kobject target BaseTarget with DUMMY as template
-.SOURCES = BaseTargetSource.c
-kendobj
-$(if "$([target at BaseTarget].SOURCES)" == "BaseTargetSource.c",,$(error [target at BaseTarget].SOURCES is '$([target at BaseTarget].SOURCES)' not 'BaseTargetSource.c'))
-$(if "$(BaseTarget_SOURCES)" == "BaseTargetSource.c",,$(error BaseTarget's _SOURCES wasn't set correctly in the global space))
+kBuild-define-target BaseTarget using DUMMY
+_SOURCES = BaseTargetSource.c
+kBuild-endef-target BaseTarget
+$(if-expr "$([target at BaseTarget]_SOURCES)" == "BaseTargetSource.c",,$(error [target at BaseTarget]_SOURCES is '$([target at BaseTarget]_SOURCES)' not 'BaseTargetSource.c'))
+$(if-expr "$(BaseTarget_SOURCES)" == "BaseTargetSource.c",,$(error BaseTarget's _SOURCES wasn't set correctly in the global space))
 
-$(if "$([target at BaseTarget].TEMPLATE)" == "DUMMY",,$(error [target at BaseTarget].TEMPLATE is '$([target at BaseTarget].TEMPLATE)' not 'DUMMY'))
-$(if "$(BaseTarget_TEMPLATE)" == "DUMMY",,$(error BaseTarget's _TEMPLATE wasn't set correctly in the global space))
+$(if-expr "$([target at BaseTarget]_TEMPLATE)" == "DUMMY",,$(error [target at BaseTarget]_TEMPLATE is '$([target at BaseTarget]_TEMPLATE)' not 'DUMMY'))
+$(if-expr "$(BaseTarget_TEMPLATE)" == "DUMMY",,$(error BaseTarget's _TEMPLATE wasn't set correctly in the global space))
 
 # Test #2
-kobject target TargetWithLocals
-local .LOCAL_PROP = no global alias
-kendobj
-$(if "$([target at TargetWithLocals].LOCAL_PROP)" == "no global alias",,$(error [target at TargetWithLocals].LOCAL_PROP is '$([target at TargetWithLocals].LOCAL_PROP)' not 'no global alias'))
-$(if "$(TargetWithLocals_LOCAL_PROP)" == "",,$(error TargetWithLocals_LOCAL_PROP's local property 'LOCAL_PROP' was exposed globally.))
+kBuild-define-target TargetWithLocals
+local _LOCAL_PROP = no global alias
+kBuild-endef-target
+$(if-expr "$([target at TargetWithLocals]_LOCAL_PROP)" == "no global alias",,$(error [target at TargetWithLocals]_LOCAL_PROP is '$([target at TargetWithLocals]_LOCAL_PROP)' not 'no global alias'))
+$(if-expr "$(TargetWithLocals_LOCAL_PROP)" == "",,$(error TargetWithLocals_LOCAL_PROP's local property 'LOCAL_PROP' was exposed globally.))
+
+# Test #3
+kBuild-define-target OutsideMod
+_SOURCES = file3.c
+_OTHER   = inside-value
+kBuild-endef-target
+[target at OutsideMod]_SOURCES += file4.c
+[target at OutsideMod]_SOURCES <= file2.c
+[target at OutsideMod]_OTHER   = outside-value
+$(if-expr "$([target at OutsideMod]_SOURCES)" == "file2.c file3.c file4.c",,$(error [target at OutsideMod]_SOURCES is '$([target at OutsideMod]_SOURCES)' not 'file2.c file3.c file4.c'))
+$(if-expr "$(OutsideMod_SOURCES)"          == "file2.c file3.c file4.c",,$(error OutsideMod_SOURCES is '$(OutsideMod_SOURCES)' not 'file2.c file3.c file4.c'))
+
+$(if-expr "$([target at OutsideMod]_OTHER)" == "outside-value",,$(error [target at OutsideMod]_OTHER is '$([target at OutsideMod]_OTHER)' not 'outside-value'))
+$(if-expr "$(OutsideMod_OTHER)"          == "outside-value",,$(error OutsideMod_OTHER is '$(OutsideMod_OTHER)' not 'outside-value'))
+
+# Test #4
+kBuild-define-target SpecialBase
+_SOURCES = file1.c file2.c
+_DEFS.win.x86 = XXX YYY
+_DEFS.win.amd64 = $(filter-out YYY,$([@self]_DEFS.win.x86))
+# Unnecessary use of [@self].
+[@self]_LIBS = MyLib
+kBuild-endef-target
+
+kBuild-define-target SpecialChild extending SpecialBase
+_SOURCES = file1-child.c $(filter-out file1.c,$([@super]_SOURCES))
+# Rare use of [@super].
+[@super]_SET_BY_CHILD = 42
+kBuild-endef-target
+
+$(call TEST_EQ,[target at SpecialBase]_LIBS,MyLib)
+$(call TEST_EQ,SpecialBase_LIBS,MyLib)
+
+$(call TEST_EQ,[target at SpecialBase]_SET_BY_CHILD,42)
+$(call TEST_EQ,SpecialBase_SET_BY_CHILD,42)
+$(call TEST_EQ,[target at SpecialChild]_SET_BY_CHILD,42)
+#$(call TEST_EQ,SpecialChild_SET_BY_CHILD,42) ## @todo
+
+$(call TEST_EQ,[target at SpecialBase]_DEFS.win.x86,XXX YYY)
+$(call TEST_EQ,[target at SpecialBase]_DEFS.win.amd64,XXX)
+$(call TEST_EQ,SpecialBase_DEFS.win.amd64,XXX)
+$(call TEST_EQ,[target at SpecialChild]_DEFS.win.x86,XXX YYY)
+$(call TEST_EQ,[target at SpecialChild]_DEFS.win.amd64,XXX)
+#$(call TEST_EQ,SpecialChild_DEFS.win.amd64,XXX) ## @todo
 
+$(call TEST_EQ,[target at SpecialChild]_SOURCES,file1-child.c file2.c)
+$(call TEST_EQ,SpecialChild_SOURCES,file1-child.c file2.c)
 
 all_recursive:
-	#$(ECHO) "kBuild-define-xxxx works fine"
+	@kmk_echo "kBuild-define-xxxx works fine"
 
diff --git a/src/kmk/variable.c b/src/kmk/variable.c
index 125b8a5..7e9f253 100644
--- a/src/kmk/variable.c
+++ b/src/kmk/variable.c
@@ -42,6 +42,20 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 # include <stddef.h>
 #endif
 
+#ifdef KMK
+/** Gets the real variable if alias.  For use when looking up variables. */
+# define RESOLVE_ALIAS_VARIABLE(v) \
+  do { \
+    if ((v) != NULL && (v)->alias) \
+      { \
+        (v) = (struct variable *)(v)->value; \
+        assert ((v)->aliased); \
+        assert (!(v)->alias); \
+      } \
+  } while (0)
+#endif
+
+
 /* Chain of all pattern-specific variables.  */
 
 static struct pattern_var *pattern_vars;
@@ -200,8 +214,14 @@ variable_hash_cmp (const void *xv, const void *yv)
 # endif
 #endif
 
+
+#ifdef KMK /* Drop the 'static' */
+struct variable_set global_variable_set;
+struct variable_set_list global_setlist
+#else
 static struct variable_set global_variable_set;
 static struct variable_set_list global_setlist
+#endif
   = { 0, &global_variable_set, 0 };
 struct variable_set_list *current_variable_set_list = &global_setlist;
 

@@ -246,53 +266,48 @@ define_variable_in_set (const char *name, unsigned int length,
   struct variable **var_slot;
   struct variable var_key;
 
+  if (env_overrides && origin == o_env)
+    origin = o_env_override;
+
 #ifndef KMK
   if (set == NULL)
     set = &global_variable_set;
-#else
+#else /* KMK */
+  /* Intercept kBuild object variable definitions. */
+  if (name[0] == '[' && length > 3)
+    {
+      v = try_define_kbuild_object_variable_via_accessor (name, length,
+                                                          value, value_len, duplicate_value,
+                                                          origin, recursive, flocp);
+      if (v != VAR_NOT_KBUILD_ACCESSOR)
+        return v;
+    }
   if (set == NULL)
     {
-      /* underscore prefixed variables are automatically local in
-         kBuild-define-* scopes.  They also get a global definition with
-         the current scope prefix. */
-      if (g_pTopKbDef && length > 0 && name[0] == '_')
-        {
-          char         *prefixed_nm;
-          unsigned int  prefixed_nm_len;
-
-          set = get_top_kbuild_variable_set();
-          v = define_variable_in_set(name, length, value, value_len,
-                                     1 /* duplicate_value */,
-                                     origin, recursive, set, flocp);
-
-          prefixed_nm_len = length;
-          prefixed_nm = kbuild_prefix_variable(name, &prefixed_nm_len);
-          define_variable_in_set(prefixed_nm, prefixed_nm_len,
-                                 value, value_len, duplicate_value,
-                                 origin, recursive, &global_variable_set,
-                                 flocp);
-          free(prefixed_nm);
-          return v;
-        }
+      if (g_pTopKbEvalData)
+        return define_kbuild_object_variable_in_top_obj (name, length,
+                                                         value, value_len, duplicate_value,
+                                                         origin, recursive, flocp);
       set = &global_variable_set;
     }
-#endif
+#endif /* KMK */
 
 #ifndef CONFIG_WITH_STRCACHE2
   var_key.name = (char *) name;
   var_key.length = length;
   var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
 
-  if (env_overrides && origin == o_env)
-    origin = o_env_override;
+  /* if (env_overrides && origin == o_env)
+    origin = o_env_override; - bird moved this up */
 
   v = *var_slot;
 #else  /* CONFIG_WITH_STRCACHE2 */
-  var_key.name = name = strcache2_add (&variable_strcache, name, length);
-  var_key.length = length;
+  name = strcache2_add (&variable_strcache, name, length);
   if (   set != &global_variable_set
-      || !(v = strcache2_get_user_val (&variable_strcache, var_key.name)))
+      || !(v = strcache2_get_user_val (&variable_strcache, name)))
     {
+      var_key.name = name;
+      var_key.length = length;
       var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
       v = *var_slot;
     }
@@ -304,6 +319,9 @@ define_variable_in_set (const char *name, unsigned int length,
 #endif /* CONFIG_WITH_STRCACHE2 */
   if (! HASH_VACANT (v))
     {
+#ifdef KMK
+      RESOLVE_ALIAS_VARIABLE(v);
+#endif
       if (env_overrides && v->origin == o_env)
 	/* V came from in the environment.  Since it was defined
 	   before the switches were parsed, it wasn't affected by -e.  */
@@ -419,6 +437,10 @@ define_variable_in_set (const char *name, unsigned int length,
   v->per_target = 0;
   v->append = 0;
   v->private_var = 0;
+#ifdef KMK
+  v->alias = 0;
+  v->aliased = 0;
+#endif
   v->export = v_default;
   MAKE_STATS_2(v->changes = 0);
   MAKE_STATS_2(v->reallocs = 0);
@@ -466,9 +488,17 @@ undefine_variable_in_set (const char *name, unsigned int length,
   if (set == NULL)
     set = &global_variable_set;
 
+#ifndef CONFIG_WITH_STRCACHE2
   var_key.name = (char *) name;
   var_key.length = length;
   var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
+#else
+  var_key.name = strcache2_lookup(&variable_strcache, name, length);
+  if (!var_key.name)
+    return;
+  var_key.length = length;
+  var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
+#endif
 
   if (env_overrides && origin == o_env)
     origin = o_env_override;
@@ -476,6 +506,17 @@ undefine_variable_in_set (const char *name, unsigned int length,
   v = *var_slot;
   if (! HASH_VACANT (v))
     {
+#ifdef KMK
+      if (v->aliased || v->alias)
+        {
+           if (v->aliased)
+             error (NULL, _("Cannot undefine the aliased variable '%s'"), v->name);
+           else
+             error (NULL, _("Cannot undefine the variable alias '%s'"), v->name);
+          return;
+        }
+#endif
+
       if (env_overrides && v->origin == o_env)
 	/* V came from in the environment.  Since it was defined
 	   before the switches were parsed, it wasn't affected by -e.  */
@@ -486,11 +527,119 @@ undefine_variable_in_set (const char *name, unsigned int length,
       if ((int) origin >= (int) v->origin)
 	{
           hash_delete_at (&set->table, var_slot);
+#ifdef CONFIG_WITH_STRCACHE2
+          if (set == &global_variable_set)
+            strcache2_set_user_val (&variable_strcache, v->name, NULL);
+#endif
           free_variable_name_and_value (v);
 	}
     }
 }
 
+#ifdef KMK
+/* Define variable named NAME as an alias of the variable TARGET.
+   SET defaults to the global set if NULL. FLOCP is just for completeness. */
+
+struct variable *
+define_variable_alias_in_set (const char *name, unsigned int length,
+                              struct variable *target, enum variable_origin origin,
+                              struct variable_set *set, const struct floc *flocp)
+{
+  struct variable     *v;
+  struct variable     **var_slot;
+
+  /* Look it up the hash table slot for it. */
+  name = strcache2_add (&variable_strcache, name, length);
+  if (   set != &global_variable_set
+      || !(v = strcache2_get_user_val (&variable_strcache, name)))
+    {
+      struct variable var_key;
+
+      var_key.name = name;
+      var_key.length = length;
+      var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
+      v = *var_slot;
+    }
+  else
+    {
+      assert (!v || (v->name == name && !HASH_VACANT (v)));
+      var_slot = 0;
+    }
+  if (! HASH_VACANT (v))
+    {
+      /* A variable of this name is already defined.
+         If the old definition is from a stronger source
+         than this one, don't redefine it.  */
+
+      if (env_overrides && v->origin == o_env)
+        /* V came from in the environment.  Since it was defined
+           before the switches were parsed, it wasn't affected by -e.  */
+        v->origin = o_env_override;
+
+      if ((int) origin < (int) v->origin)
+        return v;
+
+      if (v->value != 0 && !v->rdonly_val)
+          free (v->value);
+      MAKE_STATS_2(v->changes++);
+    }
+  else
+    {
+      /* Create a new variable definition and add it to the hash table.  */
+      v = alloccache_alloc (&variable_cache);
+      v->name = name; /* already cached. */
+      v->length = length;
+      hash_insert_at (&set->table, v, var_slot);
+      v->special = 0;
+      v->expanding = 0;
+      v->exp_count = 0;
+      v->per_target = 0;
+      v->append = 0;
+      v->private_var = 0;
+      v->aliased = 0;
+      v->export = v_default;
+      MAKE_STATS_2(v->changes = 0);
+      MAKE_STATS_2(v->reallocs = 0);
+      v->exportable = 1;
+      if (*name != '_' && (*name < 'A' || *name > 'Z')
+          && (*name < 'a' || *name > 'z'))
+        v->exportable = 0;
+      else
+        {
+          for (++name; *name != '\0'; ++name)
+            if (*name != '_' && (*name < 'a' || *name > 'z')
+                && (*name < 'A' || *name > 'Z') && !ISDIGIT(*name))
+              break;
+
+          if (*name != '\0')
+            v->exportable = 0;
+        }
+
+     /* If it's the global set, remember the variable. */
+     if (set == &global_variable_set)
+       strcache2_set_user_val (&variable_strcache, v->name, v);
+    }
+
+  /* Common variable setup. */
+  v->alias = 1;
+  v->rdonly_val = 1;
+  v->value = (char *)target;
+  v->value_length = sizeof(*target); /* Non-zero to provoke trouble. */
+  v->value_alloc_len = sizeof(*target);
+  if (flocp != 0)
+    v->fileinfo = *flocp;
+  else
+    v->fileinfo.filenm = 0;
+  v->origin = origin;
+  v->recursive = 0;
+
+  /* Mark the target as aliased. */
+  target->aliased = 1;
+
+  return v;
+}
+#endif /* KMK */
+
 /* If the variable passed in is "special", handle its special nature.
    Currently there are two such variables, both used for introspection:
    .VARIABLES expands to a list of all the variables defined in this instance
@@ -730,7 +879,19 @@ lookup_variable (const char *name, unsigned int length)
   int is_parent = 0;
 #ifdef CONFIG_WITH_STRCACHE2
   const char *cached_name;
+#endif
 
+# ifdef KMK
+  /* Check for kBuild-define- local variable accesses and handle these first. */
+  if (length > 3 && name[0] == '[')
+    {
+      struct variable *v = lookup_kbuild_object_variable_accessor(name, length);
+      if (v != VAR_NOT_KBUILD_ACCESSOR)
+        return v;
+    }
+# endif
+
+#ifdef CONFIG_WITH_STRCACHE2
   /* lookup the name in the string case, if it's not there it won't
      be in any of the sets either. */
   cached_name = strcache2_lookup (&variable_strcache, name, length);
@@ -755,7 +916,12 @@ lookup_variable (const char *name, unsigned int length)
       v = (struct variable *) hash_find_item_strcached ((struct hash_table *) &set->table, &var_key);
 # endif /* CONFIG_WITH_STRCACHE2 */
       if (v && (!is_parent || !v->private_var))
-	return v->special ? lookup_special_var (v) : v;
+        {
+# ifdef KMK
+          RESOLVE_ALIAS_VARIABLE(v);
+# endif
+	  return v->special ? lookup_special_var (v) : v;
+        }
 
       is_parent |= setlist->next_is_parent;
     }
@@ -838,6 +1004,9 @@ lookup_variable_in_set (const char *name, unsigned int length,
                         const struct variable_set *set)
 {
   struct variable var_key;
+#ifdef KMK
+  struct variable *v;
+#endif
 #ifndef CONFIG_WITH_STRCACHE2
   var_key.name = (char *) name;
   var_key.length = length;
@@ -846,6 +1015,19 @@ lookup_variable_in_set (const char *name, unsigned int length,
 #else  /* CONFIG_WITH_STRCACHE2 */
   const char *cached_name;
 
+# ifdef KMK
+  /* Check for kBuild-define- local variable accesses and handle these first. */
+  if (length > 3 && name[0] == '[' && set == &global_variable_set)
+    {
+      struct variable *v = lookup_kbuild_object_variable_accessor(name, length);
+      if (v != VAR_NOT_KBUILD_ACCESSOR)
+        {
+          RESOLVE_ALIAS_VARIABLE(v);
+          return v;
+        }
+    }
+# endif
+
   /* lookup the name in the string case, if it's not there it won't
      be in any of the sets either.  Optimize lookups in the global set. */
   cached_name = strcache2_lookup(&variable_strcache, name, length);
@@ -854,17 +1036,21 @@ lookup_variable_in_set (const char *name, unsigned int length,
 
   if (set == &global_variable_set)
     {
-      struct variable *v;
       v = strcache2_get_user_val (&variable_strcache, cached_name);
       assert (!v || v->name == cached_name);
-      return v;
     }
+  else
+    {
+      var_key.name = cached_name;
+      var_key.length = length;
 
-  var_key.name = cached_name;
-  var_key.length = length;
-
-  return (struct variable *) hash_find_item_strcached (
-    (struct hash_table *) &set->table, &var_key);
+      v = (struct variable *) hash_find_item_strcached (
+        (struct hash_table *) &set->table, &var_key);
+    }
+# ifdef KMK
+  RESOLVE_ALIAS_VARIABLE(v);
+# endif
+  return v;
 #endif /* CONFIG_WITH_STRCACHE2 */
 }
 

@@ -1152,7 +1338,16 @@ merge_variable_sets (struct variable_set *to_set,
 	else
 	  {
 	    /* GKM FIXME: delete in from_set->table */
-	    free (from_var->value);
+#ifdef KMK
+            if (from_var->aliased)
+              fatal(NULL, ("Attempting to delete aliased variable '%s'"), from_var->name);
+            if (from_var->alias)
+              fatal(NULL, ("Attempting to delete variable aliased '%s'"), from_var->name);
+#endif
+#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
+            if (!from_var->rdonly_val)
+#endif
+              free (from_var->value);
 	    free (from_var);
 	  }
       }
@@ -1843,6 +2038,9 @@ void append_string_to_variable (struct variable *v, const char *value, unsigned
      The new value is the unexpanded old and new values. */
   unsigned int new_value_len = value_len + (v->value_length != 0 ? 1 + v->value_length : 0);
   int done_1st_prepend_copy = 0;
+#ifdef KMK
+  assert (!v->alias);
+#endif
 
   /* Drop empty strings. Use $(NO_SUCH_VARIABLE) if a space is wanted. */
   if (!value_len)
@@ -1901,7 +2099,7 @@ void append_string_to_variable (struct variable *v, const char *value, unsigned
   v->value_length = new_value_len;
 }
 
-static struct variable *
+struct variable *
 do_variable_definition_append (const struct floc *flocp, struct variable *v,
                                const char *value, unsigned int value_len,
                                int simple_value, enum variable_origin origin,
@@ -1981,8 +2179,12 @@ do_variable_definition_2 (const struct floc *flocp,
   int append = 0;
   int conditional = 0;
   const size_t varname_len = strlen (varname); /* bird */
+
 #ifdef CONFIG_WITH_VALUE_LENGTH
-  assert (value_len == ~0U || value_len == strlen (value));
+  if (value_len == ~0U)
+    value_len = strlen (value);
+  else
+    assert (value_len == strlen (value));
 #endif
 
   /* Calculate the variable's new value in VALUE.  */
@@ -2051,16 +2253,9 @@ do_variable_definition_2 (const struct floc *flocp,
       {
 #endif
 
-#ifdef CONFIG_WITH_LOCAL_VARIABLES
-          /* If we have += but we're in a target or local variable context,
-             we want to append only with other variables in the context of
-             this target.  */
-        if (target_var || origin == o_local)
-#else
         /* If we have += but we're in a target variable context, we want to
            append only with other variables in the context of this target.  */
         if (target_var)
-#endif
           {
             append = 1;
             v = lookup_variable_in_set (varname, varname_len,
@@ -2071,6 +2266,26 @@ do_variable_definition_2 (const struct floc *flocp,
             if (v && !v->append)
               append = 0;
           }
+#ifdef KMK
+        else if (   g_pTopKbEvalData
+                 || (   varname_len > 3
+                     && varname[0] == '['
+                     && is_kbuild_object_variable_accessor (varname, varname_len)) )
+          {
+            v = kbuild_object_variable_pre_append (varname, varname_len,
+                                                   value, value_len, simple_value,
+                                                   origin, org_flavor == f_append, flocp);
+            if (free_value)
+               free (free_value);
+            return v;
+          }
+#endif
+#ifdef CONFIG_WITH_LOCAL_VARIABLES
+        /* If 'local', restrict it to the current variable context. */
+        else if (origin == o_local)
+          v = lookup_variable_in_set (varname, varname_len,
+                                      current_variable_set_list->set);
+#endif
         else
           v = lookup_variable (varname, varname_len);
 
@@ -2536,6 +2751,10 @@ print_variable (const void *item, void *arg)
   const struct variable *v = item;
   const char *prefix = arg;
   const char *origin;
+#ifdef KMK
+  const struct variable *alias = v;
+  RESOLVE_ALIAS_VARIABLE(v);
+#endif
 
   switch (v->origin)
     {
@@ -2573,9 +2792,20 @@ print_variable (const void *item, void *arg)
   fputs (origin, stdout);
   if (v->private_var)
     fputs (" private", stdout);
+#ifndef KMK
   if (v->fileinfo.filenm)
     printf (_(" (from `%s', line %lu)"),
             v->fileinfo.filenm, v->fileinfo.lineno);
+#else  /* KMK */
+  if (alias->fileinfo.filenm)
+    printf (_(" (from '%s', line %lu)"),
+            alias->fileinfo.filenm, alias->fileinfo.lineno);
+  if (alias->aliased)
+    fputs (" aliased", stdout);
+  if (alias->alias)
+    printf (_(", alias for '%s'"), v->name);
+#endif /* KMK */
+
 #ifdef CONFIG_WITH_MAKE_STATS
   if (v->changes != 0)
       printf (_(", %u changes"), v->changes);
@@ -2598,12 +2828,20 @@ print_variable (const void *item, void *arg)
 
   /* Is this a `define'?  */
   if (v->recursive && strchr (v->value, '\n') != 0)
+#ifndef KMK /** @todo language feature for aliases */
     printf ("define %s\n%s\nendef\n", v->name, v->value);
+#else
+    printf ("define %s\n%s\nendef\n", alias->name, v->value);
+#endif
   else
     {
       char *p;
 
+#ifndef KMK /** @todo language feature for aliases */
       printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":");
+#else
+      printf ("%s %s= ", alias->name, v->recursive ? v->append ? "+" : "" : ":");
+#endif
 
       /* Check if the value is just whitespace.  */
       p = next_token (v->value);
diff --git a/src/kmk/variable.h b/src/kmk/variable.h
index b885cb4..6c922dd 100644
--- a/src/kmk/variable.h
+++ b/src/kmk/variable.h
@@ -89,6 +89,10 @@ struct variable
 #ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     unsigned int rdonly_val:1;  /* VALUE is read only (strcache/const). */
 #endif
+#ifdef KMK
+    unsigned int alias:1;       /* Nonzero if alias. VALUE points to the real variable. */
+    unsigned int aliased:1;     /* Nonzero if aliased. Cannot be undefined. */
+#endif
     enum variable_flavor
       flavor ENUM_BITFIELD (3);	/* Variable flavor.  */
     enum variable_origin
@@ -142,6 +146,8 @@ extern struct variable_set_list *current_variable_set_list;
 extern struct variable *default_goal_var;
 
 #ifdef KMK
+extern struct variable_set global_variable_set;
+extern struct variable_set_list global_setlist;
 extern unsigned int variable_buffer_length;
 # define VARIABLE_BUFFER_ZONE   5
 #endif
@@ -350,6 +356,10 @@ struct variable *lookup_variable_in_set (const char *name, unsigned int length,
 #ifdef CONFIG_WITH_VALUE_LENGTH
 void append_string_to_variable (struct variable *v, const char *value,
                                 unsigned int value_len, int append);
+struct variable * do_variable_definition_append (const struct floc *flocp, struct variable *v,
+                                                 const char *value, unsigned int value_len,
+                                                 int simple_value, enum variable_origin origin,
+                                                 int append);
 
 struct variable *define_variable_in_set (const char *name, unsigned int length,
                                          const char *value,
@@ -443,6 +453,13 @@ void undefine_variable_in_set (const char *name, unsigned int length,
 #define undefine_variable_global(n,l,o) \
           undefine_variable_in_set((n),(l),(o),NULL)
 
+#ifdef KMK
+struct variable *
+define_variable_alias_in_set (const char *name, unsigned int length,
+                              struct variable *target, enum variable_origin origin,
+                              struct variable_set *set, const struct floc *flocp);
+#endif
+
 /* Warn that NAME is an undefined variable.  */
 
 #define warn_undefined(n,l) do{\
diff --git a/src/kmk/w32/include/dirent.h b/src/kmk/w32/include/dirent.h
index 6e77c8b..fa5af3d 100644
--- a/src/kmk/w32/include/dirent.h
+++ b/src/kmk/w32/include/dirent.h
@@ -18,6 +18,12 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifndef _DIRENT_H
 #define _DIRENT_H
 
+#ifdef KMK
+# include <windows.h>
+# include "nt/ntdir.h"
+
+#else /* !KMK */
+
 #ifdef __MINGW32__
 # include <windows.h>
 # include_next <dirent.h>
@@ -57,4 +63,5 @@ int telldir(DIR *);
 void seekdir(DIR *, long);
 
 #endif  /* !__MINGW32__ */
+#endif  /* !KMK */
 #endif
diff --git a/src/lib/Makefile.kmk b/src/lib/Makefile.kmk
index e89a302..68df500 100644
--- a/src/lib/Makefile.kmk
+++ b/src/lib/Makefile.kmk
@@ -1,10 +1,10 @@
-# $Id: Makefile.kmk 2469 2011-07-12 12:52:34Z bird $
+# $Id: Makefile.kmk 2713 2013-11-21 21:11:00Z bird $
 ## @file
 # Sub-makefile for various libraries and stuff.
 #
 
 #
-# Copyright (c) 2006-2010 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+# Copyright (c) 2006-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
 #
 # This file is part of kBuild.
 #
@@ -36,10 +36,17 @@ kDep_NOINST = 1
 LIBRARIES += kUtil
 kUtil_TEMPLATE = LIB
 kUtil_DEFS.win = __WIN__
-kUtil_SOURCES = crc32.c md5.c
+kUtil_SOURCES = \
+	crc32.c \
+	md5.c
 kUtil_SOURCES.win = \
 	nt_fullpath.c \
-	quoted_spawn.c
+	quoted_spawn.c \
+       nt/nthlpcore.c \
+       nt/nthlpfs.c \
+       nt/ntdir.c \
+       nt/ntstat.c \
+       nt/ntunlink.c
 kUtil_SOURCES.solaris = \
 	restartable-syscall-wrappers.c
 #kUtil_SOURCES.linux = \
@@ -56,5 +63,11 @@ wrapper_TEMPLATE = BIN
 wrapper_SOURCES = wrapper.c
 wrapper_NOINST = 1
 
+PROGRAMS.win += tstNtStat
+tstNtStat_TEMPLATE = BIN
+tstNtStat_SOURCES = nt/tstNtStat.c
+tstNtStat_LIBS = $(LIB_KUTIL)
+tstNtStat_NOINST = 1
+
 include $(FILE_KBUILD_SUB_FOOTER)
 
diff --git a/src/lib/nt/Makefile.kup b/src/lib/nt/Makefile.kup
new file mode 100644
index 0000000..e69de29
diff --git a/src/lib/nt/ntdir.c b/src/lib/nt/ntdir.c
new file mode 100644
index 0000000..a80e53a
--- /dev/null
+++ b/src/lib/nt/ntdir.c
@@ -0,0 +1,364 @@
+/* $Id: ntdir.c 2708 2013-11-21 10:26:40Z bird $ */
+/** @file
+ * MSC + NT opendir, readdir, telldir, seekdir, and closedir.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <stdio.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include "ntstuff.h"
+#include "nthlp.h"
+#include "ntdir.h"
+
+
+/**
+ * Internal worker for birdStatModTimeOnly.
+ */
+static BirdDir_T *birdDirOpenInternal(const char *pszPath, const char *pszFilter, int fMinimalInfo)
+{
+    HANDLE hFile = birdOpenFile(pszPath,
+                                FILE_READ_DATA | SYNCHRONIZE,
+                                FILE_ATTRIBUTE_NORMAL,
+                                FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                FILE_OPEN,
+                                FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
+                                OBJ_CASE_INSENSITIVE);
+    if (hFile != INVALID_HANDLE_VALUE)
+    {
+        /*
+         * Allocate a handle.
+         */
+        BirdDir_T *pDir = (BirdDir_T *)birdMemAlloc(sizeof(*pDir));
+        if (pDir)
+        {
+            pDir->uMagic     = BIRD_DIR_MAGIC;
+            pDir->pvHandle   = (void *)hFile;
+            pDir->uDev       = 0;
+            pDir->offPos     = 0;
+            pDir->fHaveData  = 0;
+            pDir->fFirst     = 1;
+            pDir->iInfoClass = fMinimalInfo ? MyFileNamesInformation : MyFileIdFullDirectoryInformation;
+            pDir->offBuf     = 0;
+            pDir->cbBuf      = 0;
+            pDir->pabBuf     = NULL;
+            return pDir;
+        }
+
+        birdCloseFile(hFile);
+        birdSetErrnoToNoMem();
+    }
+
+    return NULL;
+}
+
+
+/**
+ * Implements opendir.
+ */
+BirdDir_T *birdDirOpen(const char *pszPath)
+{
+    return birdDirOpenInternal(pszPath, NULL, 1 /*fMinimalInfo*/);
+}
+
+
+/**
+ * Alternative opendir, with extra stat() info returned by readdir().
+ */
+BirdDir_T *birdDirOpenExtraInfo(const char *pszPath)
+{
+    return birdDirOpenInternal(pszPath, NULL, 0 /*fMinimalInfo*/);
+}
+
+
+static int birdDirReadMore(BirdDir_T *pDir)
+{
+    MY_NTSTATUS         rcNt;
+    MY_IO_STATUS_BLOCK  Ios;
+    int                 fFirst;
+
+    /*
+     * Retrieve the volume serial number + creation time and create the
+     * device number the first time around.  Also allocate a buffer.
+     */
+    fFirst = pDir->fFirst;
+    if (fFirst)
+    {
+        union
+        {
+            MY_FILE_FS_VOLUME_INFORMATION VolInfo;
+            unsigned char abBuf[1024];
+        } uBuf;
+
+        Ios.Information = 0;
+        Ios.u.Status    = -1;
+        rcNt = g_pfnNtQueryVolumeInformationFile((HANDLE)pDir->pvHandle, &Ios, &uBuf, sizeof(uBuf), MyFileFsVolumeInformation);
+        if (MY_NT_SUCCESS(rcNt))
+            rcNt = Ios.u.Status;
+        if (MY_NT_SUCCESS(rcNt))
+            pDir->uDev = uBuf.VolInfo.VolumeSerialNumber
+                       | (uBuf.VolInfo.VolumeCreationTime.QuadPart << 32);
+        else
+            pDir->uDev = 0;
+
+        /*
+         * Allocate a buffer.
+         */
+        pDir->cbBuf = 0x20000;
+        pDir->pabBuf = birdMemAlloc(pDir->cbBuf);
+        if (!pDir->pabBuf)
+            return birdSetErrnoToNoMem();
+
+        pDir->fFirst = 0;
+    }
+
+    /*
+     * Read another buffer full.
+     */
+    Ios.Information = 0;
+    Ios.u.Status    = -1;
+
+    rcNt = g_pfnNtQueryDirectoryFile((HANDLE)pDir->pvHandle,
+                                     NULL,      /* hEvent */
+                                     NULL,      /* pfnApcComplete */
+                                     NULL,      /* pvApcCompleteCtx */
+                                     &Ios,
+                                     pDir->pabBuf,
+                                     pDir->cbBuf,
+                                     (MY_FILE_INFORMATION_CLASS)pDir->iInfoClass,
+                                     FALSE,     /* fReturnSingleEntry */
+                                     NULL,      /* Filter / restart pos. */
+                                     FALSE);    /* fRestartScan */
+    if (!MY_NT_SUCCESS(rcNt))
+    {
+        int rc;
+        if (rcNt == MY_STATUS_NO_MORE_FILES)
+            rc = 0;
+        else
+            rc = birdSetErrnoFromNt(rcNt);
+        pDir->fHaveData = 0;
+        pDir->offBuf    = pDir->cbBuf;
+        return rc;
+    }
+
+    pDir->offBuf    = 0;
+    pDir->fHaveData = 1;
+
+    return 0;
+}
+
+
+static int birdDirCopyNameToEntry(WCHAR const *pwcName, ULONG cbName, BirdDirEntry_T *pEntry)
+{
+    int cchOut = WideCharToMultiByte(CP_ACP, 0,
+                                     pwcName, cbName / sizeof(WCHAR),
+                                     pEntry->d_name, sizeof(pEntry->d_name) - 1,
+                                     NULL, NULL);
+    if (cchOut > 0)
+    {
+        pEntry->d_name[cchOut] = '\0';
+        pEntry->d_namlen = (unsigned __int16)cchOut;
+        pEntry->d_reclen = (unsigned __int16)((size_t)&pEntry->d_name[cchOut + 1] - (size_t)pEntry);
+        return 0;
+    }
+    return -1;
+}
+
+
+
+/**
+ * Implements readdir_r().
+ */
+int birdDirReadReentrant(BirdDir_T *pDir, BirdDirEntry_T *pEntry, BirdDirEntry_T **ppResult)
+{
+    int fSkipEntry;
+
+    *ppResult = NULL;
+
+    if (!pDir || pDir->uMagic != BIRD_DIR_MAGIC)
+        return birdSetErrnoToBadFileNo();
+
+    do
+    {
+        ULONG offNext;
+        ULONG cbMinCur;
+
+        /*
+         * Read more?
+         */
+        if (!pDir->fHaveData)
+        {
+            if (birdDirReadMore(pDir) != 0)
+                return -1;
+            if (!pDir->fHaveData)
+                return 0;
+        }
+
+        /*
+         * Convert the NT data to the unixy output structure.
+         */
+        fSkipEntry = 0;
+        switch (pDir->iInfoClass)
+        {
+            case MyFileNamesInformation:
+            {
+                MY_FILE_NAMES_INFORMATION *pInfo = (MY_FILE_NAMES_INFORMATION *)&pDir->pabBuf[pDir->offBuf];
+                if (   pDir->offBuf          >= pDir->cbBuf - MIN_SIZEOF_MY_FILE_NAMES_INFORMATION
+                    || pInfo->FileNameLength >= pDir->cbBuf
+                    || pDir->offBuf + pInfo->FileNameLength + MIN_SIZEOF_MY_FILE_NAMES_INFORMATION > pDir->cbBuf)
+                {
+                    fSkipEntry = 1;
+                    pDir->fHaveData = 0;
+                    continue;
+                }
+
+                memset(&pEntry->d_stat, 0, sizeof(pEntry->d_stat));
+                pEntry->d_stat.st_mode  = S_IFMT;
+                pEntry->d_type          = DT_UNKNOWN;
+                pEntry->d_reclen        = 0;
+                pEntry->d_namlen        = 0;
+                if (birdDirCopyNameToEntry(pInfo->FileName, pInfo->FileNameLength, pEntry) != 0)
+                    fSkipEntry = 1;
+
+                cbMinCur = MIN_SIZEOF_MY_FILE_NAMES_INFORMATION + pInfo->FileNameLength;
+                offNext  = pInfo->NextEntryOffset;
+                break;
+            }
+
+            case MyFileIdFullDirectoryInformation:
+            {
+                MY_FILE_ID_FULL_DIR_INFORMATION *pInfo = (MY_FILE_ID_FULL_DIR_INFORMATION *)&pDir->pabBuf[pDir->offBuf];
+                if (   pDir->offBuf          >= pDir->cbBuf - MIN_SIZEOF_MY_FILE_ID_FULL_DIR_INFORMATION
+                    || pInfo->FileNameLength >= pDir->cbBuf
+                    || pDir->offBuf + pInfo->FileNameLength + MIN_SIZEOF_MY_FILE_ID_FULL_DIR_INFORMATION > pDir->cbBuf)
+                {
+                    fSkipEntry = 1;
+                    pDir->fHaveData = 0;
+                    continue;
+                }
+
+                pEntry->d_type          = DT_UNKNOWN;
+                pEntry->d_reclen        = 0;
+                pEntry->d_namlen        = 0;
+                if (birdDirCopyNameToEntry(pInfo->FileName, pInfo->FileNameLength, pEntry) != 0)
+                    fSkipEntry = 1;
+                birdStatFillFromFileIdFullDirInfo(&pEntry->d_stat, pInfo, pEntry->d_name);
+                pEntry->d_stat.st_dev   = pDir->uDev;
+                switch (pEntry->d_stat.st_mode & S_IFMT)
+                {
+                    case S_IFREG:       pEntry->d_type = DT_REG; break;
+                    case S_IFDIR:       pEntry->d_type = DT_DIR; break;
+                    case S_IFLNK:       pEntry->d_type = DT_LNK; break;
+                    case S_IFIFO:       pEntry->d_type = DT_FIFO; break;
+                    case S_IFCHR:       pEntry->d_type = DT_CHR; break;
+                    default:
+#ifndef NDEBUG
+                        __debugbreak();
+#endif
+                        pEntry->d_type = DT_UNKNOWN;
+                        break;
+                }
+
+                cbMinCur = MIN_SIZEOF_MY_FILE_ID_FULL_DIR_INFORMATION + pInfo->FileNameLength;
+                offNext  = pInfo->NextEntryOffset;
+                break;
+            }
+
+            default:
+                return birdSetErrnoToBadFileNo();
+        }
+
+        /*
+         * Advance.
+         */
+        if (   offNext >= cbMinCur
+            && offNext < pDir->cbBuf)
+            pDir->offBuf += offNext;
+        else
+        {
+            pDir->fHaveData = 0;
+            pDir->offBuf    = pDir->cbBuf;
+        }
+        pDir->offPos++;
+    } while (fSkipEntry);
+
+
+    /*
+     * Successful return.
+     */
+    *ppResult = pEntry;
+    return 0;
+}
+
+
+/**
+ * Implements readdir().
+ */
+BirdDirEntry_T *birdDirRead(BirdDir_T *pDir)
+{
+    BirdDirEntry_T *pRet = NULL;
+    birdDirReadReentrant(pDir, &pDir->DirEntry, &pRet);
+    return pRet;
+}
+
+
+/**
+ * Implements telldir().
+ */
+long birdDirTell(BirdDir_T *pDir)
+{
+    if (!pDir || pDir->uMagic != BIRD_DIR_MAGIC)
+        return birdSetErrnoToBadFileNo();
+    return pDir->offPos;
+}
+
+
+void birdDirSeek(BirdDir_T *pDir, long offDir);
+
+
+/**
+ * Implements closedir().
+ */
+int             birdDirClose(BirdDir_T *pDir)
+{
+    if (!pDir || pDir->uMagic != BIRD_DIR_MAGIC)
+        return birdSetErrnoToBadFileNo();
+
+    pDir->uMagic++;
+    birdCloseFile((HANDLE)pDir->pvHandle);
+    pDir->pvHandle = (void *)INVALID_HANDLE_VALUE;
+    birdMemFree(pDir->pabBuf);
+    pDir->pabBuf = NULL;
+    birdMemFree(pDir);
+
+    return 0;
+}
diff --git a/src/lib/nt/ntdir.h b/src/lib/nt/ntdir.h
new file mode 100644
index 0000000..f84cf51
--- /dev/null
+++ b/src/lib/nt/ntdir.h
@@ -0,0 +1,115 @@
+/* $Id: ntdir.h 2708 2013-11-21 10:26:40Z bird $ */
+/** @file
+ * MSC + NT opendir, readdir, closedir and friends.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+#ifndef ___nt_ntdir_h
+#define ___nt_ntdir_h
+
+#include "nttypes.h"
+#include "ntstat.h"
+
+typedef struct dirent
+{
+    /** Optional stat information.
+     * Only provided if using birdDirOpenExtraInfo(). */
+    BirdStat_T          d_stat;
+    /** The record length. */
+    unsigned __int16    d_reclen;
+    /** The name length. */
+    unsigned __int16    d_namlen;
+    /** The name type. */
+    unsigned char       d_type;
+    /** The name. */
+    char                d_name[512 - sizeof(BirdStat_T) - 2 - 2 - 1];
+} BirdDirEntry_T;
+
+#define d_ino           d_stat.st_ino;
+
+/** @name d_type values.
+ * @{ */
+#define DT_UNKNOWN           0
+#define DT_FIFO              1
+#define DT_CHR               2
+#define DT_DIR               4
+#define DT_BLK               6
+#define DT_REG               8
+#define DT_LNK              10
+#define DT_SOCK             12
+#define DT_WHT              14
+/** @}  */
+
+typedef struct BirdDir
+{
+    /** Magic value. */
+    unsigned            uMagic;
+    /** The directory handle. */
+    void               *pvHandle;
+    /** The device number (st_dev). */
+    unsigned __int64    uDev;
+    /** The current position. */
+    long                offPos;
+
+    /** Set if we haven't yet read anything. */
+    int                 fFirst;
+    /** Set if we have data in the buffer. */
+    int                 fHaveData;
+    /** The info type we're querying. */
+    int                 iInfoClass;
+    /** The current buffer position. */
+    unsigned            offBuf;
+    /** The number of bytes allocated for pabBuf. */
+    unsigned            cbBuf;
+    /** Buffer of size cbBuf. */
+    unsigned char      *pabBuf;
+
+    /** Static directory entry. */
+    BirdDirEntry_T      DirEntry;
+} BirdDir_T;
+/** Magic value for BirdDir. */
+#define BIRD_DIR_MAGIC      0x19731120
+
+
+BirdDir_T      *birdDirOpen(const char *pszPath);
+BirdDir_T      *birdDirOpenExtraInfo(const char *pszPath);
+BirdDirEntry_T *birdDirRead(BirdDir_T *pDir);
+long            birdDirTell(BirdDir_T *pDir);
+void            birdDirSeek(BirdDir_T *pDir, long offDir);
+int             birdDirClose(BirdDir_T *pDir);
+
+#define opendir                     birdDirOpen
+#define readdir                     birdDirRead
+#define telldir                     birdDirTell
+#define seekdir                     birdDirSeek
+#define rewinddir(a_pDir, a_offDir) birdDirSeek(a_pDir, 0)
+#define closedir                    birdDirClose
+#define _D_NAMLEN(a_pEnt)           ((a_pEnt)->d_namlen)
+typedef BirdDir_T DIR;
+
+#endif
+
diff --git a/src/lib/nt/nthlp.h b/src/lib/nt/nthlp.h
new file mode 100644
index 0000000..47914f9
--- /dev/null
+++ b/src/lib/nt/nthlp.h
@@ -0,0 +1,70 @@
+/* $Id: nthlp.h 2713 2013-11-21 21:11:00Z bird $ */
+/** @file
+ * MSC + NT helper functions.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+#ifndef ___nt_nthlp_h
+#define ___nt_nthlp_h
+
+#include "ntstuff.h"
+
+
+/** Lazy resolving of the NTDLL imports. */
+#define birdResolveImports() do { if (g_fResolvedNtImports) {} else birdResolveImportsWorker(); } while (0)
+void        birdResolveImportsWorker(void);
+extern int  g_fResolvedNtImports;
+
+void       *birdTmpAlloc(size_t cb);
+void        birdTmpFree(void *pv);
+
+void       *birdMemAlloc(size_t cb);
+void       *birdMemAllocZ(size_t cb);
+void        birdMemFree(void *pv);
+
+int         birdSetErrnoFromNt(MY_NTSTATUS rcNt);
+int         birdSetErrnoFromWin32(DWORD dwErr);
+int         birdSetErrnoToNoMem(void);
+int         birdSetErrnoToInvalidArg(void);
+int         birdSetErrnoToBadFileNo(void);
+
+
+HANDLE      birdOpenFile(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs, ULONG fShareAccess,
+                         ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
+HANDLE      birdOpenParentDir(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs, ULONG fShareAccess,
+                              ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
+                              MY_UNICODE_STRING *pNameUniStr);
+MY_NTSTATUS birdOpenFileUniStr(MY_UNICODE_STRING *pNtPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
+                               ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
+                               HANDLE *phFile);
+void        birdCloseFile(HANDLE hFile);
+int         birdDosToNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath);
+void        birdFreeNtPath(MY_UNICODE_STRING *pNtPath);
+
+
+#endif
+
diff --git a/src/lib/nt/nthlpcore.c b/src/lib/nt/nthlpcore.c
new file mode 100644
index 0000000..9452da6
--- /dev/null
+++ b/src/lib/nt/nthlpcore.c
@@ -0,0 +1,450 @@
+/* $Id: nthlpcore.c 2715 2013-12-06 17:41:35Z bird $ */
+/** @file
+ * MSC + NT core helpers functions and globals.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <errno.h>
+#include "nthlp.h"
+#ifndef NDEBUG
+# include <stdio.h>
+#endif
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+MY_NTSTATUS (WINAPI *g_pfnNtClose)(HANDLE);
+MY_NTSTATUS (WINAPI *g_pfnNtCreateFile)(PHANDLE, MY_ACCESS_MASK, MY_OBJECT_ATTRIBUTES *, MY_IO_STATUS_BLOCK *,
+                                        PLARGE_INTEGER, ULONG, ULONG, ULONG, ULONG, PVOID, ULONG);
+MY_NTSTATUS (WINAPI *g_pfnNtDeleteFile)(MY_OBJECT_ATTRIBUTES *);
+MY_NTSTATUS (WINAPI *g_pfnNtQueryInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *, PVOID, LONG, MY_FILE_INFORMATION_CLASS);
+MY_NTSTATUS (WINAPI *g_pfnNtQueryVolumeInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *, PVOID, LONG, MY_FS_INFORMATION_CLASS);
+MY_NTSTATUS (WINAPI *g_pfnNtQueryDirectoryFile)(HANDLE, HANDLE, MY_IO_APC_ROUTINE *, PVOID, MY_IO_STATUS_BLOCK *,
+                                                PVOID, ULONG, MY_FILE_INFORMATION_CLASS, BOOLEAN,
+                                                MY_UNICODE_STRING *, BOOLEAN);
+MY_NTSTATUS (WINAPI *g_pfnNtSetInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *, PVOID, LONG, MY_FILE_INFORMATION_CLASS);
+BOOLEAN     (WINAPI *g_pfnRtlDosPathNameToNtPathName_U)(PCWSTR, MY_UNICODE_STRING *, PCWSTR *, MY_RTL_RELATIVE_NAME_U *);
+MY_NTSTATUS (WINAPI *g_pfnRtlAnsiStringToUnicodeString)(MY_UNICODE_STRING *, MY_ANSI_STRING const *, BOOLEAN);
+
+
+static struct
+{
+    FARPROC    *ppfn;
+    const char *pszName;
+} const g_apfnDynamicNtdll[] =
+{
+    { (FARPROC *)&g_pfnNtClose,                         "NtClose" },
+    { (FARPROC *)&g_pfnNtCreateFile,                    "NtCreateFile" },
+    { (FARPROC *)&g_pfnNtDeleteFile,                    "NtDeleteFile" },
+    { (FARPROC *)&g_pfnNtQueryInformationFile,          "NtQueryInformationFile" },
+    { (FARPROC *)&g_pfnNtQueryVolumeInformationFile,    "NtQueryVolumeInformationFile" },
+    { (FARPROC *)&g_pfnNtQueryDirectoryFile,            "NtQueryDirectoryFile" },
+    { (FARPROC *)&g_pfnNtSetInformationFile,            "NtSetInformationFile" },
+    { (FARPROC *)&g_pfnRtlDosPathNameToNtPathName_U,    "RtlDosPathNameToNtPathName_U" },
+    { (FARPROC *)&g_pfnRtlAnsiStringToUnicodeString,    "RtlAnsiStringToUnicodeString" },
+};
+/** Set to 1 if we've successfully resolved the imports, otherwise 0. */
+int g_fResolvedNtImports = 0;
+
+
+
+void birdResolveImportsWorker(void)
+{
+    HMODULE     hMod = LoadLibraryW(L"ntdll.dll");
+    int         i    = sizeof(g_apfnDynamicNtdll) / sizeof(g_apfnDynamicNtdll[0]);
+    while (i-- > 0)
+    {
+        const char *pszSym = g_apfnDynamicNtdll[i].pszName;
+        FARPROC     pfn;
+        *g_apfnDynamicNtdll[i].ppfn = pfn = GetProcAddress(hMod, pszSym);
+        if (!pfn)
+        {
+            /* Write short message and die. */
+            static const char   s_szMsg[] = "\r\nFatal error resolving NTDLL.DLL symbols!\r\nSymbol: ";
+            DWORD               cbWritten;
+            if (   !WriteFile(GetStdHandle(STD_ERROR_HANDLE), s_szMsg, sizeof(s_szMsg) - 1, &cbWritten, NULL)
+                || !WriteFile(GetStdHandle(STD_ERROR_HANDLE), pszSym, (DWORD)strlen(pszSym), &cbWritten, NULL)
+                || !WriteFile(GetStdHandle(STD_ERROR_HANDLE), "\r\n", sizeof("\r\n") - 1, &cbWritten, NULL)
+                )
+                *(void **)i = NULL;
+            ExitProcess(127);
+        }
+    }
+
+    g_fResolvedNtImports = 1;
+}
+
+
+void *birdTmpAlloc(size_t cb)
+{
+    return malloc(cb);
+}
+
+
+void birdTmpFree(void *pv)
+{
+    if (pv)
+        free(pv);
+}
+
+
+void *birdMemAlloc(size_t cb)
+{
+    return malloc(cb);
+}
+
+
+void *birdMemAllocZ(size_t cb)
+{
+    return calloc(cb, 1);
+}
+
+
+void birdMemFree(void *pv)
+{
+    if (pv)
+        free(pv);
+}
+
+
+int birdErrnoFromNtStatus(MY_NTSTATUS rcNt)
+{
+    switch (rcNt)
+    {
+        /* EPERM            =  1 */
+        case STATUS_CANNOT_DELETE:
+        case STATUS_DELETE_PENDING:
+            return EPERM;
+        /* ENOENT           =  2 */
+        case STATUS_NOT_FOUND:
+        case STATUS_OBJECT_NAME_NOT_FOUND:
+        case STATUS_OBJECT_PATH_NOT_FOUND:
+        case STATUS_OBJECT_NAME_INVALID:
+        case STATUS_INVALID_COMPUTER_NAME:
+        case STATUS_VARIABLE_NOT_FOUND:
+        case STATUS_MESSAGE_NOT_FOUND:
+        case STATUS_DLL_NOT_FOUND:
+        case STATUS_ORDINAL_NOT_FOUND:
+        case STATUS_ENTRYPOINT_NOT_FOUND:
+        case STATUS_PATH_NOT_COVERED:
+        case STATUS_BAD_NETWORK_PATH:
+        case STATUS_DFS_EXIT_PATH_FOUND:
+        case RPC_NT_OBJECT_NOT_FOUND:
+            return ENOENT;
+        /* ESRCH            =  3 */
+        case STATUS_PROCESS_NOT_IN_JOB:
+            return ESRCH;
+        /* EINTR            =  4 */
+        case STATUS_ALERTED:
+        case STATUS_USER_APC:
+            return EINTR;
+        /* EIO              =  5 */
+        /* ENXIO            =  6 */
+        /* E2BIG            =  7 */
+        /* ENOEXEC          =  8 */
+        case STATUS_INVALID_IMAGE_FORMAT:
+        case STATUS_INVALID_IMAGE_NE_FORMAT:
+        case STATUS_INVALID_IMAGE_LE_FORMAT:
+        case STATUS_INVALID_IMAGE_NOT_MZ:
+        case STATUS_INVALID_IMAGE_PROTECT:
+        case STATUS_INVALID_IMAGE_WIN_16:
+        case STATUS_IMAGE_SUBSYSTEM_NOT_PRESENT:
+        case STATUS_IMAGE_CHECKSUM_MISMATCH:
+        case STATUS_IMAGE_MP_UP_MISMATCH:
+        case STATUS_IMAGE_MACHINE_TYPE_MISMATCH:
+        case STATUS_IMAGE_MACHINE_TYPE_MISMATCH_EXE:
+        case STATUS_SYSTEM_IMAGE_BAD_SIGNATURE:
+        case STATUS_SECTION_NOT_IMAGE:
+        case STATUS_INVALID_IMAGE_WIN_32:
+        case STATUS_INVALID_IMAGE_WIN_64:
+        case STATUS_INVALID_IMAGE_HASH:
+        case STATUS_IMAGE_CERT_REVOKED:
+            return ENOEXEC;
+        /* EBADF            =  9 */
+        case STATUS_INVALID_HANDLE:
+        case STATUS_PORT_CLOSED:
+        case STATUS_OPLOCK_HANDLE_CLOSED:
+        case STATUS_HANDLES_CLOSED:
+        case STATUS_FILE_FORCED_CLOSED:
+            return EBADF;
+        /* ECHILD           = 10 */
+        /* EAGAIN           = 11 */
+        case STATUS_WMI_TRY_AGAIN:
+        case STATUS_GRAPHICS_TRY_AGAIN_LATER:
+        case STATUS_GRAPHICS_TRY_AGAIN_NOW:
+            return EAGAIN;
+        /* ENOMEM           = 12 */
+        case STATUS_NO_MEMORY:
+        case STATUS_HV_INSUFFICIENT_MEMORY:
+        case STATUS_INSUFFICIENT_RESOURCES:
+        case STATUS_REMOTE_RESOURCES:
+        case STATUS_INSUFF_SERVER_RESOURCES:
+            return ENOMEM;
+        /* EACCES           = 13 */
+        case STATUS_ACCESS_DENIED:
+        case STATUS_NETWORK_ACCESS_DENIED:
+        case RPC_NT_PROXY_ACCESS_DENIED:
+        case STATUS_CTX_SHADOW_DENIED:
+        case STATUS_CTX_WINSTATION_ACCESS_DENIED:
+            return EACCES;
+        /* EFAULT           = 14 */
+        case STATUS_ACCESS_VIOLATION:
+        case STATUS_HARDWARE_MEMORY_ERROR:
+            return EFAULT;
+        /* EBUSY            = 16 */
+        case STATUS_PIPE_BUSY:
+        case STATUS_RESOURCE_IN_USE:
+            return EBUSY;
+        /* EEXIST           = 17 */
+        case STATUS_OBJECT_NAME_EXISTS:
+        case STATUS_OBJECT_NAME_COLLISION:
+        case STATUS_DUPLICATE_NAME:
+            return EEXIST;
+        /* EXDEV            = 18 */
+        case STATUS_NOT_SAME_DEVICE:
+            return EXDEV;
+        /* ENODEV           = 19 */
+        /* ENOTDIR          = 20 */
+        case STATUS_NOT_A_DIRECTORY:
+        case STATUS_DIRECTORY_IS_A_REPARSE_POINT:
+        case STATUS_OBJECT_PATH_SYNTAX_BAD:
+        case STATUS_OBJECT_PATH_INVALID:
+        case STATUS_OBJECT_TYPE_MISMATCH:
+            return ENOTDIR;
+        /* EISDIR           = 21 */
+        case STATUS_FILE_IS_A_DIRECTORY:
+            return EISDIR;
+        /* EINVAL           = 22 */
+        case STATUS_INVALID_PARAMETER:
+        case STATUS_INVALID_PARAMETER_1:
+        case STATUS_INVALID_PARAMETER_2:
+        case STATUS_INVALID_PARAMETER_3:
+        case STATUS_INVALID_PARAMETER_4:
+        case STATUS_INVALID_PARAMETER_5:
+        case STATUS_INVALID_PARAMETER_6:
+        case STATUS_INVALID_PARAMETER_7:
+        case STATUS_INVALID_PARAMETER_8:
+        case STATUS_INVALID_PARAMETER_9:
+        case STATUS_INVALID_PARAMETER_10:
+        case STATUS_INVALID_PARAMETER_11:
+        case STATUS_INVALID_PARAMETER_12:
+        case STATUS_INVALID_PARAMETER_MIX:
+            return EINVAL;
+        /* ENFILE           = 23 */
+        /* EMFILE           = 24 */
+        case STATUS_TOO_MANY_OPENED_FILES:
+            return EMFILE;
+        /* ENOTTY           = 25 */
+        /* EFBIG            = 27 */
+        /* ENOSPC           = 28 */
+        case STATUS_DISK_FULL:
+            return ENOSPC;
+        /* ESPIPE           = 29 */
+        /* EROFS            = 30 */
+        /* EMLINK           = 31 */
+        /* EPIPE            = 32 */
+        case STATUS_PIPE_BROKEN:
+        case RPC_NT_PIPE_CLOSED:
+            return EPIPE;
+        /* EDOM             = 33 */
+        /* ERANGE           = 34 */
+        /* EDEADLK          = 36 */
+        case STATUS_POSSIBLE_DEADLOCK:
+            return EDEADLK;
+        /* ENAMETOOLONG     = 38 */
+        case STATUS_NAME_TOO_LONG:
+            return ENAMETOOLONG;
+        /* ENOLCK           = 39 */
+        /* ENOSYS           = 40 */
+        case STATUS_NOT_SUPPORTED:
+            return ENOSYS;
+        /* ENOTEMPTY        = 41 */
+        case STATUS_DIRECTORY_NOT_EMPTY:
+            return ENOTEMPTY;
+        /* EILSEQ           = 42 */
+        /* EADDRINUSE       = 100 */
+        /* EADDRNOTAVAIL    = 101 */
+        /* EAFNOSUPPORT     = 102 */
+        /* EALREADY         = 103 */
+        case STATUS_INTERRUPT_VECTOR_ALREADY_CONNECTED:
+        case STATUS_DEVICE_ALREADY_ATTACHED:
+        case STATUS_PORT_ALREADY_SET:
+        case STATUS_IMAGE_ALREADY_LOADED:
+        case STATUS_TOKEN_ALREADY_IN_USE:
+        case STATUS_IMAGE_ALREADY_LOADED_AS_DLL:
+        case STATUS_ADDRESS_ALREADY_EXISTS:
+        case STATUS_ADDRESS_ALREADY_ASSOCIATED:
+            return EALREADY;
+        /* EBADMSG          = 104 */
+        /* ECANCELED        = 105 */
+        /* ECONNABORTED     = 106 */
+        /* ECONNREFUSED     = 107 */
+        /* ECONNRESET       = 108 */
+        /* EDESTADDRREQ     = 109 */
+        /* EHOSTUNREACH     = 110 */
+        case STATUS_HOST_UNREACHABLE:
+            return EHOSTUNREACH;
+        /* EIDRM            = 111 */
+        /* EINPROGRESS      = 112 */
+        /* EISCONN          = 113 */
+        /* ELOOP            = 114 */
+        /* EMSGSIZE         = 115 */
+        /* ENETDOWN         = 116 */
+        /* ENETRESET        = 117 */
+        /* ENETUNREACH      = 118 */
+        case STATUS_NETWORK_UNREACHABLE:
+            return ENETUNREACH;
+        /* ENOBUFS          = 119 */
+        /* ENODATA          = 120 */
+        /* ENOLINK          = 121 */
+        /* ENOMSG           = 122 */
+        /* ENOPROTOOPT      = 123 */
+        /* ENOSR            = 124 */
+        /* ENOSTR           = 125 */
+        /* ENOTCONN         = 126 */
+        /* ENOTRECOVERABLE  = 127 */
+        /* ENOTSOCK         = 128 */
+        /* ENOTSUP          = 129 */
+        /* EOPNOTSUPP       = 130 */
+        /* EOTHER           = 131 */
+        /* EOVERFLOW        = 132 */
+        /* EOWNERDEAD       = 133 */
+        /* EPROTO           = 134 */
+        /* EPROTONOSUPPORT  = 135 */
+        /* EPROTOTYPE       = 136 */
+        /* ETIME            = 137 */
+        /* ETIMEDOUT        = 138 */
+        case STATUS_VIRTUAL_CIRCUIT_CLOSED:
+        case STATUS_TIMEOUT:
+            return ETIMEDOUT;
+
+        /* ETXTBSY          = 139 */
+        case STATUS_SHARING_VIOLATION:
+            return ETXTBSY;
+        /* EWOULDBLOCK      = 140 */
+    }
+
+#ifndef NDEBUG
+    __debugbreak();
+    fprintf(stderr, "rcNt=%#x (%d)\n", rcNt, rcNt);
+#endif
+    return EINVAL;
+}
+
+
+int birdSetErrnoFromNt(MY_NTSTATUS rcNt)
+{
+    errno = birdErrnoFromNtStatus(rcNt);
+    return -1;
+}
+
+
+int birdSetErrnoFromWin32(DWORD dwErr)
+{
+    switch (dwErr)
+    {
+        default:
+        case ERROR_INVALID_FUNCTION:        errno = EINVAL; break;
+        case ERROR_FILE_NOT_FOUND:          errno = ENOENT; break;
+        case ERROR_PATH_NOT_FOUND:          errno = ENOENT; break;
+        case ERROR_TOO_MANY_OPEN_FILES:     errno = EMFILE; break;
+        case ERROR_ACCESS_DENIED:           errno = EACCES; break;
+        case ERROR_INVALID_HANDLE:          errno = EBADF; break;
+        case ERROR_ARENA_TRASHED:           errno = ENOMEM; break;
+        case ERROR_NOT_ENOUGH_MEMORY:       errno = ENOMEM; break;
+        case ERROR_INVALID_BLOCK:           errno = ENOMEM; break;
+        case ERROR_BAD_ENVIRONMENT:         errno = E2BIG; break;
+        case ERROR_BAD_FORMAT:              errno = ENOEXEC; break;
+        case ERROR_INVALID_ACCESS:          errno = EINVAL; break;
+        case ERROR_INVALID_DATA:            errno = EINVAL; break;
+        case ERROR_INVALID_DRIVE:           errno = ENOENT; break;
+        case ERROR_CURRENT_DIRECTORY:       errno = EACCES; break;
+        case ERROR_NOT_SAME_DEVICE:         errno = EXDEV; break;
+        case ERROR_NO_MORE_FILES:           errno = ENOENT; break;
+        case ERROR_LOCK_VIOLATION:          errno = EACCES; break;
+        case ERROR_BAD_NETPATH:             errno = ENOENT; break;
+        case ERROR_NETWORK_ACCESS_DENIED:   errno = EACCES; break;
+        case ERROR_BAD_NET_NAME:            errno = ENOENT; break;
+        case ERROR_FILE_EXISTS:             errno = EEXIST; break;
+        case ERROR_CANNOT_MAKE:             errno = EACCES; break;
+        case ERROR_FAIL_I24:                errno = EACCES; break;
+        case ERROR_INVALID_PARAMETER:       errno = EINVAL; break;
+        case ERROR_NO_PROC_SLOTS:           errno = EAGAIN; break;
+        case ERROR_DRIVE_LOCKED:            errno = EACCES; break;
+        case ERROR_BROKEN_PIPE:             errno = EPIPE; break;
+        case ERROR_DISK_FULL:               errno = ENOSPC; break;
+        case ERROR_INVALID_TARGET_HANDLE:   errno = EBADF; break;
+        case ERROR_WAIT_NO_CHILDREN:        errno = ECHILD; break;
+        case ERROR_CHILD_NOT_COMPLETE:      errno = ECHILD; break;
+        case ERROR_DIRECT_ACCESS_HANDLE:    errno = EBADF; break;
+        case ERROR_NEGATIVE_SEEK:           errno = EINVAL; break;
+        case ERROR_SEEK_ON_DEVICE:          errno = EACCES; break;
+        case ERROR_DIR_NOT_EMPTY:           errno = ENOTEMPTY; break;
+        case ERROR_NOT_LOCKED:              errno = EACCES; break;
+        case ERROR_BAD_PATHNAME:            errno = ENOENT; break;
+        case ERROR_MAX_THRDS_REACHED:       errno = EAGAIN; break;
+        case ERROR_LOCK_FAILED:             errno = EACCES; break;
+        case ERROR_ALREADY_EXISTS:          errno = EEXIST; break;
+        case ERROR_FILENAME_EXCED_RANGE:    errno = ENOENT; break;
+        case ERROR_NESTING_NOT_ALLOWED:     errno = EAGAIN; break;
+#ifdef EMLINK
+        case ERROR_TOO_MANY_LINKS:          errno = EMLINK; break;
+#endif
+
+        case ERROR_SHARING_VIOLATION:
+            errno = ETXTBSY;
+            break;
+    }
+
+    return -1;
+}
+
+
+int birdSetErrnoToNoMem(void)
+{
+    errno = ENOMEM;
+    return -1;
+}
+
+
+int birdSetErrnoToInvalidArg(void)
+{
+    errno = EINVAL;
+    return -1;
+}
+
+
+int birdSetErrnoToBadFileNo(void)
+{
+    errno = EBADF;
+    return -1;
+}
+
diff --git a/src/lib/nt/nthlpfs.c b/src/lib/nt/nthlpfs.c
new file mode 100644
index 0000000..d2e7f45
--- /dev/null
+++ b/src/lib/nt/nthlpfs.c
@@ -0,0 +1,306 @@
+/* $Id: nthlpfs.c 2713 2013-11-21 21:11:00Z bird $ */
+/** @file
+ * MSC + NT helpers for file system related functions.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include "nthlp.h"
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+static int g_fHaveOpenReparsePoint = -1;
+
+
+
+static int birdHasTrailingSlash(const char *pszPath)
+{
+    char ch, ch2;
+
+    /* Skip leading slashes. */
+    while ((ch = *pszPath) == '/' || ch == '\\')
+        pszPath++;
+    if (ch == '\0')
+        return 0;
+
+    /* Find the last char. */
+    while ((ch2 = *++pszPath) != '\0')
+        ch = ch2;
+
+    return ch == '/' || ch == '\\' || ch == ':';
+}
+
+
+static int birdIsPathDirSpec(const char *pszPath)
+{
+    char ch, ch2;
+
+    /* Check for empty string. */
+    ch = *pszPath;
+    if (ch == '\0')
+        return 0;
+
+    /* Find the last char. */
+    while ((ch2 = *++pszPath) != '\0')
+        ch = ch2;
+
+    return ch == '/' || ch == '\\' || ch == ':';
+}
+
+
+int birdDosToNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath)
+{
+    MY_NTSTATUS         rcNt;
+    WCHAR               wszTmp[4096];
+    MY_UNICODE_STRING   TmpUniStr;
+    MY_ANSI_STRING      Src;
+
+    birdResolveImports();
+
+    pNtPath->Length = pNtPath->MaximumLength = 0;
+    pNtPath->Buffer = NULL;
+
+    /*
+     * Convert the input to wide char.
+     */
+    Src.Buffer              = (PCHAR)pszPath;
+    Src.MaximumLength       = Src.Length = (USHORT)strlen(pszPath);
+
+    TmpUniStr.Length        = 0;
+    TmpUniStr.MaximumLength = sizeof(wszTmp) - sizeof(WCHAR);
+    TmpUniStr.Buffer        = wszTmp;
+
+    rcNt = g_pfnRtlAnsiStringToUnicodeString(&TmpUniStr, &Src, FALSE);
+    if (MY_NT_SUCCESS(rcNt))
+    {
+        if (TmpUniStr.Length > 0 && !(TmpUniStr.Length & 1))
+        {
+            wszTmp[TmpUniStr.Length / sizeof(WCHAR)] = '\0';
+
+            /*
+             * Convert the wide DOS path to an NT path.
+             */
+            if (g_pfnRtlDosPathNameToNtPathName_U(wszTmp, pNtPath, NULL, FALSE))
+                return 0;
+        }
+        rcNt = -1;
+    }
+    return birdSetErrnoFromNt(rcNt);
+}
+
+
+void birdFreeNtPath(MY_UNICODE_STRING *pNtPath)
+{
+    HeapFree(GetProcessHeap(), 0, pNtPath->Buffer);
+    pNtPath->Buffer = NULL;
+    pNtPath->Length = 0;
+    pNtPath->MaximumLength = 0;
+}
+
+
+MY_NTSTATUS birdOpenFileUniStr(MY_UNICODE_STRING *pNtPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
+                               ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
+                               HANDLE *phFile)
+{
+    MY_IO_STATUS_BLOCK      Ios;
+    MY_OBJECT_ATTRIBUTES    ObjAttr;
+    MY_NTSTATUS             rcNt;
+
+    birdResolveImports();
+
+    if (  (fCreateOptions & FILE_OPEN_REPARSE_POINT)
+        && g_fHaveOpenReparsePoint == 0)
+        fCreateOptions &= ~FILE_OPEN_REPARSE_POINT;
+
+    Ios.Information = -1;
+    Ios.u.Status = 0;
+    MyInitializeObjectAttributes(&ObjAttr, pNtPath, fObjAttribs, NULL /*hRoot*/, NULL /*pSecAttr*/);
+
+    rcNt = g_pfnNtCreateFile(phFile,
+                             fDesiredAccess,
+                             &ObjAttr,
+                             &Ios,
+                             NULL,   /* cbFileInitialAlloc */
+                             fFileAttribs,
+                             fShareAccess,
+                             fCreateDisposition,
+                             fCreateOptions,
+                             NULL,   /* pEaBuffer */
+                             0);     /* cbEaBuffer*/
+    if (   rcNt == STATUS_INVALID_PARAMETER
+        && g_fHaveOpenReparsePoint < 0
+        && (fCreateOptions & FILE_OPEN_REPARSE_POINT))
+    {
+        fCreateOptions &= ~FILE_OPEN_REPARSE_POINT;
+
+        Ios.Information = -1;
+        Ios.u.Status = 0;
+        MyInitializeObjectAttributes(&ObjAttr, pNtPath, fObjAttribs, NULL /*hRoot*/, NULL /*pSecAttr*/);
+
+        rcNt = g_pfnNtCreateFile(phFile,
+                                 fDesiredAccess,
+                                 &ObjAttr,
+                                 &Ios,
+                                 NULL,   /* cbFileInitialAlloc */
+                                 fFileAttribs,
+                                 fShareAccess,
+                                 fCreateDisposition,
+                                 fCreateOptions,
+                                 NULL,   /* pEaBuffer */
+                                 0);     /* cbEaBuffer*/
+        if (rcNt != STATUS_INVALID_PARAMETER)
+            g_fHaveOpenReparsePoint = 0;
+    }
+    return rcNt;
+}
+
+
+HANDLE birdOpenFile(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs, ULONG fShareAccess,
+                    ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs)
+{
+    MY_UNICODE_STRING   NtPath;
+    MY_NTSTATUS         rcNt;
+
+    /*
+     * Adjust inputs.
+     */
+    if (birdIsPathDirSpec(pszPath))
+        fCreateOptions |= FILE_DIRECTORY_FILE;
+
+    /*
+     * Call the NT API directly.
+     */
+    if (birdDosToNtPath(pszPath, &NtPath) == 0)
+    {
+        HANDLE hFile;
+        rcNt = birdOpenFileUniStr(&NtPath, fDesiredAccess, fFileAttribs, fShareAccess,
+                                  fCreateDisposition, fCreateOptions, fObjAttribs, &hFile);
+        if (MY_NT_SUCCESS(rcNt))
+        {
+            birdFreeNtPath(&NtPath);
+            return hFile;
+        }
+
+        birdFreeNtPath(&NtPath);
+        birdSetErrnoFromNt(rcNt);
+    }
+
+    return INVALID_HANDLE_VALUE;
+}
+
+
+HANDLE birdOpenParentDir(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs, ULONG fShareAccess,
+                         ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
+                         MY_UNICODE_STRING *pNameUniStr)
+{
+    MY_UNICODE_STRING   NtPath;
+    MY_NTSTATUS         rcNt;
+
+    /*
+     * Adjust inputs.
+     */
+    fCreateOptions |= FILE_DIRECTORY_FILE;
+
+    /*
+     * Convert the path and split off the filename.
+     */
+    if (birdDosToNtPath(pszPath, &NtPath) == 0)
+    {
+        USHORT offName = NtPath.Length / sizeof(WCHAR);
+        USHORT cwcName = offName;
+        WCHAR  wc = 0;
+
+        while (   offName > 0
+               && (wc = NtPath.Buffer[offName - 1]) != '\\'
+               && wc != '/'
+               && wc != ':')
+            offName--;
+        if (offName > 0)
+        {
+            cwcName -= offName;
+
+            /* Make a copy of the file name, if requested. */
+            rcNt = STATUS_SUCCESS;
+            if (pNameUniStr)
+            {
+                pNameUniStr->Length        = cwcName * sizeof(WCHAR);
+                pNameUniStr->MaximumLength = pNameUniStr->Length + sizeof(WCHAR);
+                pNameUniStr->Buffer        = (WCHAR *)HeapAlloc(GetProcessHeap(), 0, pNameUniStr->MaximumLength);
+                if (pNameUniStr->Buffer)
+                {
+                    memcpy(pNameUniStr->Buffer, &NtPath.Buffer[offName],pNameUniStr->Length);
+                    pNameUniStr->Buffer[cwcName] = '\0';
+                }
+                else
+                    rcNt = STATUS_NO_MEMORY;
+            }
+
+            /* Chop, chop. */
+            // Bad idea, breaks \\?\c:\pagefile.sys. //while (   offName > 0
+            // Bad idea, breaks \\?\c:\pagefile.sys. //       && (   (wc = NtPath.Buffer[offName - 1]) == '\\'
+            // Bad idea, breaks \\?\c:\pagefile.sys. //           || wc == '/'))
+            // Bad idea, breaks \\?\c:\pagefile.sys. //    offName--;
+            NtPath.Length = offName * sizeof(WCHAR);
+            NtPath.Buffer[offName] = '\0';
+            if (MY_NT_SUCCESS(rcNt))
+            {
+                /*
+                 * Finally, try open the directory.
+                 */
+                HANDLE hFile;
+                rcNt = birdOpenFileUniStr(&NtPath, fDesiredAccess, fFileAttribs, fShareAccess,
+                                          fCreateDisposition, fCreateOptions, fObjAttribs, &hFile);
+                if (MY_NT_SUCCESS(rcNt))
+                {
+                    birdFreeNtPath(&NtPath);
+                    return hFile;
+                }
+            }
+
+            if (pNameUniStr)
+                birdFreeNtPath(pNameUniStr);
+        }
+
+        birdFreeNtPath(&NtPath);
+        birdSetErrnoFromNt(rcNt);
+    }
+
+    return INVALID_HANDLE_VALUE;
+}
+
+
+void birdCloseFile(HANDLE hFile)
+{
+    birdResolveImports();
+    g_pfnNtClose(hFile);
+}
+
diff --git a/src/lib/nt/ntstat.c b/src/lib/nt/ntstat.c
new file mode 100644
index 0000000..d6a4a3a
--- /dev/null
+++ b/src/lib/nt/ntstat.c
@@ -0,0 +1,613 @@
+/* $Id: ntstat.c 2710 2013-11-21 14:40:10Z bird $ */
+/** @file
+ * MSC + NT stat, lstat and fstat.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <stdio.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include "ntstuff.h"
+#include "nthlp.h"
+#include "ntstat.h"
+
+
+#undef stat
+
+static int birdIsExecutableExtension(const char *pszExt)
+{
+    return  !strcmp(pszExt, "exe")
+         || !strcmp(pszExt, "cmd")
+         || !strcmp(pszExt, "bat")
+         || !strcmp(pszExt, "vbs")
+         || !strcmp(pszExt, "com")
+         ;
+}
+
+
+static int birdIsFileExecutable(const char *pszName)
+{
+    const char     *pszExt = NULL;
+    char            szExt[8];
+    size_t          cchExt;
+    unsigned        i;
+    char            ch;
+
+    /* Look for a 3 char extension. */
+    ch = *pszName++;
+    if (!ch)
+        return 0;
+
+    while ((ch = *pszName++) != '\0')
+        if (ch == '.')
+            pszExt = pszName;
+
+    if (!pszExt)
+        return 0;
+    pszExt++;
+    cchExt = pszName - pszExt;
+    if (cchExt != 3)
+        return 0;
+
+    /* Copy the extension out and lower case it. */
+    for (i = 0; i < cchExt; i++, pszExt++)
+    {
+        ch = *pszExt;
+        if (ch >= 'A' && ch <= 'Z')
+            ch += 'a' - 'A';
+        szExt[i] = ch;
+    }
+    szExt[i] = '\0';
+
+    return birdIsExecutableExtension(szExt);
+}
+
+
+static int birdIsFileExecutableW(WCHAR const *pwcName, ULONG cwcName)
+{
+    char            szExt[8];
+    unsigned        cchExt;
+    unsigned        i;
+    WCHAR const    *pwc;
+
+    /* Look for a 3 char extension. */
+    if (cwcName > 2 && pwcName[cwcName - 2] == '.')
+        return 0;
+    else if (cwcName > 3 && pwcName[cwcName - 3] == '.')
+        return 0;
+    else if (cwcName > 4 && pwcName[cwcName - 4] == '.')
+        cchExt = 3;
+    else
+        return 0;
+
+    /* Copy the extension out and lower case it. */
+    pwc = &pwcName[cwcName - cchExt];
+    for (i = 0; i < cchExt; i++, pwc++)
+    {
+        WCHAR wc = *pwc;
+        if (wc >= 'A' && wc <= 'Z')
+            wc += 'a' - 'A';
+        else if (wc > 255)
+            wc = 255;
+        szExt[i] = (char)wc;
+    }
+    szExt[i] = '\0';
+
+    return birdIsExecutableExtension(szExt);
+}
+
+
+static unsigned short birdFileInfoToMode(HANDLE hFile, ULONG fAttribs, const char *pszName,
+                                         MY_FILE_NAME_INFORMATION *pNameInfo, __int16 *pfIsDirSymlink)
+{
+    unsigned short fMode;
+
+    /* File type. */
+    if (  (fAttribs & FILE_ATTRIBUTE_REPARSE_POINT)
+        && hFile != INVALID_HANDLE_VALUE)
+    {
+        MY_FILE_ATTRIBUTE_TAG_INFORMATION   TagInfo;
+        MY_IO_STATUS_BLOCK                  Ios;
+        MY_NTSTATUS                         rcNt;
+        Ios.Information = 0;
+        Ios.u.Status    = -1;
+        rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, &TagInfo, sizeof(TagInfo), MyFileAttributeTagInformation);
+        if (   !MY_NT_SUCCESS(rcNt)
+            || !MY_NT_SUCCESS(Ios.u.Status)
+            || TagInfo.ReparseTag != IO_REPARSE_TAG_SYMLINK)
+            fAttribs &= ~FILE_ATTRIBUTE_REPARSE_POINT;
+    }
+
+    if (fAttribs & FILE_ATTRIBUTE_REPARSE_POINT)
+    {
+        *pfIsDirSymlink = !!(fAttribs & FILE_ATTRIBUTE_DIRECTORY);
+        fMode = S_IFLNK;
+    }
+    else
+    {
+        *pfIsDirSymlink = 0;
+        if (fAttribs & FILE_ATTRIBUTE_DIRECTORY)
+            fMode = S_IFDIR;
+        else
+            fMode = S_IFREG;
+    }
+
+    /* Access mask. */
+    fMode |= S_IROTH | S_IRGRP | S_IRUSR;
+    if (!(fAttribs & FILE_ATTRIBUTE_READONLY))
+        fMode |= S_IWOTH | S_IWGRP | S_IWUSR;
+    if (   (fAttribs & FILE_ATTRIBUTE_DIRECTORY)
+        || (pszName
+            ? birdIsFileExecutable(pszName)
+            : birdIsFileExecutableW(pNameInfo->FileName, pNameInfo->FileNameLength)) )
+        fMode |= S_IXOTH | S_IXGRP | S_IXUSR;
+
+    return fMode;
+}
+
+
+static void birdNtTimeToTimeSpec(__int64 iNtTime, BirdTimeSpec_T *pTimeSpec)
+{
+    iNtTime -= BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
+    pTimeSpec->tv_sec  = iNtTime / 10000000;
+    pTimeSpec->tv_nsec = (iNtTime % 10000000) * 100;
+}
+
+
+/**
+ * Fills in a stat structure from an MY_FILE_ID_FULL_DIR_INFORMATION entry.
+ *
+ * @param   pStat               The stat structure.
+ * @param   pBuf                The MY_FILE_ID_FULL_DIR_INFORMATION entry.
+ * @param   pszPath             Optionally, the path for X bit checks.
+ */
+void birdStatFillFromFileIdFullDirInfo(BirdStat_T *pStat, MY_FILE_ID_FULL_DIR_INFORMATION const *pBuf, const char *pszPath)
+{
+    pStat->st_mode          = birdFileInfoToMode(INVALID_HANDLE_VALUE, pBuf->FileAttributes, pszPath,
+                                                 NULL, &pStat->st_dirsymlink);
+    pStat->st_padding0[0]   = 0;
+    pStat->st_padding0[1]   = 0;
+    pStat->st_size          = pBuf->EndOfFile.QuadPart;
+    birdNtTimeToTimeSpec(pBuf->CreationTime.QuadPart,   &pStat->st_birthtim);
+    birdNtTimeToTimeSpec(pBuf->ChangeTime.QuadPart,     &pStat->st_ctim);
+    birdNtTimeToTimeSpec(pBuf->LastWriteTime.QuadPart,  &pStat->st_mtim);
+    birdNtTimeToTimeSpec(pBuf->LastAccessTime.QuadPart, &pStat->st_atim);
+    pStat->st_ino           = pBuf->FileId.QuadPart;
+    pStat->st_nlink         = 1;
+    pStat->st_rdev          = 0;
+    pStat->st_uid           = 0;
+    pStat->st_gid           = 0;
+    pStat->st_padding1[0]   = 0;
+    pStat->st_padding1[1]   = 0;
+    pStat->st_padding1[2]   = 0;
+    pStat->st_blksize       = 65536;
+    pStat->st_blocks        = (pBuf->AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
+                            / BIRD_STAT_BLOCK_SIZE;
+}
+
+
+int birdStatHandle(HANDLE hFile, BirdStat_T *pStat, const char *pszPath)
+{
+    int                      rc;
+    MY_NTSTATUS              rcNt;
+#if 0
+    ULONG                    cbAll = sizeof(MY_FILE_ALL_INFORMATION) + 0x10000;
+    MY_FILE_ALL_INFORMATION *pAll  = (MY_FILE_ALL_INFORMATION *)birdTmpAlloc(cbAll);
+    if (pAll)
+    {
+        MY_IO_STATUS_BLOCK Ios;
+        Ios.Information = 0;
+        Ios.u.Status    = -1;
+        rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, pAll, cbAll, MyFileAllInformation);
+        if (MY_NT_SUCCESS(rcNt))
+            rcNt = Ios.u.Status;
+        if (MY_NT_SUCCESS(rcNt))
+        {
+            pStat->st_mode          = birdFileInfoToMode(hFile, pAll->BasicInformation.FileAttributes, pszPath,
+                                                         &pAll->NameInformation, &pStat->st_dirsymlink);
+            pStat->st_padding0[0]   = 0;
+            pStat->st_padding0[1]   = 0;
+            pStat->st_size          = pAll->StandardInformation.EndOfFile.QuadPart;
+            birdNtTimeToTimeSpec(pAll->BasicInformation.CreationTime.QuadPart,   &pStat->st_birthtim);
+            birdNtTimeToTimeSpec(pAll->BasicInformation.ChangeTime.QuadPart,     &pStat->st_ctim);
+            birdNtTimeToTimeSpec(pAll->BasicInformation.LastWriteTime.QuadPart,  &pStat->st_mtim);
+            birdNtTimeToTimeSpec(pAll->BasicInformation.LastAccessTime.QuadPart, &pStat->st_atim);
+            pStat->st_ino           = pAll->InternalInformation.IndexNumber.QuadPart;
+            pStat->st_nlink         = pAll->StandardInformation.NumberOfLinks;
+            pStat->st_rdev          = 0;
+            pStat->st_uid           = 0;
+            pStat->st_gid           = 0;
+            pStat->st_padding1[0]   = 0;
+            pStat->st_padding1[1]   = 0;
+            pStat->st_padding1[2]   = 0;
+            pStat->st_blksize       = 65536;
+            pStat->st_blocks        = (pAll->StandardInformation.AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
+                                    / BIRD_STAT_BLOCK_SIZE;
+
+            /* Get the serial number, reusing the buffer from above. */
+            rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, pAll, cbAll, MyFileFsVolumeInformation);
+            if (MY_NT_SUCCESS(rcNt))
+                rcNt = Ios.u.Status;
+            if (MY_NT_SUCCESS(rcNt))
+            {
+                MY_FILE_FS_VOLUME_INFORMATION const *pVolInfo = (MY_FILE_FS_VOLUME_INFORMATION const *)pAll;
+                pStat->st_dev       = pVolInfo->VolumeSerialNumber
+                                    | (pVolInfo->VolumeCreationTime.QuadPart << 32);
+                rc = 0;
+            }
+            else
+            {
+                pStat->st_dev       = 0;
+                rc = birdSetErrnoFromNt(rcNt);
+            }
+        }
+        else
+            rc = birdSetErrnoFromNt(rcNt);
+    }
+    else
+        rc = birdSetErrnoToNoMem();
+#else
+    ULONG                           cbNameInfo = 0;
+    MY_FILE_NAME_INFORMATION       *pNameInfo  = NULL;
+    MY_FILE_STANDARD_INFORMATION    StdInfo;
+    MY_FILE_BASIC_INFORMATION       BasicInfo;
+    MY_FILE_INTERNAL_INFORMATION    InternalInfo;
+    MY_IO_STATUS_BLOCK              Ios;
+
+    Ios.Information = 0;
+    Ios.u.Status    = -1;
+    rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, &StdInfo, sizeof(StdInfo), MyFileStandardInformation);
+    if (MY_NT_SUCCESS(rcNt))
+        rcNt = Ios.u.Status;
+    if (MY_NT_SUCCESS(rcNt))
+        rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, &BasicInfo, sizeof(BasicInfo), MyFileBasicInformation);
+    if (MY_NT_SUCCESS(rcNt))
+        rcNt = Ios.u.Status;
+    if (MY_NT_SUCCESS(rcNt))
+        rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, &InternalInfo, sizeof(InternalInfo), MyFileInternalInformation);
+    if (MY_NT_SUCCESS(rcNt))
+        rcNt = Ios.u.Status;
+    if (MY_NT_SUCCESS(rcNt) && !pszPath)
+    {
+        cbNameInfo = 0x10020;
+        pNameInfo  = (MY_FILE_NAME_INFORMATION *)alloca(cbNameInfo);
+        rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, pNameInfo, cbNameInfo, MyFileNameInformation);
+        if (MY_NT_SUCCESS(rcNt))
+            rcNt = Ios.u.Status;
+    }
+
+    if (MY_NT_SUCCESS(rcNt))
+    {
+        pStat->st_mode          = birdFileInfoToMode(hFile, BasicInfo.FileAttributes, pszPath,
+                                                     pNameInfo, &pStat->st_dirsymlink);
+        pStat->st_padding0[0]   = 0;
+        pStat->st_padding0[1]   = 0;
+        pStat->st_size          = StdInfo.EndOfFile.QuadPart;
+        birdNtTimeToTimeSpec(BasicInfo.CreationTime.QuadPart,   &pStat->st_birthtim);
+        birdNtTimeToTimeSpec(BasicInfo.ChangeTime.QuadPart,     &pStat->st_ctim);
+        birdNtTimeToTimeSpec(BasicInfo.LastWriteTime.QuadPart,  &pStat->st_mtim);
+        birdNtTimeToTimeSpec(BasicInfo.LastAccessTime.QuadPart, &pStat->st_atim);
+        pStat->st_ino           = InternalInfo.IndexNumber.QuadPart;
+        pStat->st_nlink         = StdInfo.NumberOfLinks;
+        pStat->st_rdev          = 0;
+        pStat->st_uid           = 0;
+        pStat->st_gid           = 0;
+        pStat->st_padding1[0]   = 0;
+        pStat->st_padding1[1]   = 0;
+        pStat->st_padding1[2]   = 0;
+        pStat->st_blksize       = 65536;
+        pStat->st_blocks        = (StdInfo.AllocationSize.QuadPart + BIRD_STAT_BLOCK_SIZE - 1)
+                                / BIRD_STAT_BLOCK_SIZE;
+
+        /* Get the serial number, reusing the buffer from above. */
+        if (!cbNameInfo)
+        {
+            cbNameInfo = sizeof(MY_FILE_FS_VOLUME_INFORMATION) + 1024;
+            pNameInfo  = (MY_FILE_NAME_INFORMATION *)alloca(cbNameInfo);
+        }
+        rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, pNameInfo, cbNameInfo, MyFileFsVolumeInformation);
+        if (MY_NT_SUCCESS(rcNt))
+            rcNt = Ios.u.Status;
+        if (MY_NT_SUCCESS(rcNt))
+        {
+            MY_FILE_FS_VOLUME_INFORMATION const *pVolInfo = (MY_FILE_FS_VOLUME_INFORMATION const *)pNameInfo;
+            pStat->st_dev       = pVolInfo->VolumeSerialNumber
+                                | (pVolInfo->VolumeCreationTime.QuadPart << 32);
+            rc = 0;
+        }
+        else
+        {
+            pStat->st_dev       = 0;
+            rc = birdSetErrnoFromNt(rcNt);
+        }
+    }
+    else
+        rc = birdSetErrnoFromNt(rcNt);
+
+#endif
+    return rc;
+}
+
+
+static int birdStatInternal(const char *pszPath, BirdStat_T *pStat, int fFollow)
+{
+    int rc;
+    HANDLE hFile = birdOpenFile(pszPath,
+                                FILE_READ_ATTRIBUTES,
+                                FILE_ATTRIBUTE_NORMAL,
+                                FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                FILE_OPEN,
+                                FILE_OPEN_FOR_BACKUP_INTENT | (fFollow ? 0 : FILE_OPEN_REPARSE_POINT),
+                                OBJ_CASE_INSENSITIVE);
+    if (hFile != INVALID_HANDLE_VALUE)
+    {
+        rc = birdStatHandle(hFile, pStat, pszPath);
+        birdCloseFile(hFile);
+
+#if 0
+        {
+            static char s_szPrev[256];
+            size_t cchPath = strlen(pszPath);
+            if (memcmp(s_szPrev, pszPath, cchPath >= 255 ? 255 : cchPath + 1) == 0)
+                fprintf(stderr, "stat: %s -> rc/errno=%d/%u\n", pszPath, rc, errno);
+            else
+                memcpy(s_szPrev, pszPath, cchPath + 1);
+        }
+#endif
+        //fprintf(stderr, "stat: %s -> rc/errno=%d/%u\n", pszPath, rc, errno);
+    }
+    else
+    {
+        //fprintf(stderr, "stat: %s -> %u\n", pszPath, GetLastError());
+
+        /*
+         * On things like pagefile.sys we may get sharing violation.  We fall
+         * back on directory enumeration for dealing with that.
+         */
+        if (   errno == ETXTBSY
+            && strchr(pszPath, '*') == NULL /* Serious paranoia... */
+            && strchr(pszPath, '?') == NULL)
+        {
+            MY_UNICODE_STRING NameUniStr;
+            hFile = birdOpenParentDir(pszPath,
+                                      FILE_READ_DATA | SYNCHRONIZE,
+                                      FILE_ATTRIBUTE_NORMAL,
+                                      FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                      FILE_OPEN,
+                                      FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
+                                      OBJ_CASE_INSENSITIVE,
+                                      &NameUniStr);
+            if (hFile != INVALID_HANDLE_VALUE)
+            {
+                MY_FILE_ID_FULL_DIR_INFORMATION *pBuf;
+                ULONG               cbBuf = sizeof(*pBuf) + NameUniStr.MaximumLength + 1024;
+                MY_IO_STATUS_BLOCK  Ios;
+                MY_NTSTATUS         rcNt;
+
+                pBuf = (MY_FILE_ID_FULL_DIR_INFORMATION *)alloca(cbBuf);
+                Ios.u.Status    = -1;
+                Ios.Information = -1;
+                rcNt = g_pfnNtQueryDirectoryFile(hFile, NULL, NULL, NULL, &Ios, pBuf, cbBuf,
+                                                 MyFileIdFullDirectoryInformation, FALSE, &NameUniStr, TRUE);
+                if (MY_NT_SUCCESS(rcNt))
+                    rcNt = Ios.u.Status;
+                if (MY_NT_SUCCESS(rcNt))
+                {
+                    /*
+                     * Convert the data.
+                     */
+                    birdStatFillFromFileIdFullDirInfo(pStat, pBuf, pszPath);
+
+                    /* Get the serial number, reusing the buffer from above. */
+                    rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, pBuf, cbBuf, MyFileFsVolumeInformation);
+                    if (MY_NT_SUCCESS(rcNt))
+                        rcNt = Ios.u.Status;
+                    if (MY_NT_SUCCESS(rcNt))
+                    {
+                        MY_FILE_FS_VOLUME_INFORMATION const *pVolInfo = (MY_FILE_FS_VOLUME_INFORMATION const *)pBuf;
+                        pStat->st_dev       = pVolInfo->VolumeSerialNumber
+                                            | (pVolInfo->VolumeCreationTime.QuadPart << 32);
+                        rc = 0;
+                    }
+                    else
+                    {
+                        pStat->st_dev       = 0;
+                        rc = birdSetErrnoFromNt(rcNt);
+                    }
+                }
+
+                birdFreeNtPath(&NameUniStr);
+                birdCloseFile(hFile);
+
+                if (MY_NT_SUCCESS(rcNt))
+                    return 0;
+                birdSetErrnoFromNt(rcNt);
+            }
+        }
+        rc = -1;
+    }
+
+    return rc;
+}
+
+
+/**
+ * Implements UNIX fstat().
+ */
+int birdStatOnFd(int fd, BirdStat_T *pStat)
+{
+    int     rc;
+    HANDLE  hFile = (HANDLE)_get_osfhandle(fd);
+    if (hFile != INVALID_HANDLE_VALUE)
+    {
+        DWORD fFileType;
+
+        birdResolveImports();
+
+        SetLastError(NO_ERROR);
+        fFileType = GetFileType(hFile) & ~FILE_TYPE_REMOTE;
+        switch (fFileType)
+        {
+            case FILE_TYPE_DISK:
+                rc = birdStatHandle(hFile, pStat, NULL);
+                break;
+
+            case FILE_TYPE_CHAR:
+            case FILE_TYPE_PIPE:
+                if (fFileType == FILE_TYPE_PIPE)
+                    pStat->st_mode          = S_IFIFO | 0666;
+                else
+                    pStat->st_mode          = S_IFCHR | 0666;
+                pStat->st_padding0[0]       = 0;
+                pStat->st_padding0[1]       = 0;
+                pStat->st_size              = 0;
+                pStat->st_atim.tv_sec       = 0;
+                pStat->st_atim.tv_nsec      = 0;
+                pStat->st_mtim.tv_sec       = 0;
+                pStat->st_mtim.tv_nsec      = 0;
+                pStat->st_ctim.tv_sec       = 0;
+                pStat->st_ctim.tv_nsec      = 0;
+                pStat->st_birthtim.tv_sec   = 0;
+                pStat->st_birthtim.tv_nsec  = 0;
+                pStat->st_ino               = 0;
+                pStat->st_dev               = 0;
+                pStat->st_rdev              = 0;
+                pStat->st_uid               = 0;
+                pStat->st_gid               = 0;
+                pStat->st_padding1[0]       = 0;
+                pStat->st_padding1[1]       = 0;
+                pStat->st_padding1[2]       = 0;
+                pStat->st_blksize           = 512;
+                pStat->st_blocks            = 0;
+                if (fFileType == FILE_TYPE_PIPE)
+                {
+                    DWORD cbAvail;
+                    if (PeekNamedPipe(hFile, NULL, 0, NULL, &cbAvail, NULL))
+                        pStat->st_size = cbAvail;
+                }
+                rc = 0;
+                break;
+
+            case FILE_TYPE_UNKNOWN:
+            default:
+                if (GetLastError() == NO_ERROR)
+                    rc = birdSetErrnoToBadFileNo();
+                else
+                    rc = birdSetErrnoFromWin32(GetLastError());
+                break;
+        }
+    }
+    else
+        rc = -1;
+    return rc;
+}
+
+
+/**
+ * Implements UNIX stat().
+ */
+int birdStatFollowLink(const char *pszPath, BirdStat_T *pStat)
+{
+    return birdStatInternal(pszPath, pStat, 1 /*fFollow*/);
+}
+
+
+/**
+ * Implements UNIX lstat().
+ */
+int birdStatOnLink(const char *pszPath, BirdStat_T *pStat)
+{
+    return birdStatInternal(pszPath, pStat, 0 /*fFollow*/);
+}
+
+
+/**
+ * Internal worker for birdStatModTimeOnly.
+ */
+static int birdStatOnlyInternal(const char *pszPath, int fFollowLink, MY_FILE_BASIC_INFORMATION *pBasicInfo)
+{
+    int rc;
+    HANDLE hFile = birdOpenFile(pszPath,
+                                FILE_READ_ATTRIBUTES,
+                                FILE_ATTRIBUTE_NORMAL,
+                                FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                                FILE_OPEN,
+                                FILE_OPEN_FOR_BACKUP_INTENT | (fFollowLink ? 0 : FILE_OPEN_REPARSE_POINT),
+                                OBJ_CASE_INSENSITIVE);
+    if (hFile != INVALID_HANDLE_VALUE)
+    {
+        MY_NTSTATUS         rcNt = 0;
+        MY_IO_STATUS_BLOCK  Ios;
+        Ios.Information = 0;
+        Ios.u.Status    = -1;
+
+        if (pBasicInfo)
+        {
+            rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, pBasicInfo, sizeof(*pBasicInfo), MyFileBasicInformation);
+            if (MY_NT_SUCCESS(rcNt))
+                rcNt = Ios.u.Status;
+        }
+        birdCloseFile(hFile);
+
+        if (!MY_NT_SUCCESS(rcNt))
+            birdSetErrnoFromNt(rcNt);
+    }
+    else
+    {
+        //fprintf(stderr, "stat: %s -> %u\n", pszPath, GetLastError());
+
+        /* On things like pagefile.sys we may get sharing violation. */
+        if (GetLastError() == ERROR_SHARING_VIOLATION)
+        {
+            /** @todo Fall back on the parent directory enum if we run into a sharing
+             *        violation. */
+        }
+        rc = -1;
+    }
+    return rc;
+}
+
+
+/**
+ * Special function for getting the modification time.
+ */
+int birdStatModTimeOnly(const char *pszPath, BirdTimeSpec_T *pTimeSpec, int fFollowLink)
+{
+    MY_FILE_BASIC_INFORMATION BasicInfo;
+    int rc = birdStatOnlyInternal(pszPath, fFollowLink, &BasicInfo);
+    if (!rc)
+        birdNtTimeToTimeSpec(BasicInfo.LastWriteTime.QuadPart, pTimeSpec);
+    return rc;
+}
+
+
+
diff --git a/src/lib/nt/ntstat.h b/src/lib/nt/ntstat.h
new file mode 100644
index 0000000..fa5dd24
--- /dev/null
+++ b/src/lib/nt/ntstat.h
@@ -0,0 +1,130 @@
+/* $Id: ntstat.h 2708 2013-11-21 10:26:40Z bird $ */
+/** @file
+ * MSC + NT stat, lstat and fstat implementation and wrappers.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+#ifndef ___nt_ntstat_h
+#define ___nt_ntstat_h
+
+#include "nttypes.h"
+
+#include <sys/stat.h>
+#include <io.h>
+#include <direct.h>
+
+#undef stat
+#undef lstat
+#undef fstat
+
+
+/** The distance between the NT and unix epochs given in NT time (units of 100
+ *  ns). */
+#define BIRD_NT_EPOCH_OFFSET_UNIX_100NS 116444736000000000LL
+
+typedef struct BirdStat
+{
+    unsigned __int16    st_mode;
+    unsigned __int16    st_dirsymlink;
+    unsigned __int16    st_padding0[2];
+    __int64             st_size;
+    BirdTimeSpec_T      st_atim;
+    BirdTimeSpec_T      st_mtim;
+    BirdTimeSpec_T      st_ctim;
+    BirdTimeSpec_T      st_birthtim;
+    unsigned __int64    st_ino;
+    unsigned __int64    st_dev;
+    unsigned __int32    st_nlink;
+    unsigned __int16    st_rdev;
+    __int16             st_uid;
+    __int16             st_gid;
+    unsigned __int16    st_padding1[3];
+    unsigned __int32    st_blksize;
+    __int64             st_blocks;
+} BirdStat_T;
+
+#define BIRD_STAT_BLOCK_SIZE    512
+
+#define st_atime        st_atim.tv_sec
+#define st_ctime        st_ctim.tv_sec
+#define st_mtime        st_mtim.tv_sec
+#define st_birthtime    st_birthtim.tv_sec
+
+int birdStatFollowLink(const char *pszPath, BirdStat_T *pStat);
+int birdStatOnLink(const char *pszPath, BirdStat_T *pStat);
+int birdStatOnFd(int fd, BirdStat_T *pStat);
+int birdStatModTimeOnly(const char *pszPath, BirdTimeSpec_T *pTimeSpec, int fFollowLink);
+#ifdef ___nt_ntstuff_h
+void birdStatFillFromFileIdFullDirInfo(BirdStat_T *pStat, MY_FILE_ID_FULL_DIR_INFORMATION const *pBuf, const char *pszPath);
+#endif
+
+#define STAT_REDEFINED_ALREADY
+
+#define stat                            BirdStat
+#define BirdStat(a_pszPath, a_pStat)    birdStatFollowLink(a_pszPath, a_pStat)
+#define lstat(a_pszPath, a_pStat)       birdStatOnLink(a_pszPath, a_pStat)
+#define fstat(a_fd, a_pStat)            birdStatOnFd(a_fd, a_pStat)
+
+
+#ifndef _S_IFLNK
+# define _S_IFLNK       0xa000
+#endif
+#ifndef S_IFLNK
+# define S_IFLNK        _S_IFLNK
+#endif
+#ifndef S_IFIFO
+# define S_IFIFO        _S_IFIFO
+#endif
+
+#ifndef S_ISLNK
+# define S_ISLNK(m)     (((m) & _S_IFMT) == _S_IFLNK)
+#endif
+#ifndef S_ISDIR
+# define S_ISDIR(m)     (((m) & _S_IFMT) == _S_IFDIR)
+#endif
+#ifndef S_ISREG
+# define S_ISREG(m)     (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
+#define	S_IRWXU         (_S_IREAD | _S_IWRITE | _S_IEXEC)
+#define	S_IXUSR         _S_IEXEC
+#define	S_IWUSR         _S_IWRITE
+#define	S_IRUSR         _S_IREAD
+#define S_IRWXG         0000070
+#define S_IRGRP	        0000040
+#define S_IWGRP	        0000020
+#define S_IXGRP         0000010
+#define S_IRWXO         0000007
+#define S_IROTH	        0000004
+#define S_IWOTH	        0000002
+#define S_IXOTH         0000001
+#define	S_ISUID         0004000
+#define	S_ISGID         0002000
+#define ALLPERMS        0000777
+
+#endif
+
diff --git a/src/lib/nt/ntstuff.h b/src/lib/nt/ntstuff.h
new file mode 100644
index 0000000..3341e10
--- /dev/null
+++ b/src/lib/nt/ntstuff.h
@@ -0,0 +1,385 @@
+/* $Id: ntstuff.h 2713 2013-11-21 21:11:00Z bird $ */
+/** @file
+ * Definitions, types, prototypes and globals for NT.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+
+#ifndef ___nt_ntstuff_h
+#define ___nt_ntstuff_h
+
+#define timeval timeval_Windows
+#define WIN32_NO_STATUS
+#include <Windows.h>
+#undef WIN32_NO_STATUS
+#include <ntstatus.h>
+#undef timeval
+
+
+/** @defgroup grp_nt_ntstuff NT Stuff
+ * @{ */
+
+typedef LONG MY_NTSTATUS;
+typedef ULONG MY_ACCESS_MASK;
+
+typedef struct MY_IO_STATUS_BLOCK
+{
+    union
+    {
+        MY_NTSTATUS     Status;
+        PVOID           Pointer;
+    } u;
+    ULONG_PTR           Information;
+} MY_IO_STATUS_BLOCK;
+
+typedef VOID WINAPI MY_IO_APC_ROUTINE(PVOID, MY_IO_STATUS_BLOCK *, ULONG);
+
+typedef struct MY_UNICODE_STRING
+{
+    USHORT              Length;
+    USHORT              MaximumLength;
+    PWSTR               Buffer;
+} MY_UNICODE_STRING;
+
+typedef struct MY_STRING
+{
+    USHORT              Length;
+    USHORT              MaximumLength;
+    PCHAR               Buffer;
+} MY_STRING;
+typedef MY_STRING MY_ANSI_STRING;
+
+typedef struct MY_OBJECT_ATTRIBUTES
+{
+    ULONG               Length;
+    HANDLE              RootDirectory;
+    MY_UNICODE_STRING  *ObjectName;
+    ULONG               Attributes;
+    PVOID               SecurityDescriptor;
+    PVOID               SecurityQualityOfService;
+} MY_OBJECT_ATTRIBUTES;
+
+#define MyInitializeObjectAttributes(a_pAttr, a_pName, a_fAttribs, a_hRoot, a_pSecDesc) \
+    do { \
+        (a_pAttr)->Length                   = sizeof(MY_OBJECT_ATTRIBUTES); \
+        (a_pAttr)->RootDirectory            = (a_hRoot); \
+        (a_pAttr)->Attributes               = (a_fAttribs); \
+        (a_pAttr)->ObjectName               = (a_pName); \
+        (a_pAttr)->SecurityDescriptor       = (a_pSecDesc); \
+        (a_pAttr)->SecurityQualityOfService = NULL; \
+    } while (0)
+
+
+
+typedef struct MY_FILE_BASIC_INFORMATION
+{
+    LARGE_INTEGER   CreationTime;
+    LARGE_INTEGER   LastAccessTime;
+    LARGE_INTEGER   LastWriteTime;
+    LARGE_INTEGER   ChangeTime;
+    ULONG           FileAttributes;
+} MY_FILE_BASIC_INFORMATION;
+
+typedef struct MY_FILE_STANDARD_INFORMATION
+{
+    LARGE_INTEGER   AllocationSize;
+    LARGE_INTEGER   EndOfFile;
+    ULONG           NumberOfLinks;
+    BOOLEAN         DeletePending;
+    BOOLEAN         Directory;
+} MY_FILE_STANDARD_INFORMATION;
+
+typedef struct MY_FILE_INTERNAL_INFORMATION
+{
+    LARGE_INTEGER   IndexNumber;
+} MY_FILE_INTERNAL_INFORMATION;
+
+typedef struct MY_FILE_EA_INFORMATION
+{
+    ULONG           EaSize;
+} MY_FILE_EA_INFORMATION;
+
+typedef struct MY_FILE_ACCESS_INFORMATION
+{
+    ACCESS_MASK     AccessFlags;
+} MY_FILE_ACCESS_INFORMATION;
+
+typedef struct MY_FILE_POSITION_INFORMATION
+{
+    LARGE_INTEGER   CurrentByteOffset;
+} MY_FILE_POSITION_INFORMATION;
+
+typedef struct MY_FILE_MODE_INFORMATION
+{
+    ULONG           Mode;
+} MY_FILE_MODE_INFORMATION;
+
+typedef struct MY_FILE_ALIGNMENT_INFORMATION
+{
+    ULONG           AlignmentRequirement;
+} MY_FILE_ALIGNMENT_INFORMATION;
+
+typedef struct MY_FILE_NAME_INFORMATION
+{
+    ULONG           FileNameLength;
+    WCHAR           FileName[1];
+} MY_FILE_NAME_INFORMATION;
+
+typedef struct MY_FILE_ALL_INFORMATION
+{
+    MY_FILE_BASIC_INFORMATION       BasicInformation;
+    MY_FILE_STANDARD_INFORMATION    StandardInformation;
+    MY_FILE_INTERNAL_INFORMATION    InternalInformation;
+    MY_FILE_EA_INFORMATION          EaInformation;
+    MY_FILE_ACCESS_INFORMATION      AccessInformation;
+    MY_FILE_POSITION_INFORMATION    PositionInformation;
+    MY_FILE_MODE_INFORMATION        ModeInformation;
+    MY_FILE_ALIGNMENT_INFORMATION   AlignmentInformation;
+    MY_FILE_NAME_INFORMATION        NameInformation;
+} MY_FILE_ALL_INFORMATION;
+
+typedef struct MY_FILE_ATTRIBUTE_TAG_INFORMATION
+{
+    ULONG           FileAttributes;
+    ULONG           ReparseTag;
+} MY_FILE_ATTRIBUTE_TAG_INFORMATION;
+
+
+typedef struct MY_FILE_NAMES_INFORMATION
+{
+    ULONG           NextEntryOffset;
+    ULONG           FileIndex;
+    ULONG           FileNameLength;
+    WCHAR           FileName[1];
+} MY_FILE_NAMES_INFORMATION;
+/** The sizeof(MY_FILE_NAMES_INFORMATION) without the FileName. */
+#define MIN_SIZEOF_MY_FILE_NAMES_INFORMATION  (4 + 4 + 4)
+
+
+typedef struct MY_FILE_ID_FULL_DIR_INFORMATION
+{
+    ULONG           NextEntryOffset;
+    ULONG           FileIndex;
+    LARGE_INTEGER   CreationTime;
+    LARGE_INTEGER   LastAccessTime;
+    LARGE_INTEGER   LastWriteTime;
+    LARGE_INTEGER   ChangeTime;
+    LARGE_INTEGER   EndOfFile;
+    LARGE_INTEGER   AllocationSize;
+    ULONG           FileAttributes;
+    ULONG           FileNameLength;
+    ULONG           EaSize;
+    LARGE_INTEGER   FileId;
+    WCHAR           FileName[1];
+} MY_FILE_ID_FULL_DIR_INFORMATION;
+/** The sizeof(MY_FILE_NAMES_INFORMATION) without the FileName. */
+#define MIN_SIZEOF_MY_FILE_ID_FULL_DIR_INFORMATION  ( (size_t)&((MY_FILE_ID_FULL_DIR_INFORMATION *)0)->FileName )
+
+
+typedef struct MY_FILE_DISPOSITION_INFORMATION
+{
+    BOOLEAN         DeleteFile;
+} MY_FILE_DISPOSITION_INFORMATION;
+
+
+typedef enum MY_FILE_INFORMATION_CLASS
+{
+    MyFileDirectoryInformation                     = 1,
+    MyFileFullDirectoryInformation,             /* = 2  */
+    MyFileBothDirectoryInformation,             /* = 3  */
+    MyFileBasicInformation,                     /* = 4  */
+    MyFileStandardInformation,                  /* = 5  */
+    MyFileInternalInformation,                  /* = 6  */
+    MyFileEaInformation,                        /* = 7  */
+    MyFileAccessInformation,                    /* = 8  */
+    MyFileNameInformation,                      /* = 9  */
+    MyFileRenameInformation,                    /* = 10 */
+    MyFileLinkInformation,                      /* = 11 */
+    MyFileNamesInformation,                     /* = 12 */
+    MyFileDispositionInformation,               /* = 13 */
+    MyFilePositionInformation,                  /* = 14 */
+    MyFileFullEaInformation,                    /* = 15 */
+    MyFileModeInformation,                      /* = 16 */
+    MyFileAlignmentInformation,                 /* = 17 */
+    MyFileAllInformation,                       /* = 18 */
+    MyFileAllocationInformation,                /* = 19 */
+    MyFileEndOfFileInformation,                 /* = 20 */
+    MyFileAlternateNameInformation,             /* = 21 */
+    MyFileStreamInformation,                    /* = 22 */
+    MyFilePipeInformation,                      /* = 23 */
+    MyFilePipeLocalInformation,                 /* = 24 */
+    MyFilePipeRemoteInformation,                /* = 25 */
+    MyFileMailslotQueryInformation,             /* = 26 */
+    MyFileMailslotSetInformation,               /* = 27 */
+    MyFileCompressionInformation,               /* = 28 */
+    MyFileObjectIdInformation,                  /* = 29 */
+    MyFileCompletionInformation,                /* = 30 */
+    MyFileMoveClusterInformation,               /* = 31 */
+    MyFileQuotaInformation,                     /* = 32 */
+    MyFileReparsePointInformation,              /* = 33 */
+    MyFileNetworkOpenInformation,               /* = 34 */
+    MyFileAttributeTagInformation,              /* = 35 */
+    MyFileTrackingInformation,                  /* = 36 */
+    MyFileIdBothDirectoryInformation,           /* = 37 */
+    MyFileIdFullDirectoryInformation,           /* = 38 */
+    MyFileValidDataLengthInformation,           /* = 39 */
+    MyFileShortNameInformation,                 /* = 40 */
+    MyFileIoCompletionNotificationInformation,  /* = 41 */
+    MyFileIoStatusBlockRangeInformation,        /* = 42 */
+    MyFileIoPriorityHintInformation,            /* = 43 */
+    MyFileSfioReserveInformation,               /* = 44 */
+    MyFileSfioVolumeInformation,                /* = 45 */
+    MyFileHardLinkInformation,                  /* = 46 */
+    MyFileProcessIdsUsingFileInformation,       /* = 47 */
+    MyFileNormalizedNameInformation,            /* = 48 */
+    MyFileNetworkPhysicalNameInformation,       /* = 49 */
+    MyFileIdGlobalTxDirectoryInformation,       /* = 50 */
+    MyFileIsRemoteDeviceInformation,            /* = 51 */
+    MyFileAttributeCacheInformation,            /* = 52 */
+    MyFileNumaNodeInformation,                  /* = 53 */
+    MyFileStandardLinkInformation,              /* = 54 */
+    MyFileRemoteProtocolInformation,            /* = 55 */
+    MyFileMaximumInformation
+} MY_FILE_INFORMATION_CLASS;
+
+
+typedef struct MY_FILE_FS_VOLUME_INFORMATION
+{
+    LARGE_INTEGER   VolumeCreationTime;
+    ULONG           VolumeSerialNumber;
+    ULONG           VolumeLabelLength;
+    BOOLEAN         SupportsObjects;
+    WCHAR           VolumeLabel[1];
+} MY_FILE_FS_VOLUME_INFORMATION;
+
+typedef enum MY_FSINFOCLASS
+{
+    MyFileFsVolumeInformation                      = 1,
+    MyFileFsLabelInformation,                   /* = 2  */
+    MyFileFsSizeInformation,                    /* = 3  */
+    MyFileFsDeviceInformation,                  /* = 4  */
+    MyFileFsAttributeInformation,               /* = 5  */
+    MyFileFsControlInformation,                 /* = 6  */
+    MyFileFsFullSizeInformation,                /* = 7  */
+    MyFileFsObjectIdInformation,                /* = 8  */
+    MyFileFsDriverPathInformation,              /* = 9  */
+    MyFileFsVolumeFlagsInformation,             /* = 10 */
+    MyFileFsMaximumInformation
+} MY_FS_INFORMATION_CLASS;
+
+
+typedef struct MY_RTLP_CURDIR_REF
+{
+    LONG            RefCount;
+    HANDLE          Handle;
+} MY_RTLP_CURDIR_REF;
+
+typedef struct MY_RTL_RELATIVE_NAME_U
+{
+    MY_UNICODE_STRING   RelativeName;
+    HANDLE              ContainingDirectory;
+    MY_RTLP_CURDIR_REF  CurDirRef;
+} MY_RTL_RELATIVE_NAME_U;
+
+
+#ifndef OBJ_INHERIT
+# define OBJ_INHERIT                        0x00000002U
+# define OBJ_PERMANENT                      0x00000010U
+# define OBJ_EXCLUSIVE                      0x00000020U
+# define OBJ_CASE_INSENSITIVE               0x00000040U
+# define OBJ_OPENIF                         0x00000080U
+# define OBJ_OPENLINK                       0x00000100U
+# define OBJ_KERNEL_HANDLE                  0x00000200U
+# define OBJ_FORCE_ACCESS_CHECK             0x00000400U
+# define OBJ_VALID_ATTRIBUTES               0x000007f2U
+#endif
+
+#ifndef FILE_OPEN
+# define FILE_SUPERSEDE                     0x00000000U
+# define FILE_OPEN                          0x00000001U
+# define FILE_CREATE                        0x00000002U
+# define FILE_OPEN_IF                       0x00000003U
+# define FILE_OVERWRITE                     0x00000004U
+# define FILE_OVERWRITE_IF                  0x00000005U
+# define FILE_MAXIMUM_DISPOSITION           0x00000005U
+#endif
+
+#ifndef FILE_DIRECTORY_FILE
+# define FILE_DIRECTORY_FILE                0x00000001U
+# define FILE_WRITE_THROUGH                 0x00000002U
+# define FILE_SEQUENTIAL_ONLY               0x00000004U
+# define FILE_NO_INTERMEDIATE_BUFFERING     0x00000008U
+# define FILE_SYNCHRONOUS_IO_ALERT          0x00000010U
+# define FILE_SYNCHRONOUS_IO_NONALERT       0x00000020U
+# define FILE_NON_DIRECTORY_FILE            0x00000040U
+# define FILE_CREATE_TREE_CONNECTION        0x00000080U
+# define FILE_COMPLETE_IF_OPLOCKED          0x00000100U
+# define FILE_NO_EA_KNOWLEDGE               0x00000200U
+# define FILE_OPEN_REMOTE_INSTANCE          0x00000400U
+# define FILE_RANDOM_ACCESS                 0x00000800U
+# define FILE_DELETE_ON_CLOSE               0x00001000U
+# define FILE_OPEN_BY_FILE_ID               0x00002000U
+# define FILE_OPEN_FOR_BACKUP_INTENT        0x00004000U
+# define FILE_NO_COMPRESSION                0x00008000U
+# define FILE_RESERVE_OPFILTER              0x00100000U
+# define FILE_OPEN_REPARSE_POINT            0x00200000U
+# define FILE_OPEN_NO_RECALL                0x00400000U
+# define FILE_OPEN_FOR_FREE_SPACE_QUERY     0x00800000U
+#endif
+
+
+/** @name NT status codes and associated macros.
+ * @{ */
+#define MY_NT_SUCCESS(a_ntRc)               ((MY_NTSTATUS)(a_ntRc) >= 0)
+#define MY_NT_FAILURE(a_ntRc)               ((MY_NTSTATUS)(a_ntRc) <  0)
+#define MY_STATUS_NO_MORE_FILES             ((MY_NTSTATUS)0x80000006)
+/** @}  */
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+extern MY_NTSTATUS (WINAPI * g_pfnNtClose)(HANDLE);
+extern MY_NTSTATUS (WINAPI * g_pfnNtCreateFile)(PHANDLE, MY_ACCESS_MASK, MY_OBJECT_ATTRIBUTES *, MY_IO_STATUS_BLOCK *,
+                                                PLARGE_INTEGER, ULONG, ULONG, ULONG, ULONG, PVOID, ULONG);
+extern MY_NTSTATUS (WINAPI * g_pfnNtDeleteFile)(MY_OBJECT_ATTRIBUTES *);
+extern MY_NTSTATUS (WINAPI * g_pfnNtQueryInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *,
+                                                          PVOID, LONG, MY_FILE_INFORMATION_CLASS);
+extern MY_NTSTATUS (WINAPI * g_pfnNtQueryVolumeInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *,
+                                                                PVOID, LONG, MY_FS_INFORMATION_CLASS);
+extern MY_NTSTATUS (WINAPI * g_pfnNtQueryDirectoryFile)(HANDLE, HANDLE, MY_IO_APC_ROUTINE *, PVOID, MY_IO_STATUS_BLOCK *,
+                                                        PVOID, ULONG, MY_FILE_INFORMATION_CLASS, BOOLEAN,
+                                                        MY_UNICODE_STRING *, BOOLEAN);
+extern MY_NTSTATUS (WINAPI * g_pfnNtSetInformationFile)(HANDLE, MY_IO_STATUS_BLOCK *, PVOID, LONG, MY_FILE_INFORMATION_CLASS);
+extern BOOLEAN     (WINAPI * g_pfnRtlDosPathNameToNtPathName_U)(PCWSTR, MY_UNICODE_STRING *, PCWSTR *, MY_RTL_RELATIVE_NAME_U *);
+extern MY_NTSTATUS (WINAPI * g_pfnRtlAnsiStringToUnicodeString)(MY_UNICODE_STRING *, MY_ANSI_STRING const *, BOOLEAN);
+
+
+/** @} */
+
+#endif
+
diff --git a/src/lib/nt/nttypes.h b/src/lib/nt/nttypes.h
new file mode 100644
index 0000000..8e714c4
--- /dev/null
+++ b/src/lib/nt/nttypes.h
@@ -0,0 +1,49 @@
+/* $Id: nttypes.h 2702 2013-11-21 00:11:08Z bird $ */
+/** @file
+ * MSC + NT basic & common types, various definitions.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+#ifndef ___nt_nttypes_h
+#define ___nt_nttypes_h
+
+#include <sys/types.h>
+
+typedef struct BirdTimeSpec
+{
+    __int64       tv_sec;
+    __int32       tv_nsec;
+    __int32       tv_padding0;
+} BirdTimeSpec_T;
+
+/** The distance between the NT and unix epochs given in NT time (units of 100
+ *  ns). */
+#define BIRD_NT_EPOCH_OFFSET_UNIX_100NS 116444736000000000LL
+
+#endif
+
+
diff --git a/src/lib/nt/ntunlink.c b/src/lib/nt/ntunlink.c
new file mode 100644
index 0000000..b417767
--- /dev/null
+++ b/src/lib/nt/ntunlink.c
@@ -0,0 +1,171 @@
+/* $Id: ntunlink.c 2713 2013-11-21 21:11:00Z bird $ */
+/** @file
+ * MSC + NT unlink and variations.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <stdio.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include "ntstuff.h"
+#include "nthlp.h"
+
+
+static MY_NTSTATUS birdMakeWritable(MY_UNICODE_STRING *pNtPath)
+{
+    MY_NTSTATUS rcNt;
+    HANDLE      hFile;
+
+    rcNt = birdOpenFileUniStr(pNtPath,
+                              FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                              FILE_ATTRIBUTE_NORMAL,
+                              FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+                              FILE_OPEN,
+                              FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
+                              OBJ_CASE_INSENSITIVE,
+                              &hFile);
+    if (MY_NT_SUCCESS(rcNt))
+    {
+        MY_FILE_BASIC_INFORMATION   BasicInfo;
+        MY_IO_STATUS_BLOCK          Ios;
+        DWORD                       dwAttr;
+
+        Ios.Information = -1;
+        Ios.u.Status    = -1;
+        rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, &BasicInfo, sizeof(BasicInfo), MyFileBasicInformation);
+
+        if (MY_NT_SUCCESS(rcNt) && MY_NT_SUCCESS(Ios.u.Status))
+            dwAttr = BasicInfo.FileAttributes & ~FILE_ATTRIBUTE_READONLY;
+        else
+            dwAttr = FILE_ATTRIBUTE_NORMAL;
+        memset(&BasicInfo, 0, sizeof(BasicInfo));
+        BasicInfo.FileAttributes = dwAttr;
+
+        Ios.Information = -1;
+        Ios.u.Status    = -1;
+        rcNt = g_pfnNtSetInformationFile(hFile, &Ios, &BasicInfo, sizeof(BasicInfo), MyFileBasicInformation);
+
+        birdCloseFile(hFile);
+    }
+
+    return rcNt;
+}
+
+
+static int birdUnlinkInternal(const char *pszFile, int fReadOnlyToo, int fFast)
+{
+    MY_UNICODE_STRING   NtPath;
+    int                 rc;
+
+    rc = birdDosToNtPath(pszFile, &NtPath);
+    if (rc == 0)
+    {
+        MY_NTSTATUS rcNt;
+        if (fFast)
+        {
+            /* This uses FILE_DELETE_ON_CLOSE. Probably only suitable when in a hurry... */
+            MY_OBJECT_ATTRIBUTES ObjAttr;
+            MyInitializeObjectAttributes(&ObjAttr, &NtPath, OBJ_CASE_INSENSITIVE, NULL /*hRoot*/, NULL /*pSecAttr*/);
+            rcNt = g_pfnNtDeleteFile(&ObjAttr);
+
+            /* In case some file system does things differently than NTFS. */
+            if (rcNt == STATUS_CANNOT_DELETE)
+            {
+                birdMakeWritable(&NtPath);
+                rcNt = g_pfnNtDeleteFile(&ObjAttr);
+            }
+        }
+        else
+        {
+            /* Use the set information stuff. Probably more reliable. */
+            HANDLE hFile;
+            int    fMayTryAgain = 1;
+            for (;;)
+            {
+                rcNt = birdOpenFileUniStr(&NtPath,
+                                          DELETE,
+                                          FILE_ATTRIBUTE_NORMAL,
+                                          FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                          FILE_OPEN,
+                                          FILE_OPEN_FOR_BACKUP_INTENT | FILE_OPEN_REPARSE_POINT,
+                                          OBJ_CASE_INSENSITIVE,
+                                          &hFile);
+                if (MY_NT_SUCCESS(rcNt))
+                {
+                    MY_FILE_DISPOSITION_INFORMATION DispInfo;
+                    MY_IO_STATUS_BLOCK              Ios;
+
+                    DispInfo.DeleteFile = TRUE;
+
+                    Ios.Information = -1;
+                    Ios.u.Status    = -1;
+
+                    rcNt = g_pfnNtSetInformationFile(hFile, &Ios, &DispInfo, sizeof(DispInfo), MyFileDispositionInformation);
+
+                    birdCloseFile(hFile);
+                }
+                if (rcNt != STATUS_CANNOT_DELETE || !fMayTryAgain)
+                    break;
+
+                fMayTryAgain = 0;
+                birdMakeWritable(&NtPath);
+            }
+        }
+
+        birdFreeNtPath(&NtPath);
+
+        if (MY_NT_SUCCESS(rcNt))
+            rc = 0;
+        else
+            rc = birdSetErrnoFromNt(rcNt);
+    }
+    return rc;
+}
+
+
+int birdUnlink(const char *pszFile)
+{
+    return birdUnlinkInternal(pszFile, 0 /*fReadOnlyToo*/, 0 /*fFast*/);
+}
+
+
+int birdUnlinkForced(const char *pszFile)
+{
+    return birdUnlinkInternal(pszFile, 1 /*fReadOnlyToo*/, 0 /*fFast*/);
+}
+
+
+int birdUnlinkForcedFast(const char *pszFile)
+{
+    return birdUnlinkInternal(pszFile, 1 /*fReadOnlyToo*/, 1 /*fFast*/);
+}
+
diff --git a/src/lib/nt/ntunlink.h b/src/lib/nt/ntunlink.h
new file mode 100644
index 0000000..ec7d82a
--- /dev/null
+++ b/src/lib/nt/ntunlink.h
@@ -0,0 +1,44 @@
+/* $Id: ntunlink.h 2713 2013-11-21 21:11:00Z bird $ */
+/** @file
+ * MSC + NT unlink and variations.
+ */
+
+/*
+ * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+#ifndef ___nt_ntunlink_h
+#define ___nt_ntunlink_h
+
+#include "nttypes.h"
+
+int birdUnlink(const char *pszFile);
+int birdUnlinkForced(const char *pszFile);
+int birdUnlinkForcedFast(const char *pszFile);
+
+#undef  unlink
+#define unlink(a_pszPath)     birdUnlinkForced(a_pszPath)
+
+#endif
+
diff --git a/src/lib/nt/tstNtStat.c b/src/lib/nt/tstNtStat.c
new file mode 100644
index 0000000..2a830f1
--- /dev/null
+++ b/src/lib/nt/tstNtStat.c
@@ -0,0 +1,156 @@
+/* $Id: tstNtStat.c 2702 2013-11-21 00:11:08Z bird $ */
+/** @file
+ * Manual lstat/stat testcase.
+ */
+
+/*
+ * Copyright (c) 2013 knut st. osmundsen <bird-kBuild-spamx at anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Alternatively, the content of this file may be used under the terms of the
+ * GPL version 2 or later, or LGPL version 2.1 or later.
+ */
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <stdio.h>
+#include <errno.h>
+#include "ntstat.h"
+
+
+static int IsLeapYear(int iYear)
+{
+    return iYear % 4 == 0
+        && (   iYear % 100 != 0
+            || iYear % 400 == 0);
+}
+
+static int DaysInMonth(int iYear, int iMonth)
+{
+    switch (iMonth)
+    {
+        case 1:
+        case 3:
+        case 5:
+        case 7:
+        case 8:
+        case 10:
+        case 12:
+            return 31;
+        case 4:
+        case 6:
+        case 9:
+        case 11:
+            return 30;
+        case 2:
+            return IsLeapYear(iYear) ? 29 : 28;
+
+        default:
+            *(void **)(size_t)iMonth = 0; /* crash! */
+            return 0;
+    }
+}
+
+
+static char *FormatTimeSpec(char *pszBuf, BirdTimeSpec_T const *pTimeSpec)
+{
+    if (pTimeSpec->tv_sec >= 0)
+    {
+        int     iYear  = 1970;
+        int     iMonth = 1;
+        int     iDay   = 1;
+        int     iHour  = 0;
+        int     iMin   = 0;
+        int     iSec   = 0;
+        __int64 cSecs  = pTimeSpec->tv_sec;
+
+        /* lazy bird approach, find date, day by day */
+        while (cSecs >= 24*3600)
+        {
+            if (   iDay < 28
+                || iDay < DaysInMonth(iYear, iMonth))
+                iDay++;
+            else
+            {
+                if (iMonth < 12)
+                    iMonth++;
+                else
+                {
+                    iYear++;
+                    iMonth = 1;
+                }
+                iDay = 1;
+            }
+            cSecs -= 24*3600;
+        }
+
+        iHour  = (int)cSecs / 3600;
+        cSecs %= 3600;
+        iMin   = (int)cSecs / 60;
+        iSec   = (int)cSecs % 60;
+
+        sprintf(pszBuf, "%04d-%02d-%02dT%02u:%02u:%02u.%09u (%I64d.%09u)",
+                iYear, iMonth, iDay, iHour, iMin, iSec, pTimeSpec->tv_nsec,
+                pTimeSpec->tv_sec, pTimeSpec->tv_nsec);
+    }
+    else
+        sprintf(pszBuf, "%I64d.%09u (before 1970-01-01)", pTimeSpec->tv_sec, pTimeSpec->tv_nsec);
+    return pszBuf;
+}
+
+
+int main(int argc, char **argv)
+{
+    int rc = 0;
+    int i;
+
+    for (i = 1; i < argc; i++)
+    {
+        struct stat st;
+        if (lstat(argv[i], &st) == 0)
+        {
+            char szBuf[256];
+            printf("%s:\n", argv[i]);
+            printf("  st_mode:          %o\n", st.st_mode);
+            printf("  st_dirsymlink:    %d\n", st.st_dirsymlink);
+            printf("  st_size:          %I64u (%#I64x)\n", st.st_size, st.st_size);
+            printf("  st_atim:          %s\n", FormatTimeSpec(szBuf, &st.st_atim));
+            printf("  st_mtim:          %s\n", FormatTimeSpec(szBuf, &st.st_mtim));
+            printf("  st_ctim:          %s\n", FormatTimeSpec(szBuf, &st.st_ctim));
+            printf("  st_birthtim:      %s\n", FormatTimeSpec(szBuf, &st.st_birthtim));
+            printf("  st_ino:           %#I64x\n", st.st_ino);
+            printf("  st_dev:           %#I64x\n", st.st_dev);
+            printf("  st_nlink:         %u\n", st.st_nlink);
+            printf("  st_rdev:          %#x\n", st.st_rdev);
+            printf("  st_uid:           %d\n", st.st_uid);
+            printf("  st_gid:           %d\n", st.st_gid);
+            printf("  st_blksize:       %d (%#x)\n", st.st_blksize, st.st_blksize);
+            printf("  st_blocks:        %I64u (%#I64x)\n", st.st_blocks, st.st_blocks);
+        }
+        else
+        {
+            fprintf(stderr, "stat failed on '%s': errno=%u\n", argv[i], errno);
+            rc = 1;
+        }
+    }
+    return rc;
+}
+
diff --git a/src/sed/lib/getline.c b/src/sed/lib/getline.c
index defaeda..4cb9d45 100644
--- a/src/sed/lib/getline.c
+++ b/src/sed/lib/getline.c
@@ -5,7 +5,9 @@
 #undef _GNU_SOURCE
 
 #include <sys/types.h>
+#define getline stdio_getline   /* bird */
 #include <stdio.h>
+#undef getline 			/* bird */
 
 #ifdef HAVE_STRINGS_H
 # include <strings.h>
diff --git a/src/sed/lib/regex_internal.c b/src/sed/lib/regex_internal.c
index a0b3fa7..536bf39 100644
--- a/src/sed/lib/regex_internal.c
+++ b/src/sed/lib/regex_internal.c
@@ -781,7 +781,7 @@ re_string_peek_byte_case (const re_string_t *pstr, int idx)
 }
 
 static unsigned char
-internal_function __attribute ((pure))
+internal_function
 re_string_fetch_byte_case (re_string_t *pstr)
 {
   if (BE (!pstr->mbs_allocated, 1))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-virtualbox/kbuild.git



More information about the Pkg-virtualbox-commits mailing list