Index: /trunk/src/ash-messup/Makefile.kmk
===================================================================
--- /trunk/src/ash-messup/Makefile.kmk	(revision 881)
+++ /trunk/src/ash-messup/Makefile.kmk	(revision 882)
@@ -59,5 +59,9 @@
 	$(PATH_TARGET)/builtins.c \
 	$(PATH_TARGET)/init.c \
-	$(PATH_TARGET)/nodes.c
+	$(PATH_TARGET)/nodes.c \
+	\
+	shinstance.c \
+	shthread.c \
+	shfile.c
 kmk_ash_SOURCES.linux = \
 	sys_signame.c \
@@ -114,5 +118,6 @@
 #$(eval $(def_copy_generated)))
 
-kmk_ash_INCS += generated 
+kmk_ash_INCS += generated
+kmk_ash_DEFS += HAVE_SYS_CDEFS_H 
 
 include $(PATH_KBUILD)/footer.kmk
Index: /trunk/src/ash-messup/alias.c
===================================================================
--- /trunk/src/ash-messup/alias.c	(revision 881)
+++ /trunk/src/ash-messup/alias.c	(revision 882)
@@ -54,20 +54,21 @@
 #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 *);
+#include "shinstance.h"
+
+/*#define ATABSIZE 39
+
+struct alias *atab[ATABSIZE];*/
+
+STATIC void setalias(shinstance *, char *, char *);
+STATIC int unalias(shinstance *, char *);
+STATIC struct alias **hashalias(shinstance *, char *);
 
 STATIC
 void
-setalias(char *name, char *val)
+setalias(shinstance *psh, char *name, char *val)
 {
 	struct alias *ap, **app;
 
-	app = hashalias(name);
+	app = hashalias(psh, name);
 	for (ap = *app; ap; ap = ap->next) {
 		if (equal(name, ap->name)) {
@@ -117,9 +118,9 @@
 
 STATIC int
-unalias(char *name)
+unalias(shinstance *psh, char *name)
 {
 	struct alias *ap, **app;
 
-	app = hashalias(name);
+	app = hashalias(psh, name);
 
 	for (ap = *app; ap; app = &(ap->next), ap = ap->next) {
@@ -150,13 +151,13 @@
 
 #ifdef mkinit
-MKINIT void rmaliases(void);
+MKINIT void rmaliases(shinstance *psh);
 
 SHELLPROC {
-	rmaliases();
+	rmaliases(psh);
 }
 #endif
 
 void
-rmaliases(void)
+rmaliases(shinstance *psh)
 {
 	struct alias *ap, *tmp;
@@ -165,6 +166,6 @@
 	INTOFF;
 	for (i = 0; i < ATABSIZE; i++) {
-		ap = atab[i];
-		atab[i] = NULL;
+		ap = psh->atab[i];
+		psh->atab[i] = NULL;
 		while (ap) {
 			ckfree(ap->name);
@@ -179,7 +180,7 @@
 
 struct alias *
-lookupalias(char *name, int check)
-{
-	struct alias *ap = *hashalias(name);
+lookupalias(shinstance *psh, char *name, int check)
+{
+	struct alias *ap = *hashalias(psh, name);
 
 	for (; ap; ap = ap->next) {
@@ -195,9 +196,9 @@
 
 char *
-get_alias_text(char *name)
+get_alias_text(shinstance *psh, char *name)
 {
 	struct alias *ap;
 
-	ap = lookupalias(name, 0);
+	ap = lookupalias(psh, name, 0);
 	if (ap == NULL)
 		return NULL;
@@ -209,5 +210,5 @@
  */
 int
-aliascmd(int argc, char **argv)
+aliascmd(shinstance *psh, int argc, char **argv)
 {
 	char *n, *v;
@@ -219,9 +220,9 @@
 
 		for (i = 0; i < ATABSIZE; i++)
-			for (ap = atab[i]; ap; ap = ap->next) {
+			for (ap = psh->atab[i]; ap; ap = ap->next) {
 				if (*ap->name != '\0') {
-					out1fmt("alias %s=", ap->name);
-					print_quoted(ap->val);
-					out1c('\n');
+					out1fmt(psh, "alias %s=", ap->name);
+					print_quoted(psh, ap->val);
+					out1c(psh, '\n');
 				}
 			}
@@ -230,15 +231,15 @@
 	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);
+			if ((ap = lookupalias(psh, n, 0)) == NULL) {
+				outfmt(psh->out2, "alias: %s not found\n", n);
 				ret = 1;
 			} else {
-				out1fmt("alias %s=", n);
-				print_quoted(ap->val);
-				out1c('\n');
+				out1fmt(psh, "alias %s=", n);
+				print_quoted(psh, ap->val);
+				out1c(psh, '\n');
 			}
 		} else {
 			*v++ = '\0';
-			setalias(n, v);
+			setalias(psh, n, v);
 		}
 	}
@@ -248,16 +249,16 @@
 
 int
-unaliascmd(int argc, char **argv)
+unaliascmd(shinstance *psh, int argc, char **argv)
 {
 	int i;
 
-	while ((i = nextopt("a")) != '\0') {
+	while ((i = nextopt(psh, "a")) != '\0') {
 		if (i == 'a') {
-			rmaliases();
+			rmaliases(psh);
 			return (0);
 		}
 	}
-	for (i = 0; *argptr; argptr++)
-		i = unalias(*argptr);
+	for (i = 0; *psh->argptr; psh->argptr++)
+		i = unalias(psh, *psh->argptr);
 
 	return (i);
@@ -265,5 +266,5 @@
 
 STATIC struct alias **
-hashalias(char *p)
+hashalias(shinstance *psh, char *p)
 {
 	unsigned int hashval;
@@ -272,4 +273,4 @@
 	while (*p)
 		hashval+= *p++;
-	return &atab[hashval % ATABSIZE];
-}
+	return &psh->atab[hashval % ATABSIZE];
+}
Index: /trunk/src/ash-messup/main.c
===================================================================
--- /trunk/src/ash-messup/main.c	(revision 881)
+++ /trunk/src/ash-messup/main.c	(revision 882)
@@ -308,5 +308,5 @@
 
 	INTOFF;
-	if ((fd = shfile_open(psh, name, O_RDONLY)) >= 0)
+	if ((fd = shfile_open(&psh->fdtab, name, O_RDONLY)) >= 0)
 		setinputfd(psh, fd, 1);
 	INTON;
Index: /trunk/src/ash-messup/shfile.c
===================================================================
--- /trunk/src/ash-messup/shfile.c	(revision 882)
+++ /trunk/src/ash-messup/shfile.c	(revision 882)
@@ -0,0 +1,43 @@
+/* $Id: $ */
+/** @file
+ *
+ * File management. 
+ *
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "shfile.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int shfile_open(shfdtab *pfdtab, const char *name, unsigned flags)
+{
+    return open(name, flags);
+}
+
+
+int shfile_close(shfdtab *pfdtab, unsigned fd)
+{
+    return close(fd);
+}
+
Index: /trunk/src/ash-messup/shfile.h
===================================================================
--- /trunk/src/ash-messup/shfile.h	(revision 881)
+++ /trunk/src/ash-messup/shfile.h	(revision 882)
@@ -25,4 +25,6 @@
  */
 
+#ifndef ___shfile_h___
+#define ___shfile_h___
 
 #include "shtypes.h"
@@ -49,4 +51,7 @@
 
 
-int shfile_open(shinstance *, const char *, unsigned);
+int shfile_open(shfdtab *, const char *, unsigned);
+int shfile_close(shfdtab *pfdtab, unsigned fd);
 
+#endif
+
Index: /trunk/src/ash-messup/shinstance.h
===================================================================
--- /trunk/src/ash-messup/shinstance.h	(revision 881)
+++ /trunk/src/ash-messup/shinstance.h	(revision 882)
@@ -137,4 +137,8 @@
     /* builtins.h */
 
+    /* alias.c */
+#define ATABSIZE 39
+    struct alias       *atab[ATABSIZE];
+
 } shinstance;
 
Index: /trunk/src/ash-messup/shthread.c
===================================================================
--- /trunk/src/ash-messup/shthread.c	(revision 882)
+++ /trunk/src/ash-messup/shthread.c	(revision 882)
@@ -0,0 +1,48 @@
+/* $Id: $ */
+/** @file
+ *
+ * Shell Thread Management.
+ *
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "shthread.h"
+#include "shinstance.h"
+
+#if defined(_MSC_VER) || defined(__EMX__)
+# include <process.h>
+#else
+# include <pthread.h>
+#endif 
+
+
+void shthread_set_shell(struct shinstance *psh)
+{
+
+}
+
+struct shinstance *shthread_get_shell(void)
+{
+    shinstance *psh = NULL;
+    return psh;
+}
+
+
Index: /trunk/src/ash-messup/shthread.h
===================================================================
--- /trunk/src/ash-messup/shthread.h	(revision 881)
+++ /trunk/src/ash-messup/shthread.h	(revision 882)
@@ -25,4 +25,6 @@
  */
 
+#ifndef ___shthread_h___
+#define ___shthread_h___
 
 #include <sys/types.h>
@@ -37,2 +39,5 @@
 void shthread_set_shell(struct shinstance *);
 struct shinstance *shthread_get_shell(void);
+
+#endif
+
