Index: /trunk/src/kash/bltin/kill.c
===================================================================
--- /trunk/src/kash/bltin/kill.c	(revision 1212)
+++ /trunk/src/kash/bltin/kill.c	(revision 1213)
@@ -47,16 +47,11 @@
 
 #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>
+#include "jobs.h"
+#include "error.h"
+#include "shinstance.h"
 
 #ifndef HAVE_SYS_SIGNAME
@@ -65,28 +60,22 @@
 #endif
 
-#ifdef SHELL            /* sh (aka ash) builtin */
-#define main killcmd
-#include "bltin/bltin.h"
-#include "jobs.h"
-#endif /* SHELL */
-
-static void nosig(char *);
-static void printsignals(FILE *);
+static int nosig(shinstance *, char *);
+static void printsignals(shinstance *, struct output *);
 static int signame_to_signum(char *);
-static void usage(void);
-int main(int, char *[]);
+static int usage(shinstance *psh);
 
 int
-main(int argc, char *argv[])
+killcmd(shinstance *psh, int argc, char *argv[])
 {
 	int errors, numsig, pid;
 	char *ep;
 
-	setprogname(argv[0]);
-	setlocale(LC_ALL, "");
 	if (argc < 2)
-		usage();
+		return usage(psh);
 
 	numsig = SIGTERM;
+#ifndef HAVE_SYS_SIGNAME
+	init_sys_signame();
+#endif
 
 	argc--, argv++;
@@ -94,11 +83,11 @@
 		argc--, argv++;
 		if (argc > 1)
-			usage();
+			return usage(psh);
 		if (argc == 1) {
 			if (isdigit((unsigned char)**argv) == 0)
-				usage();
+				return usage(psh);
 			numsig = strtol(*argv, &ep, 10);
 			if (*ep != '\0') {
-				errx(EXIT_FAILURE, "illegal signal number: %s",
+				sh_errx(psh, EXIT_FAILURE, "illegal signal number: %s",
 						*argv);
 				/* NOTREACHED */
@@ -107,13 +96,12 @@
 				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);
+				return nosig(psh, *argv);
+			outfmt(psh->out1, "%s\n", sys_signame[numsig]);
+			//sh_exit(psh, 0);
+			return 0;
+		}
+		printsignals(psh, psh->out1);
+		//sh_exit(psh, 0);
+		return 0;
 	}
 
@@ -121,10 +109,10 @@
 		argc--, argv++;
 		if (argc < 1) {
-			warnx("option requires an argument -- s");
-			usage();
+			sh_warnx(psh, "option requires an argument -- s");
+			return usage(psh);
 		}
 		if (strcmp(*argv, "0")) {
 			if ((numsig = signame_to_signum(*argv)) < 0)
-				nosig(*argv);
+				return nosig(psh, *argv);
 		} else
 			numsig = 0;
@@ -134,55 +122,51 @@
 		if (isalpha((unsigned char)**argv)) {
 			if ((numsig = signame_to_signum(*argv)) < 0)
-				nosig(*argv);
+				return nosig(psh, *argv);
 		} else if (isdigit((unsigned char)**argv)) {
 			numsig = strtol(*argv, &ep, 10);
 			if (!*argv || *ep) {
-				errx(EXIT_FAILURE, "illegal signal number: %s",
+				sh_errx(psh, EXIT_FAILURE, "illegal signal number: %s",
 						*argv);
 				/* NOTREACHED */
 			}
 			if (numsig < 0 || numsig >= NSIG)
-				nosig(*argv);
+				return nosig(psh, *argv);
 		} else
-			nosig(*argv);
+			return nosig(psh, *argv);
 		argc--, argv++;
 	}
 
 	if (argc == 0)
-		usage();
+		return usage(psh);
 
 	for (errors = 0; argc; argc--, argv++) {
-#ifdef SHELL
 		if (*argv[0] == '%') {
 			pid = getjobpgrp(psh, *argv);
 			if (pid == 0) {
-				warnx("illegal job id: %s", *argv);
+				sh_warnx(psh, "illegal job id: %s", *argv);
 				errors = 1;
 				continue;
 			}
-		} else
-#endif
-		{
+		} else {
 			pid = strtol(*argv, &ep, 10);
 			if (!**argv || *ep) {
-				warnx("illegal process id: %s", *argv);
+				sh_warnx(psh, "illegal process id: %s", *argv);
 				errors = 1;
 				continue;
 			}
 		}
-		if (kill(pid, numsig) == -1) {
-			warn("%s", *argv);
+		if (sh_kill(psh, pid, numsig) == -1) {
+			sh_warn(psh, "%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 */
+			sh_kill(psh, pid, SIGCONT);
+	}
+
+	//sh_exit(psh, errors);
+	///* NOTREACHED */
+	return errors;
 }
 
@@ -191,7 +175,4 @@
 {
 	int n;
-#ifndef HAVE_SYS_SIGNAME
-	init_sys_signame();
-#endif
 	if (strncasecmp(sig, "sig", 3) == 0)
 		sig += 3;
@@ -203,36 +184,27 @@
 }
 
+static int
+nosig(shinstance *psh, char *name)
+{
+	sh_warnx(psh, "unknown signal %s; valid signals:", name);
+	printsignals(psh, psh->out2);
+	//sh_exit(psh, 1);
+	///* NOTREACHED */
+	return 1;
+}
+
 static void
-nosig(char *name)
-{
-
-	warnx("unknown signal %s; valid signals:", name);
-	printsignals(stderr);
-	exit(1);
-	/* NOTREACHED */
-}
-
-static void
-printsignals(FILE *fp)
+printsignals(shinstance *psh, struct output *out)
 {
 	int sig;
-	int len, nl;
+	size_t 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)
+	if (shfile_isatty(&psh->fdtab, out->fd)) {
+		sh_winsize win;
+		if (shfile_ioctl(&psh->fdtab, out->fd, 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++) {
@@ -241,26 +213,26 @@
 
 		if (len + nl >= termwidth) {
-			fprintf(fp, "\n");
+			outfmt(out, "\n");
 			len = 0;
-		} else
-			if (len != 0)
-				fprintf(fp, " ");
+		} else if (len != 0)
+			outfmt(out, " ");
 		len += nl;
-		fprintf(fp, "%s", name);
+		outfmt(out, "%s", name);
 	}
 	if (len != 0)
-		fprintf(fp, "\n");
-}
-
-static void
-usage(void)
-{
-
-	fprintf(stderr, "usage: %s [-s signal_name] pid ...\n"
+		outfmt(out, "\n");
+}
+
+static int
+usage(shinstance *psh)
+{
+	outfmt(psh->out2,
+	    "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 */
-}
+	    psh->commandname, psh->commandname, psh->commandname, psh->commandname);
+	//sh_exit(psh, 1);
+	///* NOTREACHED */
+	return 1;
+}
Index: /trunk/src/kash/error.h
===================================================================
--- /trunk/src/kash/error.h	(revision 1212)
+++ /trunk/src/kash/error.h	(revision 1213)
@@ -34,4 +34,7 @@
  *	@(#)error.h	8.2 (Berkeley) 5/4/95
  */
+
+#ifndef ___error_h
+#define ___error_h
 
 #include <stdarg.h>
@@ -117,2 +120,4 @@
 #define longjmp(jmploc, val)	_longjmp(jmploc, val)
 #endif
+
+#endif
Index: /trunk/src/kash/shfile.h
===================================================================
--- /trunk/src/kash/shfile.h	(revision 1212)
+++ /trunk/src/kash/shfile.h	(revision 1213)
@@ -114,6 +114,18 @@
 char *shfile_getcwd(shfdtab *, char *, int);
 int shfile_isatty(shfdtab *, int);
-int shfile_ioctl(shfdtab *, int, unsigned long, char *);
+int shfile_ioctl(shfdtab *, int, unsigned long, void *);
 int shfile_access(shfdtab *, const char *, int);
+#ifdef _MSC_VER
+# define TIOCGWINSZ         0x4201
+typedef struct sh_winsize
+{
+    unsigned ws_row;        /**< Rows, in characters. */
+    unsigned ws_col;        /**< Columns, in characters. */
+    unsigned ws_xpixel;     /**< Horizontal size, pixels. */
+    unsigned ws_ypixel;     /**< Vertical size, pixels. */
+} sh_winsize;
+#else
+typedef struct winsize sh_winsize;
+#endif
 
 #endif
Index: /trunk/src/kash/shinstance.h
===================================================================
--- /trunk/src/kash/shinstance.h	(revision 1212)
+++ /trunk/src/kash/shinstance.h	(revision 1213)
@@ -25,9 +25,13 @@
  */
 
-#ifndef ___shinstance_h___
-#define ___shinstance_h___
+#ifndef ___shinstance_h
+#define ___shinstance_h
 
 #include <stdio.h> /* BUFSIZ */
 #include <signal.h> /* NSIG */
+#ifndef _MSC_VER
+# include <termios.h>
+# include <sys/ioctl.h>
+#endif
 
 #include "shtypes.h"
@@ -40,4 +44,10 @@
 #include "exec.h"
 #include "var.h"
+
+#ifdef _MSC_VER
+# define strcasecmp stricmp
+# define strncasecmp strnicmp
+#endif
+
 
 /* memalloc.c */
@@ -330,4 +340,16 @@
 #define SH_SIG_DFL ((sh_sig_t)SIG_DFL)
 #define SH_SIG_IGN ((sh_sig_t)SIG_IGN)
+#ifdef _MSC_VER
+# define SIG_BLOCK          1
+# define SIG_UNBLOCK        2
+# define SIG_SETMASK        3
+# define SIGHUP             5
+# define SIGQUIT            9
+# define SIGPIPE            12
+# define SIGTTOU            17
+# define SIGTSTP            18
+# define SIGTTIN            19
+# define SIGCONT            20
+#endif /* _MSC_VER */
 
 int sh_sigaction(int, const struct sh_sigaction *, struct sh_sigaction *);
@@ -389,4 +411,5 @@
 pid_t sh_getpgid(shinstance *, pid_t);
 int sh_setpgid(shinstance *, pid_t, pid_t);
+int sh_kill(shinstance *, pid_t, int);
 int sh_killpg(shinstance *, pid_t, int);
 
Index: /trunk/src/kash/sys_signame.c
===================================================================
--- /trunk/src/kash/sys_signame.c	(revision 1212)
+++ /trunk/src/kash/sys_signame.c	(revision 1213)
@@ -1,7 +1,7 @@
 /*
- * Fake sys_signame.  
+ * Fake sys_signame.
  */
 
-#include <signal.h>
+#include "shinstance.h" /* for MSC */
 #include <string.h>
 #include <stdio.h>
@@ -9,113 +9,113 @@
 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);
+		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 
+	SET_SIG_STR(HUP);
+#endif
 #ifdef SIGINT
-    SET_SIG_STR(INT);
-#endif 
+	SET_SIG_STR(INT);
+#endif
 #ifdef SIGQUIT
-    SET_SIG_STR(QUIT);
-#endif 
+	SET_SIG_STR(QUIT);
+#endif
 #ifdef SIGILL
-    SET_SIG_STR(ILL);
-#endif 
+	SET_SIG_STR(ILL);
+#endif
 #ifdef SIGTRAP
-    SET_SIG_STR(TRAP);
-#endif 
+	SET_SIG_STR(TRAP);
+#endif
 #ifdef SIGABRT
-    SET_SIG_STR(ABRT);
-#endif 
+	SET_SIG_STR(ABRT);
+#endif
 #ifdef SIGIOT
-    SET_SIG_STR(IOT);
-#endif 
+	SET_SIG_STR(IOT);
+#endif
 #ifdef SIGBUS
-    SET_SIG_STR(BUS);
-#endif 
+	SET_SIG_STR(BUS);
+#endif
 #ifdef SIGFPE
-    SET_SIG_STR(FPE);
-#endif 
+	SET_SIG_STR(FPE);
+#endif
 #ifdef SIGKILL
-    SET_SIG_STR(KILL);
-#endif 
+	SET_SIG_STR(KILL);
+#endif
 #ifdef SIGUSR1
-    SET_SIG_STR(USR1);
-#endif 
+	SET_SIG_STR(USR1);
+#endif
 #ifdef SIGSEGV
-    SET_SIG_STR(SEGV);
-#endif 
+	SET_SIG_STR(SEGV);
+#endif
 #ifdef SIGUSR2
-    SET_SIG_STR(USR2);
-#endif 
+	SET_SIG_STR(USR2);
+#endif
 #ifdef SIGPIPE
-    SET_SIG_STR(PIPE);
-#endif 
+	SET_SIG_STR(PIPE);
+#endif
 #ifdef SIGALRM
-    SET_SIG_STR(ALRM);
-#endif 
+	SET_SIG_STR(ALRM);
+#endif
 #ifdef SIGTERM
-    SET_SIG_STR(TERM);
-#endif 
+	SET_SIG_STR(TERM);
+#endif
 #ifdef SIGSTKFLT
-    SET_SIG_STR(STKFLT);
-#endif 
+	SET_SIG_STR(STKFLT);
+#endif
 #ifdef SIGCHLD
-    SET_SIG_STR(CHLD);
-#endif 
+	SET_SIG_STR(CHLD);
+#endif
 #ifdef SIGCONT
-    SET_SIG_STR(CONT);
-#endif 
+	SET_SIG_STR(CONT);
+#endif
 #ifdef SIGSTOP
-    SET_SIG_STR(STOP);
-#endif 
+	SET_SIG_STR(STOP);
+#endif
 #ifdef SIGTSTP
-    SET_SIG_STR(TSTP);
-#endif 
+	SET_SIG_STR(TSTP);
+#endif
 #ifdef SIGTTIN
-    SET_SIG_STR(TTIN);
-#endif 
+	SET_SIG_STR(TTIN);
+#endif
 #ifdef SIGTTOU
-    SET_SIG_STR(TTOU);
-#endif 
+	SET_SIG_STR(TTOU);
+#endif
 #ifdef SIGURG
-    SET_SIG_STR(URG);
-#endif 
+	SET_SIG_STR(URG);
+#endif
 #ifdef SIGXCPU
-    SET_SIG_STR(XCPU);
-#endif 
+	SET_SIG_STR(XCPU);
+#endif
 #ifdef SIGXFSZ
-    SET_SIG_STR(XFSZ);
-#endif 
+	SET_SIG_STR(XFSZ);
+#endif
 #ifdef SIGVTALRM
-    SET_SIG_STR(VTALRM);
-#endif 
+	SET_SIG_STR(VTALRM);
+#endif
 #ifdef SIGPROF
-    SET_SIG_STR(PROF);
-#endif 
+	SET_SIG_STR(PROF);
+#endif
 #ifdef SIGWINCH
-    SET_SIG_STR(WINCH);
-#endif 
+	SET_SIG_STR(WINCH);
+#endif
 #ifdef SIGIO
-    SET_SIG_STR(IO);
-#endif 
+	SET_SIG_STR(IO);
+#endif
 #ifdef SIGPWR
-    SET_SIG_STR(PWR);
-#endif 
+	SET_SIG_STR(PWR);
+#endif
 #ifdef SIGSYS
-    SET_SIG_STR(SYS);
-#endif 
+	SET_SIG_STR(SYS);
+#endif
 #ifdef SIGBREAK
-    SET_SIG_STR(BREAK);
-#endif 
+	SET_SIG_STR(BREAK);
+#endif
 #undef SET_SIG_STR
-    sys_signame_initialized = 1;
+	sys_signame_initialized = 1;
 }
